Update .bashrc
[dotfiles/.git] / .config / awesome / rc.lua.template
1 --[[
2
3      Awesome WM configuration template
4      github.com/lcpz
5
6 --]]
7
8 -- {{{ Required libraries
9 local awesome, client, mouse, screen, tag = awesome, client, mouse, screen, tag
10 local ipairs, string, os, table, tostring, tonumber, type = ipairs, string, os, table, tostring, tonumber, type
11
12 local gears         = require("gears")
13 local awful         = require("awful")
14                       require("awful.autofocus")
15 local wibox         = require("wibox")
16 local beautiful     = require("beautiful")
17 local naughty       = require("naughty")
18 local lain          = require("lain")
19 --local menubar       = require("menubar")
20 local freedesktop   = require("freedesktop")
21 local hotkeys_popup = require("awful.hotkeys_popup").widget
22                       require("awful.hotkeys_popup.keys")
23 local my_table      = awful.util.table or gears.table -- 4.{0,1} compatibility
24 local dpi           = require("beautiful.xresources").apply_dpi
25 -- }}}
26
27 -- {{{ Error handling
28 -- Check if awesome encountered an error during startup and fell back to
29 -- another config (This code will only ever execute for the fallback config)
30 if awesome.startup_errors then
31     naughty.notify({ preset = naughty.config.presets.critical,
32                      title = "Oops, there were errors during startup!",
33                      text = awesome.startup_errors })
34 end
35
36 -- Handle runtime errors after startup
37 do
38     local in_error = false
39     awesome.connect_signal("debug::error", function (err)
40         if in_error then return end
41         in_error = true
42
43         naughty.notify({ preset = naughty.config.presets.critical,
44                          title = "Oops, an error happened!",
45                          text = tostring(err) })
46         in_error = false
47     end)
48 end
49 -- }}}
50
51 -- {{{ Autostart windowless processes
52
53 -- This function will run once every time Awesome is started
54 local function run_once(cmd_arr)
55     for _, cmd in ipairs(cmd_arr) do
56         awful.spawn.with_shell(string.format("pgrep -u $USER -fx '%s' > /dev/null || (%s)", cmd, cmd))
57     end
58 end
59
60 run_once({ "urxvtd", "unclutter -root" }) -- entries must be separated by commas
61
62 -- This function implements the XDG autostart specification
63 --[[
64 awful.spawn.with_shell(
65     'if (xrdb -query | grep -q "^awesome\\.started:\\s*true$"); then exit; fi;' ..
66     'xrdb -merge <<< "awesome.started:true";' ..
67     -- list each of your autostart commands, followed by ; inside single quotes, followed by ..
68     'dex --environment Awesome --autostart --search-paths "$XDG_CONFIG_DIRS/autostart:$XDG_CONFIG_HOME/autostart"' -- https://github.com/jceb/dex
69 )
70 --]]
71
72 -- }}}
73
74 -- {{{ Variable definitions
75
76 local themes = {
77     "blackburn",       -- 1
78     "copland",         -- 2
79     "dremora",         -- 3
80     "holo",            -- 4
81     "multicolor",      -- 5
82     "powerarrow",      -- 6
83     "powerarrow-dark", -- 7
84     "rainbow",         -- 8
85     "steamburn",       -- 9
86     "vertex",          -- 10
87 }
88
89 local chosen_theme = themes[5]
90 local modkey       = "Mod4"
91 local altkey       = "Mod1"
92 local terminal     = "urxvtc"
93 local vi_focus     = false -- vi-like client focus - https://github.com/lcpz/awesome-copycats/issues/275
94 local cycle_prev   = true -- cycle trough all previous client or just the first -- https://github.com/lcpz/awesome-copycats/issues/274
95 local editor       = os.getenv("EDITOR") or "vim"
96 local gui_editor   = os.getenv("GUI_EDITOR") or "gvim"
97 local browser      = os.getenv("BROWSER") or "firefox"
98 local scrlocker    = "slock"
99
100 awful.util.terminal = terminal
101 awful.util.tagnames = { "1", "2", "3", "4", "5" }
102 awful.layout.layouts = {
103     awful.layout.suit.floating,
104     awful.layout.suit.tile,
105     awful.layout.suit.tile.left,
106     awful.layout.suit.tile.bottom,
107     awful.layout.suit.tile.top,
108     --awful.layout.suit.fair,
109     --awful.layout.suit.fair.horizontal,
110     --awful.layout.suit.spiral,
111     --awful.layout.suit.spiral.dwindle,
112     --awful.layout.suit.max,
113     --awful.layout.suit.max.fullscreen,
114     --awful.layout.suit.magnifier,
115     --awful.layout.suit.corner.nw,
116     --awful.layout.suit.corner.ne,
117     --awful.layout.suit.corner.sw,
118     --awful.layout.suit.corner.se,
119     --lain.layout.cascade,
120     --lain.layout.cascade.tile,
121     --lain.layout.centerwork,
122     --lain.layout.centerwork.horizontal,
123     --lain.layout.termfair,
124     --lain.layout.termfair.center,
125 }
126
127 awful.util.taglist_buttons = my_table.join(
128     awful.button({ }, 1, function(t) t:view_only() end),
129     awful.button({ modkey }, 1, function(t)
130         if client.focus then
131             client.focus:move_to_tag(t)
132         end
133     end),
134     awful.button({ }, 3, awful.tag.viewtoggle),
135     awful.button({ modkey }, 3, function(t)
136         if client.focus then
137             client.focus:toggle_tag(t)
138         end
139     end),
140     awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
141     awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
142 )
143
144 awful.util.tasklist_buttons = my_table.join(
145     awful.button({ }, 1, function (c)
146         if c == client.focus then
147             c.minimized = true
148         else
149             --c:emit_signal("request::activate", "tasklist", {raise = true})<Paste>
150
151             -- Without this, the following
152             -- :isvisible() makes no sense
153             c.minimized = false
154             if not c:isvisible() and c.first_tag then
155                 c.first_tag:view_only()
156             end
157             -- This will also un-minimize
158             -- the client, if needed
159             client.focus = c
160             c:raise()
161         end
162     end),
163     awful.button({ }, 2, function (c) c:kill() end),
164     awful.button({ }, 3, function ()
165         local instance = nil
166
167         return function ()
168             if instance and instance.wibox.visible then
169                 instance:hide()
170                 instance = nil
171             else
172                 instance = awful.menu.clients({theme = {width = dpi(250)}})
173             end
174         end
175     end),
176     awful.button({ }, 4, function () awful.client.focus.byidx(1) end),
177     awful.button({ }, 5, function () awful.client.focus.byidx(-1) end)
178 )
179
180 lain.layout.termfair.nmaster           = 3
181 lain.layout.termfair.ncol              = 1
182 lain.layout.termfair.center.nmaster    = 3
183 lain.layout.termfair.center.ncol       = 1
184 lain.layout.cascade.tile.offset_x      = dpi(2)
185 lain.layout.cascade.tile.offset_y      = dpi(32)
186 lain.layout.cascade.tile.extra_padding = dpi(5)
187 lain.layout.cascade.tile.nmaster       = 5
188 lain.layout.cascade.tile.ncol          = 2
189
190 beautiful.init(string.format("%s/.config/awesome/themes/%s/theme.lua", os.getenv("HOME"), chosen_theme))
191 -- }}}
192
193 -- {{{ Menu
194 local myawesomemenu = {
195     { "hotkeys", function() return false, hotkeys_popup.show_help end },
196     { "manual", terminal .. " -e man awesome" },
197     { "edit config", string.format("%s -e %s %s", terminal, editor, awesome.conffile) },
198     { "restart", awesome.restart },
199     { "quit", function() awesome.quit() end }
200 }
201 awful.util.mymainmenu = freedesktop.menu.build({
202     icon_size = beautiful.menu_height or dpi(16),
203     before = {
204         { "Awesome", myawesomemenu, beautiful.awesome_icon },
205         -- other triads can be put here
206     },
207     after = {
208         { "Open terminal", terminal },
209         -- other triads can be put here
210     }
211 })
212 -- hide menu when mouse leaves it
213 --awful.util.mymainmenu.wibox:connect_signal("mouse::leave", function() awful.util.mymainmenu:hide() end)
214
215 --menubar.utils.terminal = terminal -- Set the Menubar terminal for applications that require it
216 -- }}}
217
218 -- {{{ Screen
219 -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
220 screen.connect_signal("property::geometry", function(s)
221     -- Wallpaper
222     if beautiful.wallpaper then
223         local wallpaper = beautiful.wallpaper
224         -- If wallpaper is a function, call it with the screen
225         if type(wallpaper) == "function" then
226             wallpaper = wallpaper(s)
227         end
228         gears.wallpaper.maximized(wallpaper, s, true)
229     end
230 end)
231
232 -- No borders when rearranging only 1 non-floating or maximized client
233 screen.connect_signal("arrange", function (s)
234     local only_one = #s.tiled_clients == 1
235     for _, c in pairs(s.clients) do
236         if only_one and not c.floating or c.maximized then
237             c.border_width = 0
238         else
239             c.border_width = beautiful.border_width
240         end
241     end
242 end)
243 -- Create a wibox for each screen and add it
244 awful.screen.connect_for_each_screen(function(s) beautiful.at_screen_connect(s) end)
245 -- }}}
246
247 -- {{{ Mouse bindings
248 root.buttons(my_table.join(
249     awful.button({ }, 3, function () awful.util.mymainmenu:toggle() end),
250     awful.button({ }, 4, awful.tag.viewnext),
251     awful.button({ }, 5, awful.tag.viewprev)
252 ))
253 -- }}}
254
255 -- {{{ Key bindings
256 globalkeys = my_table.join(
257     -- Take a screenshot
258     -- https://github.com/lcpz/dots/blob/master/bin/screenshot
259     awful.key({ altkey }, "p", function() os.execute("screenshot") end,
260               {description = "take a screenshot", group = "hotkeys"}),
261
262     -- X screen locker
263     awful.key({ altkey, "Control" }, "l", function () os.execute(scrlocker) end,
264               {description = "lock screen", group = "hotkeys"}),
265
266     -- Hotkeys
267     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
268               {description = "show help", group="awesome"}),
269     -- Tag browsing
270     awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
271               {description = "view previous", group = "tag"}),
272     awful.key({ modkey,           }, "Right",  awful.tag.viewnext,
273               {description = "view next", group = "tag"}),
274     awful.key({ modkey,           }, "Escape", awful.tag.history.restore,
275               {description = "go back", group = "tag"}),
276
277     -- Non-empty tag browsing
278     awful.key({ altkey }, "Left", function () lain.util.tag_view_nonempty(-1) end,
279               {description = "view  previous nonempty", group = "tag"}),
280     awful.key({ altkey }, "Right", function () lain.util.tag_view_nonempty(1) end,
281               {description = "view  previous nonempty", group = "tag"}),
282
283     -- Default client focus
284     awful.key({ altkey,           }, "j",
285         function ()
286             awful.client.focus.byidx( 1)
287         end,
288         {description = "focus next by index", group = "client"}
289     ),
290     awful.key({ altkey,           }, "k",
291         function ()
292             awful.client.focus.byidx(-1)
293         end,
294         {description = "focus previous by index", group = "client"}
295     ),
296
297     -- By direction client focus
298     awful.key({ modkey }, "j",
299         function()
300             awful.client.focus.global_bydirection("down")
301             if client.focus then client.focus:raise() end
302         end,
303         {description = "focus down", group = "client"}),
304     awful.key({ modkey }, "k",
305         function()
306             awful.client.focus.global_bydirection("up")
307             if client.focus then client.focus:raise() end
308         end,
309         {description = "focus up", group = "client"}),
310     awful.key({ modkey }, "h",
311         function()
312             awful.client.focus.global_bydirection("left")
313             if client.focus then client.focus:raise() end
314         end,
315         {description = "focus left", group = "client"}),
316     awful.key({ modkey }, "l",
317         function()
318             awful.client.focus.global_bydirection("right")
319             if client.focus then client.focus:raise() end
320         end,
321         {description = "focus right", group = "client"}),
322     awful.key({ modkey,           }, "w", function () awful.util.mymainmenu:show() end,
323               {description = "show main menu", group = "awesome"}),
324
325     -- Layout manipulation
326     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end,
327               {description = "swap with next client by index", group = "client"}),
328     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end,
329               {description = "swap with previous client by index", group = "client"}),
330     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
331               {description = "focus the next screen", group = "screen"}),
332     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
333               {description = "focus the previous screen", group = "screen"}),
334     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto,
335               {description = "jump to urgent client", group = "client"}),
336     awful.key({ modkey,           }, "Tab",
337         function ()
338             if cycle_prev then
339                 awful.client.focus.history.previous()
340             else
341                 awful.client.focus.byidx(-1)
342             end
343             if client.focus then
344                 client.focus:raise()
345             end
346         end,
347         {description = "cycle with previous/go back", group = "client"}),
348     awful.key({ modkey, "Shift"   }, "Tab",
349         function ()
350             if cycle_prev then
351                 awful.client.focus.byidx(1)
352                 if client.focus then
353                     client.focus:raise()
354                 end
355             end
356         end,
357         {description = "go forth", group = "client"}),
358
359     -- Show/Hide Wibox
360     awful.key({ modkey }, "b", function ()
361             for s in screen do
362                 s.mywibox.visible = not s.mywibox.visible
363                 if s.mybottomwibox then
364                     s.mybottomwibox.visible = not s.mybottomwibox.visible
365                 end
366             end
367         end,
368         {description = "toggle wibox", group = "awesome"}),
369
370     -- On the fly useless gaps change
371     awful.key({ altkey, "Control" }, "+", function () lain.util.useless_gaps_resize(1) end,
372               {description = "increment useless gaps", group = "tag"}),
373     awful.key({ altkey, "Control" }, "-", function () lain.util.useless_gaps_resize(-1) end,
374               {description = "decrement useless gaps", group = "tag"}),
375
376     -- Dynamic tagging
377     awful.key({ modkey, "Shift" }, "n", function () lain.util.add_tag() end,
378               {description = "add new tag", group = "tag"}),
379     awful.key({ modkey, "Shift" }, "r", function () lain.util.rename_tag() end,
380               {description = "rename tag", group = "tag"}),
381     awful.key({ modkey, "Shift" }, "Left", function () lain.util.move_tag(-1) end,
382               {description = "move tag to the left", group = "tag"}),
383     awful.key({ modkey, "Shift" }, "Right", function () lain.util.move_tag(1) end,
384               {description = "move tag to the right", group = "tag"}),
385     awful.key({ modkey, "Shift" }, "d", function () lain.util.delete_tag() end,
386               {description = "delete tag", group = "tag"}),
387
388     -- Standard program
389     awful.key({ modkey,           }, "Return", function () awful.spawn(terminal) end,
390               {description = "open a terminal", group = "launcher"}),
391     awful.key({ modkey, "Control" }, "r", awesome.restart,
392               {description = "reload awesome", group = "awesome"}),
393     awful.key({ modkey, "Shift"   }, "q", awesome.quit,
394               {description = "quit awesome", group = "awesome"}),
395
396     awful.key({ altkey, "Shift"   }, "l",     function () awful.tag.incmwfact( 0.05)          end,
397               {description = "increase master width factor", group = "layout"}),
398     awful.key({ altkey, "Shift"   }, "h",     function () awful.tag.incmwfact(-0.05)          end,
399               {description = "decrease master width factor", group = "layout"}),
400     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1, nil, true) end,
401               {description = "increase the number of master clients", group = "layout"}),
402     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1, nil, true) end,
403               {description = "decrease the number of master clients", group = "layout"}),
404     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1, nil, true)    end,
405               {description = "increase the number of columns", group = "layout"}),
406     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1, nil, true)    end,
407               {description = "decrease the number of columns", group = "layout"}),
408     awful.key({ modkey,           }, "space", function () awful.layout.inc( 1)                end,
409               {description = "select next", group = "layout"}),
410     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(-1)                end,
411               {description = "select previous", group = "layout"}),
412
413     awful.key({ modkey, "Control" }, "n",
414               function ()
415                   local c = awful.client.restore()
416                   -- Focus restored client
417                   if c then
418                       client.focus = c
419                       c:raise()
420                   end
421               end,
422               {description = "restore minimized", group = "client"}),
423
424     -- Dropdown application
425     awful.key({ modkey, }, "z", function () awful.screen.focused().quake:toggle() end,
426               {description = "dropdown application", group = "launcher"}),
427
428     -- Widgets popups
429     awful.key({ altkey, }, "c", function () if beautiful.cal then beautiful.cal.show(7) end end,
430               {description = "show calendar", group = "widgets"}),
431     awful.key({ altkey, }, "h", function () if beautiful.fs then beautiful.fs.show(7) end end,
432               {description = "show filesystem", group = "widgets"}),
433     awful.key({ altkey, }, "w", function () if beautiful.weather then beautiful.weather.show(7) end end,
434               {description = "show weather", group = "widgets"}),
435
436     -- Brightness
437     awful.key({ }, "XF86MonBrightnessUp", function () os.execute("xbacklight -inc 10") end,
438               {description = "+10%", group = "hotkeys"}),
439     awful.key({ }, "XF86MonBrightnessDown", function () os.execute("xbacklight -dec 10") end,
440               {description = "-10%", group = "hotkeys"}),
441
442     -- ALSA volume control
443     awful.key({ altkey }, "Up",
444         function ()
445             os.execute(string.format("amixer -q set %s 1%%+", beautiful.volume.channel))
446             beautiful.volume.update()
447         end,
448         {description = "volume up", group = "hotkeys"}),
449     awful.key({ altkey }, "Down",
450         function ()
451             os.execute(string.format("amixer -q set %s 1%%-", beautiful.volume.channel))
452             beautiful.volume.update()
453         end,
454         {description = "volume down", group = "hotkeys"}),
455     awful.key({ altkey }, "m",
456         function ()
457             os.execute(string.format("amixer -q set %s toggle", beautiful.volume.togglechannel or beautiful.volume.channel))
458             beautiful.volume.update()
459         end,
460         {description = "toggle mute", group = "hotkeys"}),
461     awful.key({ altkey, "Control" }, "m",
462         function ()
463             os.execute(string.format("amixer -q set %s 100%%", beautiful.volume.channel))
464             beautiful.volume.update()
465         end,
466         {description = "volume 100%", group = "hotkeys"}),
467     awful.key({ altkey, "Control" }, "0",
468         function ()
469             os.execute(string.format("amixer -q set %s 0%%", beautiful.volume.channel))
470             beautiful.volume.update()
471         end,
472         {description = "volume 0%", group = "hotkeys"}),
473
474     -- MPD control
475     awful.key({ altkey, "Control" }, "Up",
476         function ()
477             os.execute("mpc toggle")
478             beautiful.mpd.update()
479         end,
480         {description = "mpc toggle", group = "widgets"}),
481     awful.key({ altkey, "Control" }, "Down",
482         function ()
483             os.execute("mpc stop")
484             beautiful.mpd.update()
485         end,
486         {description = "mpc stop", group = "widgets"}),
487     awful.key({ altkey, "Control" }, "Left",
488         function ()
489             os.execute("mpc prev")
490             beautiful.mpd.update()
491         end,
492         {description = "mpc prev", group = "widgets"}),
493     awful.key({ altkey, "Control" }, "Right",
494         function ()
495             os.execute("mpc next")
496             beautiful.mpd.update()
497         end,
498         {description = "mpc next", group = "widgets"}),
499     awful.key({ altkey }, "0",
500         function ()
501             local common = { text = "MPD widget ", position = "top_middle", timeout = 2 }
502             if beautiful.mpd.timer.started then
503                 beautiful.mpd.timer:stop()
504                 common.text = common.text .. lain.util.markup.bold("OFF")
505             else
506                 beautiful.mpd.timer:start()
507                 common.text = common.text .. lain.util.markup.bold("ON")
508             end
509             naughty.notify(common)
510         end,
511         {description = "mpc on/off", group = "widgets"}),
512
513     -- Copy primary to clipboard (terminals to gtk)
514     awful.key({ modkey }, "c", function () awful.spawn.with_shell("xsel | xsel -i -b") end,
515               {description = "copy terminal to gtk", group = "hotkeys"}),
516     -- Copy clipboard to primary (gtk to terminals)
517     awful.key({ modkey }, "v", function () awful.spawn.with_shell("xsel -b | xsel") end,
518               {description = "copy gtk to terminal", group = "hotkeys"}),
519
520     -- User programs
521     awful.key({ modkey }, "q", function () awful.spawn(browser) end,
522               {description = "run browser", group = "launcher"}),
523     awful.key({ modkey }, "a", function () awful.spawn(gui_editor) end,
524               {description = "run gui editor", group = "launcher"}),
525
526     -- Default
527     --[[ Menubar
528     awful.key({ modkey }, "p", function() menubar.show() end,
529               {description = "show the menubar", group = "launcher"})
530     --]]
531     --[[ dmenu
532     awful.key({ modkey }, "x", function ()
533             os.execute(string.format("dmenu_run -i -fn 'Monospace' -nb '%s' -nf '%s' -sb '%s' -sf '%s'",
534             beautiful.bg_normal, beautiful.fg_normal, beautiful.bg_focus, beautiful.fg_focus))
535         end,
536         {description = "show dmenu", group = "launcher"})
537     --]]
538     -- alternatively use rofi, a dmenu-like application with more features
539     -- check https://github.com/DaveDavenport/rofi for more details
540     --[[ rofi
541     awful.key({ modkey }, "x", function ()
542             os.execute(string.format("rofi -show %s -theme %s",
543             'run', 'dmenu'))
544         end,
545         {description = "show rofi", group = "launcher"}),
546     --]]
547     -- Prompt
548     awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end,
549               {description = "run prompt", group = "launcher"}),
550
551     awful.key({ modkey }, "x",
552               function ()
553                   awful.prompt.run {
554                     prompt       = "Run Lua code: ",
555                     textbox      = awful.screen.focused().mypromptbox.widget,
556                     exe_callback = awful.util.eval,
557                     history_path = awful.util.get_cache_dir() .. "/history_eval"
558                   }
559               end,
560               {description = "lua execute prompt", group = "awesome"})
561     --]]
562 )
563
564 clientkeys = my_table.join(
565     awful.key({ altkey, "Shift"   }, "m",      lain.util.magnify_client,
566               {description = "magnify client", group = "client"}),
567     awful.key({ modkey,           }, "f",
568         function (c)
569             c.fullscreen = not c.fullscreen
570             c:raise()
571         end,
572         {description = "toggle fullscreen", group = "client"}),
573     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end,
574               {description = "close", group = "client"}),
575     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ,
576               {description = "toggle floating", group = "client"}),
577     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
578               {description = "move to master", group = "client"}),
579     awful.key({ modkey,           }, "o",      function (c) c:move_to_screen()               end,
580               {description = "move to screen", group = "client"}),
581     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end,
582               {description = "toggle keep on top", group = "client"}),
583     awful.key({ modkey,           }, "n",
584         function (c)
585             -- The client currently has the input focus, so it cannot be
586             -- minimized, since minimized clients can't have the focus.
587             c.minimized = true
588         end ,
589         {description = "minimize", group = "client"}),
590     awful.key({ modkey,           }, "m",
591         function (c)
592             c.maximized = not c.maximized
593             c:raise()
594         end ,
595         {description = "maximize", group = "client"})
596 )
597
598 -- Bind all key numbers to tags.
599 -- Be careful: we use keycodes to make it works on any keyboard layout.
600 -- This should map on the top row of your keyboard, usually 1 to 9.
601 for i = 1, 9 do
602     -- Hack to only show tags 1 and 9 in the shortcut window (mod+s)
603     local descr_view, descr_toggle, descr_move, descr_toggle_focus
604     if i == 1 or i == 9 then
605         descr_view = {description = "view tag #", group = "tag"}
606         descr_toggle = {description = "toggle tag #", group = "tag"}
607         descr_move = {description = "move focused client to tag #", group = "tag"}
608         descr_toggle_focus = {description = "toggle focused client on tag #", group = "tag"}
609     end
610     globalkeys = my_table.join(globalkeys,
611         -- View tag only.
612         awful.key({ modkey }, "#" .. i + 9,
613                   function ()
614                         local screen = awful.screen.focused()
615                         local tag = screen.tags[i]
616                         if tag then
617                            tag:view_only()
618                         end
619                   end,
620                   descr_view),
621         -- Toggle tag display.
622         awful.key({ modkey, "Control" }, "#" .. i + 9,
623                   function ()
624                       local screen = awful.screen.focused()
625                       local tag = screen.tags[i]
626                       if tag then
627                          awful.tag.viewtoggle(tag)
628                       end
629                   end,
630                   descr_toggle),
631         -- Move client to tag.
632         awful.key({ modkey, "Shift" }, "#" .. i + 9,
633                   function ()
634                       if client.focus then
635                           local tag = client.focus.screen.tags[i]
636                           if tag then
637                               client.focus:move_to_tag(tag)
638                           end
639                      end
640                   end,
641                   descr_move),
642         -- Toggle tag on focused client.
643         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
644                   function ()
645                       if client.focus then
646                           local tag = client.focus.screen.tags[i]
647                           if tag then
648                               client.focus:toggle_tag(tag)
649                           end
650                       end
651                   end,
652                   descr_toggle_focus)
653     )
654 end
655
656 clientbuttons = gears.table.join(
657     awful.button({ }, 1, function (c)
658         c:emit_signal("request::activate", "mouse_click", {raise = true})
659     end),
660     awful.button({ modkey }, 1, function (c)
661         c:emit_signal("request::activate", "mouse_click", {raise = true})
662         awful.mouse.client.move(c)
663     end),
664     awful.button({ modkey }, 3, function (c)
665         c:emit_signal("request::activate", "mouse_click", {raise = true})
666         awful.mouse.client.resize(c)
667     end)
668 )
669
670 -- Set keys
671 root.keys(globalkeys)
672 -- }}}
673
674 -- {{{ Rules
675 -- Rules to apply to new clients (through the "manage" signal).
676 awful.rules.rules = {
677     -- All clients will match this rule.
678     { rule = { },
679       properties = { border_width = beautiful.border_width,
680                      border_color = beautiful.border_normal,
681                      focus = awful.client.focus.filter,
682                      raise = true,
683                      keys = clientkeys,
684                      buttons = clientbuttons,
685                      screen = awful.screen.preferred,
686                      placement = awful.placement.no_overlap+awful.placement.no_offscreen,
687                      size_hints_honor = false
688      }
689     },
690
691     -- Titlebars
692     { rule_any = { type = { "dialog", "normal" } },
693       properties = { titlebars_enabled = true } },
694
695     -- Set Firefox to always map on the first tag on screen 1.
696     { rule = { class = "Firefox" },
697       properties = { screen = 1, tag = awful.util.tagnames[1] } },
698
699     { rule = { class = "Gimp", role = "gimp-image-window" },
700           properties = { maximized = true } },
701 }
702 -- }}}
703
704 -- {{{ Signals
705 -- Signal function to execute when a new client appears.
706 client.connect_signal("manage", function (c)
707     -- Set the windows at the slave,
708     -- i.e. put it at the end of others instead of setting it master.
709     -- if not awesome.startup then awful.client.setslave(c) end
710
711     if awesome.startup and
712       not c.size_hints.user_position
713       and not c.size_hints.program_position then
714         -- Prevent clients from being unreachable after screen count changes.
715         awful.placement.no_offscreen(c)
716     end
717 end)
718
719 -- Add a titlebar if titlebars_enabled is set to true in the rules.
720 client.connect_signal("request::titlebars", function(c)
721     -- Custom
722     if beautiful.titlebar_fun then
723         beautiful.titlebar_fun(c)
724         return
725     end
726
727     -- Default
728     -- buttons for the titlebar
729     local buttons = my_table.join(
730         awful.button({ }, 1, function()
731             c:emit_signal("request::activate", "titlebar", {raise = true})
732             awful.mouse.client.move(c)
733         end),
734         awful.button({ }, 2, function() c:kill() end),
735         awful.button({ }, 3, function()
736             c:emit_signal("request::activate", "titlebar", {raise = true})
737             awful.mouse.client.resize(c)
738         end)
739     )
740
741     awful.titlebar(c, {size = dpi(16)}) : setup {
742         { -- Left
743             awful.titlebar.widget.iconwidget(c),
744             buttons = buttons,
745             layout  = wibox.layout.fixed.horizontal
746         },
747         { -- Middle
748             { -- Title
749                 align  = "center",
750                 widget = awful.titlebar.widget.titlewidget(c)
751             },
752             buttons = buttons,
753             layout  = wibox.layout.flex.horizontal
754         },
755         { -- Right
756             awful.titlebar.widget.floatingbutton (c),
757             awful.titlebar.widget.maximizedbutton(c),
758             awful.titlebar.widget.stickybutton   (c),
759             awful.titlebar.widget.ontopbutton    (c),
760             awful.titlebar.widget.closebutton    (c),
761             layout = wibox.layout.fixed.horizontal()
762         },
763         layout = wibox.layout.align.horizontal
764     }
765 end)
766
767 -- Enable sloppy focus, so that focus follows mouse.
768 client.connect_signal("mouse::enter", function(c)
769     c:emit_signal("request::activate", "mouse_enter", {raise = vi_focus})
770 end)
771
772 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
773 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
774
775 -- possible workaround for tag preservation when switching back to default screen:
776 -- https://github.com/lcpz/awesome-copycats/issues/251
777 -- }}}