Merge branch 'pristine' into master
[awesome-config] / rc.lua
1 -- read the timezone from /etc/timezone (this doesn't work, somehow)
2 local function read_tz_file(path)
3     local file = io.open(path, "r") -- r read mode and b binary mode
4     if not file then return nil end
5     local content = file:read "*a" -- *a or *all reads the whole file
6     file:close()
7     content = content:gsub("^%s*", "")
8     content = content:gsub("%s*$", "")
9     return content
10 end
11
12 local tz_string = read_tz_file("/etc/timezone")
13
14 -- Standard awesome library
15 local gears = require("gears")
16 local awful = require("awful")
17 require("awful.autofocus")
18 -- Widget and layout library
19 local wibox = require("wibox")
20 -- Theme handling library
21 local beautiful = require("beautiful")
22 -- Notification library
23 local naughty = require("naughty")
24 local menubar = require("menubar")
25 local hotkeys_popup = require("awful.hotkeys_popup").widget
26
27 -- load the volume widget code and set settings
28 local volume_control = require("volume-control")
29 volumecfg = volume_control({})
30
31 -- Load Debian menu entries
32 require("debian.menu")
33
34 -- {{{ Error handling
35 -- Check if awesome encountered an error during startup and fell back to
36 -- another config (This code will only ever execute for the fallback config)
37 if awesome.startup_errors then
38     naughty.notify({ preset = naughty.config.presets.critical,
39                      title = "Oops, there were errors during startup!",
40                      text = awesome.startup_errors })
41 end
42
43 -- Handle runtime errors after startup
44 do
45     local in_error = false
46     awesome.connect_signal("debug::error", function (err)
47         -- Make sure we don't go into an endless error loop
48         if in_error then return end
49         in_error = true
50
51         naughty.notify({ preset = naughty.config.presets.critical,
52                          title = "Oops, an error happened!",
53                          text = tostring(err) })
54         in_error = false
55     end)
56 end
57 -- }}}
58
59 -- {{{ Variable definitions
60 -- Themes define colours, icons, font and wallpapers.
61 -- beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua")
62 beautiful.init(awful.util.get_themes_dir() .. "sky/theme.lua")
63 beautiful.wallpaper = "/home/mako/images/Flag_of_Cascadia.png"
64
65 -- This is used later as the default terminal and editor to run.
66 terminal = "x-terminal-emulator"
67 editor = os.getenv("EDITOR") or "editor"
68 editor_cmd = terminal .. " -e " .. editor
69
70 -- Default modkey.
71 -- Usually, Mod4 is the key with a logo between Control and Alt.
72 -- If you do not like this or do not have such a key,
73 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
74 -- However, you can use another modifier like Mod1, but it may interact with others.
75 modkey = "Mod4"
76
77 -- Table of layouts to cover with awful.layout.inc, order matters.
78 awful.layout.layouts = {
79     awful.layout.suit.tile,
80     awful.layout.suit.max,
81     awful.layout.suit.floating
82 }
83 -- }}}
84
85 -- {{{ Helper functions
86 local function client_menu_toggle_fn()
87     local instance = nil
88
89     return function ()
90         if instance and instance.wibox.visible then
91             instance:hide()
92             instance = nil
93         else
94             instance = awful.menu.clients({ theme = { width = 250 } })
95         end
96     end
97 end
98 -- }}}
99
100 -- {{{ Menu
101 -- Create a launcher widget and a main menu
102 myawesomemenu = {
103    { "hotkeys", function() return false, hotkeys_popup.show_help end},
104    { "manual", terminal .. " -e man awesome" },
105    { "edit config", editor_cmd .. " " .. awesome.conffile },
106    { "restart", awesome.restart },
107    { "quit", function() awesome.quit() end}
108 }
109
110 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
111                                     { "Debian", debian.menu.Debian_menu.Debian },
112                                     { "open terminal", terminal }
113                                   }
114                         })
115
116 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
117                                      menu = mymainmenu })
118
119 -- Menubar configuration
120 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
121 -- }}}
122
123 -- Keyboard map indicator and switcher
124 mykeyboardlayout = awful.widget.keyboardlayout()
125
126 -- {{{ Wibar
127 -- Create a textclock widget
128 mytextclock = wibox.widget.textclock("%a %m %d %H:%M", 60, tz_string)
129
130 -- Create a wibox for each screen and add it
131 local taglist_buttons = awful.util.table.join(
132                     awful.button({ }, 1, function(t) t:view_only() end),
133                     awful.button({ modkey }, 1, function(t)
134                                               if client.focus then
135                                                   client.focus:move_to_tag(t)
136                                               end
137                                           end),
138                     awful.button({ }, 3, awful.tag.viewtoggle),
139                     awful.button({ modkey }, 3, function(t)
140                                               if client.focus then
141                                                   client.focus:toggle_tag(t)
142                                               end
143                                           end),
144                     awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
145                     awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
146                 )
147
148 local tasklist_buttons = awful.util.table.join(
149                      awful.button({ }, 1, function (c)
150                                               if c == client.focus then
151                                                   c.minimized = true
152                                               else
153                                                   -- Without this, the following
154                                                   -- :isvisible() makes no sense
155                                                   c.minimized = false
156                                                   if not c:isvisible() and c.first_tag then
157                                                       c.first_tag:view_only()
158                                                   end
159                                                   -- This will also un-minimize
160                                                   -- the client, if needed
161                                                   client.focus = c
162                                                   c:raise()
163                                               end
164                                           end),
165                      awful.button({ }, 3, client_menu_toggle_fn()),
166                      awful.button({ }, 4, function ()
167                                               awful.client.focus.byidx(1)
168                                           end),
169                      awful.button({ }, 5, function ()
170                                               awful.client.focus.byidx(-1)
171                                           end))
172
173 local function set_wallpaper(s)
174     -- Wallpaper
175     if beautiful.wallpaper then
176         local wallpaper = beautiful.wallpaper
177         -- If wallpaper is a function, call it with the screen
178         if type(wallpaper) == "function" then
179             wallpaper = wallpaper(s)
180         end
181         gears.wallpaper.maximized(wallpaper, s, true)
182     end
183 end
184
185 -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
186 screen.connect_signal("property::geometry", set_wallpaper)
187
188 awful.screen.connect_for_each_screen(function(s)
189     -- Wallpaper
190     set_wallpaper(s)
191
192     -- Each screen has its own tag table.
193     awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
194
195     -- Create a promptbox for each screen
196     s.mypromptbox = awful.widget.prompt()
197     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
198     -- We need one layoutbox per screen.
199     s.mylayoutbox = awful.widget.layoutbox(s)
200     s.mylayoutbox:buttons(awful.util.table.join(
201                            awful.button({ }, 1, function () awful.layout.inc( 1) end),
202                            awful.button({ }, 3, function () awful.layout.inc(-1) end),
203                            awful.button({ }, 4, function () awful.layout.inc( 1) end),
204                            awful.button({ }, 5, function () awful.layout.inc(-1) end)))
205     -- Create a taglist widget
206     s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)
207
208     -- Create a tasklist widget
209     s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons)
210
211     -- Create the wibox
212     s.mywibox = awful.wibar({ position = "top", screen = s })
213
214     -- Add widgets to the wibox
215     s.mywibox:setup {
216         layout = wibox.layout.align.horizontal,
217         { -- Left widgets
218             layout = wibox.layout.fixed.horizontal,
219             mylauncher,
220             s.mytaglist,
221             s.mypromptbox,
222         },
223         s.mytasklist, -- Middle widget
224         { -- Right widgets
225             layout = wibox.layout.fixed.horizontal,
226             mykeyboardlayout,
227             wibox.widget.systray(),
228             -- volumecfg.widget,
229             mytextclock,
230             s.mylayoutbox,
231         },
232     }
233 end)
234 -- }}}
235
236 -- right_layout:add(volumecfg.widget)
237
238 -- {{{ Mouse bindings
239 root.buttons(awful.util.table.join(
240     awful.button({ }, 3, function () mymainmenu:toggle() end),
241     awful.button({ }, 4, awful.tag.viewnext),
242     awful.button({ }, 5, awful.tag.viewprev)
243 ))
244 -- }}}
245
246 -- {{{ Key bindings
247 globalkeys = awful.util.table.join(
248     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
249               {description="show help", group="awesome"}),
250     awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
251               {description = "view previous", group = "tag"}),
252     awful.key({ modkey,           }, "Right",  awful.tag.viewnext,
253               {description = "view next", group = "tag"}),
254     awful.key({ modkey,           }, "Escape", awful.tag.history.restore,
255               {description = "go back", group = "tag"}),
256
257     awful.key({ modkey,           }, "j",
258         function ()
259             awful.client.focus.byidx( 1)
260         end,
261         {description = "focus next by index", group = "client"}
262     ),
263     awful.key({ modkey,           }, "k",
264         function ()
265             awful.client.focus.byidx(-1)
266         end,
267         {description = "focus previous by index", group = "client"}
268     ),
269     awful.key({ modkey,           }, "w", function () mymainmenu:show() end,
270               {description = "show main menu", group = "awesome"}),
271
272     -- Layout manipulation
273     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end,
274               {description = "swap with next client by index", group = "client"}),
275     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end,
276               {description = "swap with previous client by index", group = "client"}),
277     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
278               {description = "focus the next screen", group = "screen"}),
279     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
280               {description = "focus the previous screen", group = "screen"}),
281     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto,
282               {description = "jump to urgent client", group = "client"}),
283     awful.key({ modkey,           }, "Tab",
284         function ()
285             awful.client.focus.history.previous()
286             if client.focus then
287                 client.focus:raise()
288             end
289         end,
290         {description = "go back", group = "client"}),
291
292     -- Standard program
293     awful.key({ modkey,           }, "Return", function () awful.spawn(terminal) end,
294               {description = "open a terminal", group = "launcher"}),
295     awful.key({ modkey, "Control" }, "r", awesome.restart,
296               {description = "reload awesome", group = "awesome"}),
297     awful.key({ modkey, "Shift"   }, "q", awesome.quit,
298               {description = "quit awesome", group = "awesome"}),
299
300     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)          end,
301               {description = "increase master width factor", group = "layout"}),
302     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)          end,
303               {description = "decrease master width factor", group = "layout"}),
304     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1, nil, true) end,
305               {description = "increase the number of master clients", group = "layout"}),
306     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1, nil, true) end,
307               {description = "decrease the number of master clients", group = "layout"}),
308     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1, nil, true)    end,
309               {description = "increase the number of columns", group = "layout"}),
310     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1, nil, true)    end,
311               {description = "decrease the number of columns", group = "layout"}),
312     awful.key({ modkey,           }, "space", function () awful.layout.inc( 1)                end,
313               {description = "select next", group = "layout"}),
314     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(-1)                end,
315               {description = "select previous", group = "layout"}),
316
317     awful.key({ modkey, "Control" }, "n",
318               function ()
319                   local c = awful.client.restore()
320                   -- Focus restored client
321                   if c then
322                       client.focus = c
323                       c:raise()
324                   end
325               end,
326               {description = "restore minimized", group = "client"}),
327
328     -- Prompt
329     awful.key({ modkey },            "r",     function () awful.screen.focused().mypromptbox:run() end,
330               {description = "run prompt", group = "launcher"}),
331     
332     awful.key({ modkey,  }, "x",
333               function ()
334                   awful.prompt.run {
335                     prompt       = "Run in terminal: ",
336                     textbox      = awful.screen.focused().mypromptbox.widget,
337                     exe_callback = function (prog) awful.util.spawn_with_shell(terminal .. " -title " .. prog .. " -e " .. prog) end
338                   }
339               end,
340               {description = "terminal execute prompt", group = "awesome"}),
341
342     -- Mako's additional keybindings
343     --- {{{
344     awful.key({ modkey, "Shift", }, "x",
345               function ()
346                   awful.prompt.run {
347                     prompt       = "Run Lua code: ",
348                     textbox      = awful.screen.focused().mypromptbox.widget,
349                     exe_callback = awful.util.eval,
350                     history_path = awful.util.get_cache_dir() .. "/history_eval"
351                   }
352               end,
353               {description = "lua execute prompt", group = "awesome"}),
354
355     awful.key({ modkey }, "q",
356                   function ()
357                       awful.tag.incnmaster(-1)
358                       awful.tag.incncol(3)
359               end),
360
361     awful.key({ modkey, "Shift" }, "t", awful.titlebar.toggle),
362
363     --- }}}
364
365     -- Menubar
366     awful.key({ modkey }, "p", function() menubar.show() end,
367               {description = "show the menubar", group = "launcher"})
368 )
369
370 clientkeys = awful.util.table.join(
371     awful.key({ modkey,           }, "f",
372         function (c)
373             c.fullscreen = not c.fullscreen
374             c:raise()
375         end,
376         {description = "toggle fullscreen", group = "client"}),
377     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end,
378               {description = "close", group = "client"}),
379     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ,
380               {description = "toggle floating", group = "client"}),
381     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
382               {description = "move to master", group = "client"}),
383     awful.key({ modkey,           }, "o",      function (c) c:move_to_screen()               end,
384               {description = "move to screen", group = "client"}),
385     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end,
386               {description = "toggle keep on top", group = "client"}),
387     awful.key({ modkey,           }, "n",
388         function (c)
389             -- The client currently has the input focus, so it cannot be
390             -- minimized, since minimized clients can't have the focus.
391             c.minimized = true
392         end ,
393         {description = "minimize", group = "client"}),
394     awful.key({ modkey,           }, "m",
395         function (c)
396             c.maximized = not c.maximized
397             c:raise()
398         end ,
399         {description = "maximize", group = "client"})
400 )
401
402 -- Bind all key numbers to tags.
403 -- Be careful: we use keycodes to make it works on any keyboard layout.
404 -- This should map on the top row of your keyboard, usually 1 to 9.
405 for i = 1, 9 do
406     globalkeys = awful.util.table.join(globalkeys,
407         -- View tag only.
408         awful.key({ modkey }, "#" .. i + 9,
409                   function ()
410                         local screen = awful.screen.focused()
411                         local tag = screen.tags[i]
412                         if tag then
413                            tag:view_only()
414                         end
415                   end,
416                   {description = "view tag #"..i, group = "tag"}),
417         -- Toggle tag display.
418         awful.key({ modkey, "Control" }, "#" .. i + 9,
419                   function ()
420                       local screen = awful.screen.focused()
421                       local tag = screen.tags[i]
422                       if tag then
423                          awful.tag.viewtoggle(tag)
424                       end
425                   end,
426                   {description = "toggle tag #" .. i, group = "tag"}),
427         -- Move client to tag.
428         awful.key({ modkey, "Shift" }, "#" .. i + 9,
429                   function ()
430                       if client.focus then
431                           local tag = client.focus.screen.tags[i]
432                           if tag then
433                               client.focus:move_to_tag(tag)
434                           end
435                      end
436                   end,
437                   {description = "move focused client to tag #"..i, group = "tag"}),
438         -- Toggle tag on focused client.
439         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
440                   function ()
441                       if client.focus then
442                           local tag = client.focus.screen.tags[i]
443                           if tag then
444                               client.focus:toggle_tag(tag)
445                           end
446                       end
447                   end,
448                   {description = "toggle focused client on tag #" .. i, group = "tag"}),
449         awful.key({}, "XF86AudioRaiseVolume", function() volumecfg:up() end),
450         awful.key({}, "XF86AudioLowerVolume", function() volumecfg:down() end),
451         awful.key({}, "XF86AudioMute",        function() volumecfg:toggle() end)
452     )
453 end
454
455 clientbuttons = awful.util.table.join(
456     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
457     awful.button({ modkey }, 1, awful.mouse.client.move),
458     awful.button({ modkey }, 3, awful.mouse.client.resize))
459
460 -- Set keys
461 root.keys(globalkeys)
462 -- }}}
463
464 -- {{{ Rules
465 -- Rules to apply to new clients (through the "manage" signal).
466 awful.rules.rules = {
467     -- All clients will match this rule.
468     { rule = { },
469       properties = { border_width = beautiful.border_width,
470                      border_color = beautiful.border_normal,
471                      focus = awful.client.focus.filter,
472                      raise = true,
473                      keys = clientkeys,
474                      buttons = clientbuttons,
475                      screen = awful.screen.preferred,
476                      placement = awful.placement.no_overlap+awful.placement.no_offscreen
477      }
478     },
479
480     -- Floating clients.
481     { rule_any = {
482         instance = {
483           "DTA",  -- Firefox addon DownThemAll.
484           "copyq",  -- Includes session name in class.
485         },
486         class = {
487           "Arandr",
488           "Gpick",
489           "Kruler",
490           "MessageWin",  -- kalarm.
491           "Sxiv",
492           "Wpa_gui",
493           "pinentry",
494           "veromix",
495           "xtightvncviewer"},
496
497         name = {
498           "Event Tester",  -- xev.
499         },
500         role = {
501           "AlarmWindow",  -- Thunderbird's calendar.
502           "pop-up",       -- e.g. Google Chrome's (detached) Developer Tools.
503         }
504       }, properties = { floating = true }},
505
506     -- Add titlebars to normal clients and dialogs
507     { rule_any = {type = { "normal", "dialog" }
508       }, properties = { titlebars_enabled = false }
509     },
510
511     -- Set Firefox to always map on the tag named "2" on screen 1.
512     -- { rule = { class = "Firefox" },
513     --   properties = { screen = 1, tag = "2" } },
514 }
515 -- }}}
516
517 -- {{{ Signals
518 -- Signal function to execute when a new client appears.
519 client.connect_signal("manage", function (c)
520     -- Set the windows at the slave,
521     -- i.e. put it at the end of others instead of setting it master.
522     -- if not awesome.startup then awful.client.setslave(c) end
523
524     if awesome.startup and
525       not c.size_hints.user_position
526       and not c.size_hints.program_position then
527         -- Prevent clients from being unreachable after screen count changes.
528         awful.placement.no_offscreen(c)
529     end
530 end)
531
532 -- Add a titlebar if titlebars_enabled is set to true in the rules.
533 client.connect_signal("request::titlebars", function(c)
534     -- buttons for the titlebar
535     local buttons = awful.util.table.join(
536         awful.button({ }, 1, function()
537             client.focus = c
538             c:raise()
539             awful.mouse.client.move(c)
540         end),
541         awful.button({ }, 3, function()
542             client.focus = c
543             c:raise()
544             awful.mouse.client.resize(c)
545         end)
546     )
547
548     awful.titlebar(c) : setup {
549         { -- Left
550             awful.titlebar.widget.iconwidget(c),
551             buttons = buttons,
552             layout  = wibox.layout.fixed.horizontal
553         },
554         { -- Middle
555             { -- Title
556                 align  = "center",
557                 widget = awful.titlebar.widget.titlewidget(c)
558             },
559             buttons = buttons,
560             layout  = wibox.layout.flex.horizontal
561         },
562         { -- Right
563             awful.titlebar.widget.floatingbutton (c),
564             awful.titlebar.widget.maximizedbutton(c),
565             awful.titlebar.widget.stickybutton   (c),
566             awful.titlebar.widget.ontopbutton    (c),
567             awful.titlebar.widget.closebutton    (c),
568             layout = wibox.layout.fixed.horizontal()
569         },
570         layout = wibox.layout.align.horizontal
571     }
572 end)
573
574 -- Enable sloppy focus, so that focus follows mouse.
575 client.connect_signal("mouse::enter", function(c)
576     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
577         and awful.client.focus.filter(c) then
578         client.focus = c
579     end
580 end)
581
582 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
583 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
584 -- }}}

Benjamin Mako Hill || Want to submit a patch?