awesome/rc.lua
changeset 15 73df43769340
parent 14 6348b9f842b2
child 16 b3c1a18fe12e
equal deleted inserted replaced
14:6348b9f842b2 15:73df43769340
       
     1 local debug = require("debug")
       
     2 --
     1 -- Standard awesome library
     3 -- Standard awesome library
     2 local gears = require("gears")
     4 local gears = require("gears")
     3 local awful = require("awful")
     5 local awful = require("awful")
     4 awful.rules = require("awful.rules")
     6 awful.rules = require("awful.rules")
     5 require("awful.autofocus")
     7 awful.autofocus = require("awful.autofocus")
     6 -- Widget and layout library
     8 -- Widget and layout library
     7 local wibox = require("wibox")
     9 local wibox = require("wibox")
     8 -- Theme handling library
    10 -- Theme handling library
     9 local beautiful = require("beautiful")
    11 local beautiful = require("beautiful")
    10 -- Notification library
    12 -- Notification library
    11 local naughty = require("naughty")
    13 local naughty = require("naughty")
    12 local menubar = require("menubar")
    14 local menubar = require("menubar")
    13 
    15 
       
    16 -- Revelation
       
    17 local revelation = require("revelation")
       
    18 -- vicious widgets
       
    19 local vicious = require("vicious")
       
    20 local wicked = require("wicked")
    14 -- Load Debian menu entries
    21 -- Load Debian menu entries
    15 require("debian.menu")
    22 require("debian.menu")
    16 
    23 
    17 local my = require("my")
    24 local my = require("my")
    18 
    25 
    20 
    27 
    21 -- {{{ Error handling
    28 -- {{{ Error handling
    22 -- Check if awesome encountered an error during startup and fell back to
    29 -- Check if awesome encountered an error during startup and fell back to
    23 -- another config (This code will only ever execute for the fallback config)
    30 -- another config (This code will only ever execute for the fallback config)
    24 if awesome.startup_errors then
    31 if awesome.startup_errors then
    25     naughty.notify({ preset = naughty.config.presets.critical,
    32    naughty.notify({ preset = naughty.config.presets.critical,
    26                      title = "Oops, there were errors during startup!",
    33                     title = "Oops, there were errors during startup!",
    27                      text = awesome.startup_errors })
    34                     text = awesome.startup_errors })
    28 end
    35 end
    29 
    36 
    30 -- Handle runtime errors after startup
    37 -- Handle runtime errors after startup
    31 do
    38 do
    32    local in_error = false
       
    33    awesome.connect_signal("debug::error", my.notify_error)
    39    awesome.connect_signal("debug::error", my.notify_error)
    34    awesome.connect_signal("debug::deprecation", my.notify_error)
    40    awesome.connect_signal("debug::deprecation", my.notify_error)
    35    awesome.connect_signal("debug::index::miss",
    41    awesome.connect_signal("debug::index::miss",
    36                           function (obj, key)
    42                           function (obj, key)
    37                              my.notify_error("Invalid key " .. key .. " on object")
    43                              my.notify_error("Invalid key " .. key .. " on object")
    77 beautiful.wallpaper_cmd = { wallpaper_cmd }
    83 beautiful.wallpaper_cmd = { wallpaper_cmd }
    78 awful.util.spawn_with_shell("pgrep unagi || unagi &")
    84 awful.util.spawn_with_shell("pgrep unagi || unagi &")
    79 
    85 
    80 -- Table of layouts to cover with awful.layout.inc, order matters.
    86 -- Table of layouts to cover with awful.layout.inc, order matters.
    81 local layouts =
    87 local layouts =
    82 {
    88    {
    83     awful.layout.suit.floating,
    89       awful.layout.suit.floating,
    84     awful.layout.suit.tile,
    90       awful.layout.suit.tile,
    85     awful.layout.suit.tile.left,
    91       awful.layout.suit.tile.left,
    86     awful.layout.suit.tile.bottom,
    92       awful.layout.suit.tile.bottom,
    87     awful.layout.suit.tile.top,
    93       awful.layout.suit.tile.top,
    88     awful.layout.suit.fair,
    94       awful.layout.suit.fair,
    89     awful.layout.suit.fair.horizontal,
    95       awful.layout.suit.fair.horizontal,
    90     awful.layout.suit.spiral,
    96       awful.layout.suit.spiral,
    91     awful.layout.suit.spiral.dwindle,
    97       awful.layout.suit.spiral.dwindle,
    92     awful.layout.suit.max,
    98       awful.layout.suit.max,
    93     -- awful.layout.suit.max.fullscreen,
    99       -- awful.layout.suit.max.fullscreen,
    94     awful.layout.suit.magnifier,
   100       awful.layout.suit.magnifier,
    95 }
   101    }
    96 local default_layout = 2
   102 local default_layout = 2
    97 -- }}}
   103 -- }}}
    98 
   104 
    99 -- {{{ Wallpaper
   105 -- {{{ Wallpaper
   100 if beautiful.wallpaper then
   106 if beautiful.wallpaper then
   101     for s = 1, screen.count() do
   107    for s = 1, screen.count() do
   102         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
   108       -- gears.wallpaper.maximized(beautiful.wallpaper, s, true)
   103     end
   109       awful.util.spawn(wallpaper_cmd, false, s)
   104 end
   110    end
   105 -- }}}
   111 end
   106 
   112 -- }}}
   107 -- Define if we want to use titlebar on all applications.
       
   108 use_titlebar = true
       
   109 
   113 
   110 -- {{{ Tags
   114 -- {{{ Tags
   111 -- Define a tag table which hold all screen tags.
   115 -- Define a tag table which hold all screen tags.
       
   116 local mytags = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }
       
   117 local number_of_rows = #mytags
       
   118 
   112 tags = {}
   119 tags = {}
   113 for s = 1, screen.count() do
   120 for s = 1, screen.count() do
   114     -- Each screen has its own tag table.
   121    -- Each screen has its own tag table.
   115     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[default_layout])
   122    tags[s] = awful.tag(mytags, s, layouts[default_layout])
   116 end
   123 end
       
   124 
       
   125 local function get_tag(s, i)
       
   126    return awful.tag.gettags(s)[i]
       
   127 end
       
   128 
       
   129 local function get_next_tag(s)
       
   130    local idx = awful.tag.getidx() + 1
       
   131    if idx > number_of_rows then
       
   132       idx = 1
       
   133    end
       
   134    return get_tag(s, idx)
       
   135 end
       
   136 
       
   137 local function get_prev_tag(s)
       
   138    local idx = awful.tag.getidx() - 1
       
   139    if idx < 1 then
       
   140       idx = number_of_rows
       
   141    end
       
   142    return get_tag(s, idx)
       
   143 end
       
   144 
   117 -- }}}
   145 -- }}}
   118 
   146 
   119 -- Create a laucher widget and a main menu
   147 -- Create a laucher widget and a main menu
   120 myawesomemenu = {
   148 myawesomemenu = {
   121    {"manual", terminal .. " -e man awesome"},
   149    {"manual", terminal .. " -e man awesome"},
   153 mywibox = {}
   181 mywibox = {}
   154 mypromptbox = {}
   182 mypromptbox = {}
   155 mylayoutbox = {}
   183 mylayoutbox = {}
   156 mytaglist = {}
   184 mytaglist = {}
   157 mytaglist.buttons = awful.util.table.join(
   185 mytaglist.buttons = awful.util.table.join(
   158                     awful.button({ }, 1, awful.tag.viewonly),
   186    awful.button({ }, 1, awful.tag.viewonly),
   159                     awful.button({ modkey }, 1, awful.client.movetotag),
   187    awful.button({ modkey }, 1, awful.client.movetotag),
   160                     awful.button({ }, 3, awful.tag.viewtoggle),
   188    awful.button({ }, 3, awful.tag.viewtoggle),
   161                     awful.button({ modkey }, 3, awful.client.toggletag),
   189    awful.button({ modkey }, 3, awful.client.toggletag),
   162                     awful.button({ }, 4, function(t)
   190    awful.button({ }, 4, function(t)
   163                           awful.tag.viewnext(awful.tag.getscreen(t)) end),
   191          awful.tag.viewnext(awful.tag.getscreen(t)) end),
   164                     awful.button({ }, 5, function(t)
   192    awful.button({ }, 5, function(t)
   165                           awful.tag.viewprev(awful.tag.getscreen(t)) end)
   193          awful.tag.viewprev(awful.tag.getscreen(t)) end)
   166 )
   194 )
   167 mytasklist = {}
   195 mytasklist = {}
   168 mytasklist.buttons = awful.util.table.join(
   196 mytasklist.buttons = awful.util.table.join(
   169    awful.button({ }, 1, function (c)
   197    awful.button({ }, 1, function (c)
   170          if c == client.focus then
   198          if c == client.focus then
   190             instance = awful.menu.clients({
   218             instance = awful.menu.clients({
   191                   theme = { width = 250 }
   219                   theme = { width = 250 }
   192             })
   220             })
   193          end
   221          end
   194    end),
   222    end),
       
   223    awful.button({modkey}, 3, function(c)
       
   224          c.maximized = not c.maximized
       
   225    end),
   195    awful.button({ }, 4, function ()
   226    awful.button({ }, 4, function ()
   196          awful.client.focus.byidx(1)
   227          awful.client.focus.byidx(1)
   197          if client.focus then client.focus:raise() end
   228          if client.focus then client.focus:raise() end
   198    end),
   229    end),
   199    awful.button({ }, 5, function ()
   230    awful.button({ }, 5, function ()
   208 -- local mynetdownwidget = my.decorated_monitor_widget(make_netwidget("eth1", "down"))
   239 -- local mynetdownwidget = my.decorated_monitor_widget(make_netwidget("eth1", "down"))
   209 local mymodewidget = my.widgets.mode()
   240 local mymodewidget = my.widgets.mode()
   210 
   241 
   211 
   242 
   212 for s = 1, screen.count() do
   243 for s = 1, screen.count() do
   213     -- Create a promptbox for each screen
   244 
   214     mypromptbox[s] = awful.widget.prompt()
   245    -- Create a promptbox for each screen
   215     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
   246    mypromptbox[s] = awful.widget.prompt()
   216     -- We need one layoutbox per screen.
   247    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
   217     mylayoutbox[s] = awful.widget.layoutbox(s)
   248    -- We need one layoutbox per screen.
   218     mylayoutbox[s]:buttons(awful.util.table.join(
   249    mylayoutbox[s] = awful.widget.layoutbox(s)
   219                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
   250    mylayoutbox[s]:buttons(awful.util.table.join(
   220                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
   251                              awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
   221                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
   252                              awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
   222                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
   253                              awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
   223     -- Create a taglist widget
   254                              awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
   224     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
   255    -- Create a taglist widget
   225 
   256    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
   226     -- Create a tasklist widget
   257 
   227     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
   258    -- Create a tasklist widget
   228 
   259    mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
   229     -- Create the wibox
   260 
   230     mywibox[s] = awful.wibox({ position = "top", screen = s })
   261    -- Create the wibox
   231 
   262    mywibox[s] = awful.wibox({ position = "top", screen = s })
   232     -- Widgets that are aligned to the left
   263 
   233     local left_layout = wibox.layout.fixed.horizontal()
   264    -- Widgets that are aligned to the left
   234     left_layout:add(mymodewidget)
   265    local left_layout = wibox.layout.fixed.horizontal()
   235     left_layout:add(mylauncher)
   266    left_layout:add(mymodewidget)
   236     if s == 1 then
   267    left_layout:add(mylauncher)
   237        left_layout:add(mycpuwidget)
   268    if s == 1 then
   238        left_layout:add(mymemwidget)
   269       left_layout:add(mycpuwidget)
   239     end
   270       left_layout:add(mymemwidget)
   240     left_layout:add(mytaglist[s])
   271    end
   241     left_layout:add(mypromptbox[s])
   272    left_layout:add(mytaglist[s])
   242 
   273    left_layout:add(mypromptbox[s])
   243     -- Widgets that are aligned to the right
   274 
   244     local right_layout = wibox.layout.fixed.horizontal()
   275    -- Widgets that are aligned to the right
   245     if s == 1 then
   276    local right_layout = wibox.layout.fixed.horizontal()
   246        right_layout:add(mynetwidget)
   277    if s == 1 then
   247        right_layout:add(mysystray)
   278       right_layout:add(mynetwidget)
   248     end
   279       right_layout:add(mysystray)
   249     right_layout:add(mytextclock)
   280    end
   250     right_layout:add(mylayoutbox[s])
   281    right_layout:add(mytextclock)
   251 
   282    right_layout:add(mylayoutbox[s])
   252     -- Now bring it all together (with the tasklist in the middle)
   283 
   253     local layout = wibox.layout.align.horizontal()
   284    -- Now bring it all together (with the tasklist in the middle)
   254     layout:set_left(left_layout)
   285    local layout = wibox.layout.align.horizontal()
   255     layout:set_middle(mytasklist[s])
   286    layout:set_left(left_layout)
   256     layout:set_right(right_layout)
   287    layout:set_middle(mytasklist[s])
   257 
   288    layout:set_right(right_layout)
   258     mywibox[s]:set_widget(layout)
   289 
       
   290    mywibox[s]:set_widget(layout)
   259 end
   291 end
   260 -- }}}
   292 -- }}}
   261 
   293 
   262 -- {{{ Mouse bindings
   294 -- {{{ Mouse bindings
   263 root.buttons(awful.util.table.join(
   295 root.buttons(awful.util.table.join(
   264     awful.button({ }, 3, function () mymainmenu:toggle() end),
   296                 awful.button({ }, 3, function () mymainmenu:toggle() end),
   265     awful.button({ }, 4, awful.tag.viewnext),
   297                 awful.button({ }, 4, awful.tag.viewnext),
   266     awful.button({ }, 5, awful.tag.viewprev)
   298                 awful.button({ }, 5, awful.tag.viewprev)
   267 ))
   299 ))
   268 -- }}}
   300 -- }}}
   269 
   301 
   270 -- {{{ Key tables
   302 -- {{{ Key tables
       
   303 
       
   304 local awesome_table = {
       
   305    my.make_single_key("m", "Main menu", my.mkinteractive(function () mymainmenu:show({keygrabber=true}) end)),
       
   306    -- This one returns an error.
       
   307    my.make_single_key("b", "Menu bar", function () menubar.show() end),
       
   308    my.make_single_key("t", "Terminal", my.mkspawn(terminal)),
       
   309    my.make_single_key("f", "Toggle sloppy mouse", my.sloppy_toggle),
       
   310    my.make_single_key("r", "Restart", awesome.restart),
       
   311    my.make_single_key("q", "Quit", logout)
       
   312 }
       
   313 
       
   314 local layout_table = {
       
   315    -- Client movement
       
   316    my.make_interactive_key("Right", "Focus right",
       
   317                function () awful.client.focus.bydirection("right") end),
       
   318    my.make_interactive_key("Left", "Focus left",
       
   319                function () awful.client.focus.bydirection("left") end),
       
   320    my.make_interactive_key("Up", "Focus up",
       
   321                function () awful.client.focus.bydirection("up") end),
       
   322    my.make_interactive_key("Down", "Focus down",
       
   323                function () awful.client.focus.bydirection("down") end),
       
   324    my.make_interactive_key("Shift+Right", "Move right",
       
   325                function () awful.client.swap.bydirection("right") end),
       
   326    my.make_interactive_key("Shift+Left", "Move left",
       
   327                function () awful.client.swap.bydirection("left") end),
       
   328    my.make_interactive_key("Shift+Up", "Move up",
       
   329                function () awful.client.swap.bydirection("up") end),
       
   330    my.make_interactive_key("Shift+Down", "Move down",
       
   331                function () awful.client.swap.bydirection("down") end),
       
   332    -- Master/Client transforms
       
   333    my.make_interactive_key("Control+Right", "Master grow",
       
   334                       function () awful.tag.incmwfact(  0.05 ) end),
       
   335    my.make_interactive_key("Control+Left", "Master shrink",
       
   336                       function () awful.tag.incmwfact( -0.05 ) end),
       
   337    my.make_interactive_key("Control+Shift+Down", "Add master",
       
   338                       function () awful.tag.incnmaster(  1 ) end),
       
   339    my.make_interactive_key("Control+Shift+Up", "Remove master",
       
   340                       function () awful.tag.incnmaster( -1 ) end),
       
   341    my.make_interactive_key("Control+Shift+Right", "Add column",
       
   342                       function () awful.tag.incncol(  1 ) end),
       
   343    my.make_interactive_key("Control+Shift+Left", "Remove column",
       
   344                       function () awful.tag.incncol( -1 ) end),
       
   345    -- Layouts
       
   346    my.make_interactive_key("Space", "Next layout",
       
   347                       function () awful.layout.inc(layouts,  1 ) end),
       
   348    my.make_interactive_key("Shift+Space", "Previous layout",
       
   349                       function () awful.layout.inc(layouts, -1 ) end),
       
   350 }
       
   351 
       
   352 -- Media Keys table, associated globally, with no modifiers.
       
   353 local media_table = {
       
   354    -- media keys
       
   355    my.make_single_key("XF86HomePage", "Browser", my.mkspawn(browser)),
       
   356    my.make_single_key("XF86Mail", "Mail", my.mkspawn(mail)),
       
   357    my.make_single_key("XF86Search", "Search file...", my.mkspawn(lookup)),
       
   358    my.make_single_key("XF86Explorer", "File Manager", my.mkspawn(filemanager)),
       
   359    my.make_single_key("XF86Calculator", "Calculator", my.mkspawn(calculator)),
       
   360    my.make_single_key("XF86Tools", "Music", my.mkspawn(musicplayer)),
       
   361    my.make_single_key("XF86AudioPrev", "Previous song", my.mkspawn("mpc prev")),
       
   362    my.make_single_key("XF86AudioNext", "Next song", my.mkspawn("mpc next")),
       
   363    my.make_single_key("XF86AudioPlay", "Play song", my.mkspawn("mpc toggle")),
       
   364    my.make_single_key("XF86AudioMute", "Mute", my.mkspawn("pulseaudio-ctl mute")),
       
   365    my.make_single_key("XF86AudioLowerVolume", "Volume down", my.mkspawn("pulseaudio-ctl down")),
       
   366    my.make_single_key("XF86AudioRaiseVolume", "Volume up", my.mkspawn("pulseaudio-ctl up")),
       
   367    my.make_single_key("XF86Eject", "Eject", my.mkspawn("eject")),
       
   368 }
       
   369 
       
   370 -- Global table, associated globally to modkey.
   271 local global_table = {
   371 local global_table = {
   272    my.make_single_key("Up", "View prev", awful.tag.viewprev),
   372    -- my.make_single_key("e", "Revel windows", revelation),
   273    my.make_single_key("Down", "View next", awful.tag.viewnext),
   373    my.make_single_key("Control+n", "Restore clients", awful.client.restore),
   274    my.make_single_key("Escape", "Restore history", awful.tag.history.restore),
   374    my.make_single_key("Escape", "Restore history", awful.tag.history.restore),
   275    my.make_single_key("Right", "Next screen", 
   375    my.make_single_key("Tab", "Previous client",
   276                       function ()
       
   277                          awful.client.focus.byidx( 1)
       
   278                          if client.focus then client.focus:raise() end
       
   279    end),
       
   280    my.make_single_key("Left", "Previous screen",
       
   281                       function ()
       
   282                          awful.client.focus.byidx(-1)
       
   283                          if client.focus then client.focus:raise() end
       
   284    end),
       
   285    my.make_single_key("w", "Main menu", function () mymainmenu:show() end),
       
   286    my.make_single_key("Shift+Right", "Swap with next",
       
   287                function () awful.client.swap.byidx( 1); end),
       
   288    my.make_single_key("Shift+Left", "Swap with prev",
       
   289                       function () awful.client.swap.byidx(-1); end),
       
   290    -- Is this work ?
       
   291    my.make_single_key("Control+Right", "Focus next screen",
       
   292                       function () awful.screen.focus_relative( 1); end),
       
   293    -- Is this work ?
       
   294    my.make_single_key("Control+Left", "Focus prev screen",
       
   295                function () awful.screen.focus_relative(-1); end),
       
   296    my.make_single_key("u", "Go to urgent",
       
   297                function () awful.client.urgent.jumpto(); end),
       
   298    my.make_single_key("Tab", "Next client",
       
   299                       function ()
   376                       function ()
   300                          awful.client.focus.history.previous()
   377                          awful.client.focus.history.previous()
   301                          if client.focus then
   378                          if client.focus then
   302                             client.focus:raise()
   379                             client.focus:raise()
   303                          end
   380                          end
   304    end),
   381    end),
   305    my.make_single_key("Return", "Start terminal", my.mkspawn(terminal)),
   382    my.make_single_key("u", "Go to urgent", awful.client.urgent.jumpto),
   306    my.make_single_key("Control+r", "Restart", awesome.restart),
   383 
   307    my.make_single_key("Shift+q", "Quit", logout),
   384    -- Tag Navigation
   308    my.make_single_key("l", "Inc Master Size",
   385    my.make_single_key("Prior", "View prev", awful.tag.viewprev),
   309                       function () awful.tag.incmwfact(  0.05 ) end),
   386    my.make_single_key("Next", "View next", awful.tag.viewnext),
   310    my.make_single_key("h", "Dec Master Size",
   387    my.make_single_key("Shift+Prior", "Send to Previous View",
   311                       function () awful.tag.incmwfact( -0.05 ) end),
   388                       function ()
   312    my.make_single_key("Shift+l", "Inc Master Count",
   389                          if client.focus then
   313                       function () awful.tag.incnmaster(  1 ) end),
   390                             local tag = get_prev_tag(client.focus.screen)
   314    my.make_single_key("Shift+h", "Dec Master Count",
   391                             awful.client.movetotag(tag)
   315                       function () awful.tag.incnmaster( -1 ) end),
   392                             awful.tag.viewprev()
   316    my.make_single_key("Control+l", "Inc Column Count",
   393                          end
   317                       function () awful.tag.incncol(  1 ) end),
   394    end),
   318    my.make_single_key("Control+h", "Dec Column Count",
   395    my.make_single_key("Shift+Next", "Send to Next View",
   319                       function () awful.tag.incncol( -1 ) end),
   396                       function ()
   320    my.make_single_key("Space", "Next layout",
   397                          if client.focus then
   321                       function () awful.layout.inc(layouts,  1 ) end),
   398                             local tag = get_next_tag(client.focus.screen)
   322    my.make_single_key("Shift+Space", "Prev layout",
   399                             awful.client.movetotag(tag)
   323                       function () awful.layout.inc(layouts, -1 ) end),
   400                             awful.tag.viewnext()                            
   324    my.make_single_key("Control+n", "Restore clients", awful.client.restore),
   401                          end
   325    my.make_single_key("r", "Run",
   402    end),
       
   403 
       
   404    -- Client Navigation
       
   405    my.make_single_key("Right", "Right client", my.make_focus_bydirection("right")),
       
   406    my.make_single_key("Left", "Left client", my.make_focus_bydirection("left")),
       
   407    my.make_single_key("Up", "Up client", my.make_focus_bydirection("up")),
       
   408    my.make_single_key("Down", "Down client", my.make_focus_bydirection("down")),
       
   409    my.make_single_key("Shift+Right", "Move right",
       
   410                function () awful.client.swap.bydirection("right") end),
       
   411    my.make_single_key("Shift+Left", "Move left",
       
   412                function () awful.client.swap.bydirection("left") end),
       
   413    my.make_single_key("Shift+Up", "Move up",
       
   414                function () awful.client.swap.bydirection("up") end),
       
   415    my.make_single_key("Shift+Down", "Move down",
       
   416                function () awful.client.swap.bydirection("down") end),
       
   417 
       
   418    -- Prompts...
       
   419    my.make_single_key("F2", "Run...",
   326                       function () mypromptbox[mouse.screen]:run() end),
   420                       function () mypromptbox[mouse.screen]:run() end),
   327    my.make_single_key("x", "Lua prompt",
   421    my.make_single_key("F3", "Eval...",
   328                       function ()
   422                       function ()
   329                          awful.prompt.run({ prompt = "Run Lua code: " },
   423                          awful.prompt.run({ prompt = "Run Lua code: " },
   330                             mypromptbox[mouse.screen].widget,
   424                             mypromptbox[mouse.screen].widget,
   331                             awful.util.eval, nil,
   425                             awful.util.eval, nil,
   332                             awful.util.getdir("cache") .. "/history_eval")
   426                             awful.util.getdir("cache") .. "/history_eval")
   333    end),
   427    end),
   334    -- This one returns an error.
   428    
   335    my.make_single_key("p", "Menu bar", function () menubar.show() end)
   429    -- forcing restart of mpd.
       
   430    -- it sometime have difficulty to connect to pulse
       
   431    my.make_single_key("F6", "Restart mpd",
       
   432                       function ()
       
   433                          awful.util.spawn("pkill -9 mpd")
       
   434                          awful.util.spawn("mpd")
       
   435    end),
       
   436    
       
   437    -- modal key binding
       
   438    my.make_key("a", "Main mode...", my.make_kt(awesome_table, "awesome") ),
       
   439    my.make_key("l", "Layout mode...", my.make_kt(layout_table, "layout") ),
   336 }
   440 }
   337 
   441 
   338 client_table = {
   442 -- Client table, associated to each client with modkey.
       
   443 local client_table = {
       
   444    my.make_single_key("Return", "Swap master", 
       
   445                       function(c) c:swap(awful.client.getmaster()) end),
   339    my.make_single_key("f", "Toggle fullscreen",
   446    my.make_single_key("f", "Toggle fullscreen",
   340                       function (c) c.fullscreen = not c.fullscreen end),
   447                       function (c) c.fullscreen = not c.fullscreen end),
   341    my.make_single_key("Shift+c", "Kill client", function (c) c:kill() end),
   448    my.make_single_key("F4", "Kill client", function (c) c:kill() end),
   342    my.make_single_key("Control+Space", "Toggle floating", awful.client.floating.toggle),
   449    my.make_single_key("Space", "Toggle floating", awful.client.floating.toggle),
   343    my.make_single_key("o", "Move to screen", awful.client.movetoscreen),
       
   344    my.make_single_key("t", "Toggle on top", function (c) c.ontop = not c.ontop end),
   450    my.make_single_key("t", "Toggle on top", function (c) c.ontop = not c.ontop end),
   345    my.make_single_key("n", "Iconized",
       
   346                       function (c)
       
   347                          -- The client currently has the input focus, so it cannot be
       
   348                          -- minimized, since minimized clients can't have the focus.
       
   349                          c.minimized = true
       
   350    end),
       
   351    my.make_single_key("m", "Toggle maximized",
   451    my.make_single_key("m", "Toggle maximized",
   352                       function (c)
   452                       function (c)
   353                          maximized = not c.maximized_horizontal
   453                          maximized = not c.maximized_horizontal
   354                          c.maximized_horizontal = maximized
   454                          c.maximized_horizontal = maximized
   355                          c.maximized_vertical   = maximized
   455                          c.maximized_vertical   = maximized
   356    end),
   456    end),
       
   457    my.make_single_key("h", "Hide",
       
   458                       function (c)
       
   459                          -- The client currently has the input focus, so it cannot be
       
   460                          -- minimized, since minimized clients can't have the focus.
       
   461                          c.minimized = true
       
   462    end),
       
   463    -- Client awful tagging: this is useful to tag some clients and then do stuff
       
   464    -- like move to tag on them
   357    my.make_single_key("Shift+t", "Toggle mark", awful.client.togglemarked)
   465    my.make_single_key("Shift+t", "Toggle mark", awful.client.togglemarked)
   358 }
   466 }
       
   467 
       
   468 
   359 -- }}}
   469 -- }}}
   360 
   470 
   361 -- {{{ Key bindings
   471 -- {{{ Key bindings
   362 globalkeys = awful.util.table.join(
   472 globalkeys = awful.util.table.join(
   363    awful.key({modkey}, "F1", function () my.show_kt(global_table, "Global binding") end),
   473    awful.key({modkey}, "F1", function () my.show_kt(global_table, "Global binding") end),
   364    -- make the client binding help available even when there is no client.
   474    -- make the client binding help available even when there is no client.
   365    awful.key({modkey, "Shift"}, "F1", 
   475    awful.key({modkey, "Shift"}, "F1", 
   366       function () my.show_kt(client_table, "Client binding") end),
   476       function () my.show_kt(client_table, "Client binding") end),
   367    my.make_globalkeys({modkey}, global_table)
   477    my.make_globalkeys({modkey}, global_table),
       
   478    my.make_globalkeys({}, media_table)
   368 )
   479 )
   369 
   480 
   370 clientkeys = awful.util.table.join(
   481 clientkeys = awful.util.table.join(
   371    my.make_globalkeys({modkey}, client_table)
   482    my.make_globalkeys({modkey}, client_table)
   372 )
   483 )
   373    
   484 -- }}}
       
   485 
       
   486 
   374 -- Bind all key numbers to tags.
   487 -- Bind all key numbers to tags.
   375 -- Be careful: we use keycodes to make it works on any keyboard layout.
   488 -- Be careful: we use keycodes to make it works on any keyboard layout.
   376 -- This should map on the top row of your keyboard, usually 1 to 9.
   489 -- This should map on the top row of your keyboard, usually 1 to 9.
   377 for i = 1, 9 do
   490 for i = 1, number_of_rows do
   378     globalkeys = awful.util.table.join(globalkeys,
   491    local k = "#" .. i + 9
   379         -- View tag only.
   492    globalkeys = awful.util.table.join(
   380         awful.key({ modkey }, "#" .. i + 9,
   493       globalkeys,
   381                   function ()
   494       -- View tag only.
   382                         local screen = mouse.screen
   495       awful.key({ modkey }, k,
   383                         local tag = awful.tag.gettags(screen)[i]
   496          function ()
   384                         if tag then
   497             local tag = get_tag(mouse.screen, i)
   385                            awful.tag.viewonly(tag)
   498             if tag then
   386                         end
   499                awful.tag.viewonly(tag)
   387                   end),
   500             end
   388         -- Toggle tag.
   501       end),
   389         awful.key({ modkey, "Control" }, "#" .. i + 9,
   502       -- Toggle view tag.
   390                   function ()
   503       awful.key({ modkey, "Control" }, k,
   391                       local screen = mouse.screen
   504          function ()
   392                       local tag = awful.tag.gettags(screen)[i]
   505             local tag = get_tag(mouse.screen, i)
   393                       if tag then
   506             if tag then
   394                          awful.tag.viewtoggle(tag)
   507                awful.tag.viewtoggle(tag)
   395                       end
   508             end
   396                   end),
   509       end),
   397         -- Move client to tag.
   510       -- Move client to tag.
   398         awful.key({ modkey, "Shift" }, "#" .. i + 9,
   511       awful.key({ modkey, "Shift" }, k,
   399                   function ()
   512          function ()
   400                       if client.focus then
   513             if client.focus then
   401                           local tag = awful.tag.gettags(client.focus.screen)[i]
   514                local tag = get_tag(client.focus.screen, i)
   402                           if tag then
   515                if tag then
   403                               awful.client.movetotag(tag)
   516                   awful.client.movetotag(tag)
   404                           end
   517                end
   405                      end
   518             end
   406                   end),
   519       end),
   407         -- Toggle tag.
   520       -- Toggle client tag.
   408         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
   521       awful.key({ modkey, "Control", "Shift" }, k,
   409                   function ()
   522          function ()
   410                       if client.focus then
   523             if client.focus then
   411                           local tag = awful.tag.gettags(client.focus.screen)[i]
   524                local tag = get_tag(client.focus.screen, i)
   412                           if tag then
   525                if tag then
   413                               awful.client.toggletag(tag)
   526                   awful.client.toggletag(tag)
   414                           end
   527                end
   415                       end
   528             end
   416                   end))
   529    end))
   417 end
   530 end
   418 
   531 
   419 clientbuttons = awful.util.table.join(
   532 clientbuttons = awful.util.table.join(
   420     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
   533    awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
   421     awful.button({ modkey }, 1, awful.mouse.client.move),
   534    awful.button({ modkey }, 1, awful.mouse.client.move),
   422     awful.button({ modkey }, 3, awful.mouse.client.resize))
   535    awful.button({ modkey }, 3, awful.mouse.client.resize))
   423 
   536 
   424 -- Set keys
   537 -- Set keys
       
   538 -- mympdwidget:append_global_keys()
   425 root.keys(globalkeys)
   539 root.keys(globalkeys)
   426 -- }}}
   540 -- }}}
   427 
   541 
   428 -- {{{ Rules
   542 -- {{{ Rules
   429 -- Rules to apply to new clients (through the "manage" signal).
   543 -- Rules to apply to new clients (through the "manage" signal).
   430 awful.rules.rules = {
   544 awful.rules.rules = {
   431     -- All clients will match this rule.
   545    -- All clients will match this rule.
   432     { rule = { },
   546    { rule = { },
   433       properties = { border_width = beautiful.border_width,
   547      properties = { border_width = beautiful.border_width,
   434                      border_color = beautiful.border_normal,
   548                     border_color = beautiful.border_normal,
   435                      focus = awful.client.focus.filter,
   549                     focus = awful.client.focus.filter,
   436                      raise = true,
   550                     raise = true,
   437                      keys = clientkeys,
   551                     keys = clientkeys,
   438                      buttons = clientbuttons } },
   552                     buttons = clientbuttons } },
   439     { rule = { class = "MPlayer" },
   553    { rule = { class = "MPlayer" },
   440       properties = { floating = true } },
   554      properties = { floating = true } },
   441     { rule = { class = "pinentry" },
   555    { rule = { class = "pinentry" },
   442       properties = { floating = true } },
   556      properties = { floating = true } },
   443     { rule = { class = "gimp" },
   557    { rule = { class = "gimp" },
   444       properties = { floating = true } },
   558      properties = { floating = true } },
   445     -- Set Firefox to always map on tags number 2 of screen 1.
   559    -- Set Firefox to always map on tags number 2 of screen 1.
   446     -- { rule = { class = "Firefox" },
   560    -- { rule = { class = "Firefox" },
   447     --   properties = { tag = tags[1][2] } },
   561    --   properties = { tag = tags[1][2] } },
   448 }
   562 }
   449 -- }}}
   563 -- }}}
   450 
   564    
   451 -- {{{ Signals
   565 -- {{{ Signals
   452 -- Signal function to execute when a new client appears.
   566 -- Signal function to execute when a new client appears.
   453 client.connect_signal("manage", function (c, startup)
   567 function manage_clients(c, startup)
   454     -- Enable sloppy focus
   568    -- Enable sloppy focus
   455     -- c:connect_signal("mouse::enter", function(c)
   569    -- c:connect_signal("mouse::enter", function(c)
   456     --     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
   570    --     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
   457     --         and awful.client.focus.filter(c) then
   571    --         and awful.client.focus.filter(c) then
   458     --         client.focus = c
   572    --         client.focus = c
   459     --     end
   573    --     end
   460     -- end)
   574    -- end)
   461 
   575    
   462     if not startup then
   576    if not startup then
   463         -- Set the windows at the slave,
   577       -- Set the windows at the slave,
   464         -- i.e. put it at the end of others instead of setting it master.
   578       -- i.e. put it at the end of others instead of setting it master.
   465         -- awful.client.setslave(c)
   579       -- awful.client.setslave(c)
   466 
   580       
   467         -- Put windows in a smart way, only if they does not set an initial position.
   581       -- Put windows in a smart way, only if they does not set an initial position.
   468         if not c.size_hints.user_position and not c.size_hints.program_position then
   582       if not c.size_hints.user_position and not c.size_hints.program_position then
   469             awful.placement.no_overlap(c)
   583          awful.placement.no_overlap(c)
   470             awful.placement.no_offscreen(c)
   584          awful.placement.no_offscreen(c)
   471         end
   585       end
   472     elseif not c.size_hints.user_position and not c.size_hints.program_position then
   586    elseif not c.size_hints.user_position and not c.size_hints.program_position then
   473         -- Prevent clients from being unreachable after screen count change
   587       -- Prevent clients from being unreachable after screen count change
   474         awful.placement.no_offscreen(c)
   588       awful.placement.no_offscreen(c)
   475     end
   589    end
   476 
   590    
   477     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
   591    if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
   478         -- buttons for the titlebar
   592       -- buttons for the titlebar
   479         local buttons = awful.util.table.join(
   593       local buttons = awful.util.table.join(
   480                 awful.button({ }, 1, function()
   594          awful.button({ }, 1, function()
   481                     client.focus = c
   595                client.focus = c
   482                     c:raise()
   596                c:raise()
   483                     awful.mouse.client.move(c)
   597                awful.mouse.client.move(c)
   484                 end),
   598          end),
   485                 awful.button({ }, 3, function()
   599          awful.button({ }, 3, function()
   486                     client.focus = c
   600                client.focus = c
   487                     c:raise()
   601                c:raise()
   488                     awful.mouse.client.resize(c)
   602                awful.mouse.client.resize(c)
   489                 end)
   603          end)
   490                 )
   604       )
   491 
   605       
   492         -- Widgets that are aligned to the left
   606       -- Widgets that are aligned to the left
   493         local left_layout = wibox.layout.fixed.horizontal()
   607       local left_layout = wibox.layout.fixed.horizontal()
   494         left_layout:add(awful.titlebar.widget.iconwidget(c))
   608       left_layout:add(awful.titlebar.widget.iconwidget(c))
   495         left_layout:buttons(buttons)
   609       left_layout:buttons(buttons)
   496 
   610       
   497         -- Widgets that are aligned to the right
   611       -- Widgets that are aligned to the right
   498         local right_layout = wibox.layout.fixed.horizontal()
   612       local right_layout = wibox.layout.fixed.horizontal()
   499         right_layout:add(awful.titlebar.widget.floatingbutton(c))
   613       right_layout:add(awful.titlebar.widget.floatingbutton(c))
   500         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
   614       right_layout:add(awful.titlebar.widget.maximizedbutton(c))
   501         right_layout:add(awful.titlebar.widget.stickybutton(c))
   615       right_layout:add(awful.titlebar.widget.stickybutton(c))
   502         right_layout:add(awful.titlebar.widget.ontopbutton(c))
   616       right_layout:add(awful.titlebar.widget.ontopbutton(c))
   503         right_layout:add(awful.titlebar.widget.closebutton(c))
   617       right_layout:add(awful.titlebar.widget.closebutton(c))
   504 
   618       
   505         -- The title goes in the middle
   619       -- The title goes in the middle
   506         local middle_layout = wibox.layout.flex.horizontal()
   620       local middle_layout = wibox.layout.flex.horizontal()
   507         local title = awful.titlebar.widget.titlewidget(c)
   621       local title = awful.titlebar.widget.titlewidget(c)
   508         title:set_align("center")
   622       title:set_align("center")
   509         middle_layout:add(title)
   623       middle_layout:add(title)
   510         middle_layout:buttons(buttons)
   624       middle_layout:buttons(buttons)
   511 
   625       
   512         -- Now bring it all together
   626       -- Now bring it all together
   513         local layout = wibox.layout.align.horizontal()
   627       local layout = wibox.layout.align.horizontal()
   514         layout:set_left(left_layout)
   628       layout:set_left(left_layout)
   515         layout:set_right(right_layout)
   629       layout:set_right(right_layout)
   516         layout:set_middle(middle_layout)
   630       layout:set_middle(middle_layout)
   517 
   631       
   518         awful.titlebar(c):set_widget(layout)
   632       awful.titlebar(c):set_widget(layout)
   519     end
   633    end
       
   634 end
       
   635 client.connect_signal("manage", manage_clients)
       
   636 
       
   637 -- Hook function to execute when focusing a client.
       
   638 client.connect_signal("focus", 
       
   639                       function(c)
       
   640                          if not awful.client.ismarked(c) then
       
   641                             c.border_color = beautiful.border_focus
       
   642                             -- c.opacity = 13.0
       
   643                          end
   520 end)
   644 end)
   521 
   645 
   522 client.connect_signal("focus",
   646 -- Hook function to execute when unfocusing a client.
   523                       function(c)
   647 client.connect_signal("unfocus", function(c)
   524                          c.border_color = beautiful.border_focus
   648                          if not awful.client.ismarked(c) then
       
   649                             c.border_color = beautiful.border_normal
       
   650                             -- c.opacity = 0.8
       
   651                          end
   525 end)
   652 end)
   526 
       
   527 client.connect_signal("unfocus",
       
   528                       function(c)
       
   529                          c.border_color = beautiful.border_normal
       
   530 end)
       
   531 -- }}}
   653 -- }}}
   532 
   654 
   533 my.sloppy_install(0.5)
   655 my.sloppy_install(0.5)