]> git.donarmstrong.com Git - x_base.git/blob - .config/awesome/rc.lua
bd09d3d5ac23013df976ed075ab809947c43a7a3
[x_base.git] / .config / awesome / rc.lua
1 -- Standard awesome library
2 require("awful")
3 -- Theme handling library
4 require("beautiful")
5 -- Notification library
6 require("naughty")
7
8 -- Load Debian menu entries
9 require("debian.menu")
10
11 -- {{{ Variable definitions
12 -- Themes define colours, icons, and wallpapers
13 -- The default is a dark theme
14 theme_path = "/usr/share/awesome/themes/default/theme.lua"
15 -- Uncommment this for a lighter theme
16 -- theme_path = "/usr/share/awesome/themes/sky/theme.lua"
17
18 -- Actually load theme
19 beautiful.init(theme_path)
20
21 -- This is used later as the default terminal and editor to run.
22 terminal = "x-terminal-emulator"
23 editor = os.getenv("EDITOR") or "editor"
24 editor_cmd = terminal .. " -e " .. editor
25
26 -- Default modkey.
27 -- Usually, Mod4 is the key with a logo between Control and Alt.
28 -- If you do not like this or do not have such a key,
29 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
30 -- However, you can use another modifier like Mod1, but it may interact with others.
31 modkey = "Mod4"
32
33 -- Table of layouts to cover with awful.layout.inc, order matters.
34 layouts =
35 {
36     awful.layout.suit.tile,
37     awful.layout.suit.tile.left,
38     awful.layout.suit.tile.bottom,
39     awful.layout.suit.tile.top,
40     awful.layout.suit.fair,
41     awful.layout.suit.fair.horizontal,
42     awful.layout.suit.max,
43     awful.layout.suit.max.fullscreen,
44     awful.layout.suit.magnifier,
45     awful.layout.suit.floating
46 }
47
48 -- Table of clients that should be set floating. The index may be either
49 -- the application class or instance. The instance is useful when running
50 -- a console app in a terminal like (Music on Console)
51 --    x-terminal-emulator -name mocp -e mocp
52 floatapps =
53 {
54     -- by class
55     ["MPlayer"] = true,
56     ["pinentry"] = true,
57     ["gimp"] = true,
58     -- by instance
59     ["mocp"] = true
60 }
61
62 -- Applications to be moved to a pre-defined tag by class or instance.
63 -- Use the screen and tags indices.
64 apptags =
65 {
66     -- ["Firefox"] = { screen = 1, tag = 2 },
67     -- ["mocp"] = { screen = 2, tag = 4 },
68 }
69
70 -- Define if we want to use titlebar on all applications.
71 use_titlebar = false
72 -- }}}
73
74 -- {{{ Tags
75 -- Define tags table.
76 tags = {}
77 for s = 1, screen.count() do
78     -- Each screen has its own tag table.
79     tags[s] = {}
80     -- Create 9 tags per screen.
81     for tagnumber = 1, 9 do
82         tags[s][tagnumber] = tag(tagnumber)
83         -- Add tags to screen one by one
84         tags[s][tagnumber].screen = s
85         awful.layout.set(layouts[1], tags[s][tagnumber])
86     end
87     -- I'm sure you want to see at least one tag.
88     tags[s][1].selected = true
89 end
90 -- }}}
91
92 -- {{{ Wibox
93 -- Create a textbox widget
94 mytextbox = widget({ type = "textbox", align = "right" })
95 -- Set the default text in textbox
96 mytextbox.text = "<b><small> " .. awesome.release .. " </small></b>"
97
98 -- Create a laucher widget and a main menu
99 myawesomemenu = {
100    { "manual", terminal .. " -e man awesome" },
101    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
102    { "restart", awesome.restart },
103    { "quit", awesome.quit }
104 }
105
106 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
107                                         { "open terminal", terminal },
108                                         { "Debian", debian.menu.Debian_menu.Debian }
109                                       }
110                             })
111
112 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
113                                      menu = mymainmenu })
114
115 -- Create a systray
116 mysystray = widget({ type = "systray", align = "right" })
117
118 -- Create a wibox for each screen and add it
119 mywibox = {}
120 mypromptbox = {}
121 mylayoutbox = {}
122 mytaglist = {}
123 mytaglist.buttons = awful.util.table.join(
124                     awful.button({ }, 1, awful.tag.viewonly),
125                     awful.button({ modkey }, 1, awful.client.movetotag),
126                     awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
127                     awful.button({ modkey }, 3, awful.client.toggletag),
128                     awful.button({ }, 4, awful.tag.viewnext),
129                     awful.button({ }, 5, awful.tag.viewprev)
130                     )
131 mytasklist = {}
132 mytasklist.buttons = awful.util.table.join(
133                      awful.button({ }, 1, function (c)
134                                               if not c:isvisible() then
135                                                   awful.tag.viewonly(c:tags()[1])
136                                               end
137                                               client.focus = c
138                                               c:raise()
139                                           end),
140                      awful.button({ }, 3, function ()
141                                               if instance then
142                                                   instance:hide()
143                                                   instance = nil
144                                               else
145                                                   instance = awful.menu.clients({ width=250 })
146                                               end
147                                           end),
148                      awful.button({ }, 4, function ()
149                                               awful.client.focus.byidx(1)
150                                               if client.focus then client.focus:raise() end
151                                           end),
152                      awful.button({ }, 5, function ()
153                                               awful.client.focus.byidx(-1)
154                                               if client.focus then client.focus:raise() end
155                                           end))
156
157 for s = 1, screen.count() do
158     -- Create a promptbox for each screen
159     mypromptbox[s] = awful.widget.prompt({ align = "left" })
160     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
161     -- We need one layoutbox per screen.
162     mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
163     mylayoutbox[s]:buttons(awful.util.table.join(
164                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
165                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
166                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
167                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
168     -- Create a taglist widget
169     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
170
171     -- Create a tasklist widget
172     mytasklist[s] = awful.widget.tasklist(function(c)
173                                               return awful.widget.tasklist.label.currenttags(c, s)
174                                           end, mytasklist.buttons)
175
176     -- Create the wibox
177     mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
178     -- Add widgets to the wibox - order matters
179     mywibox[s].widgets = { mylauncher,
180                            mytaglist[s],
181                            mytasklist[s],
182                            mypromptbox[s],
183                            mytextbox,
184                            mylayoutbox[s],
185                            s == 1 and mysystray or nil }
186     mywibox[s].screen = s
187 end
188 -- }}}
189
190 -- {{{ Mouse bindings
191 root.buttons(awful.util.table.join(
192     awful.button({ }, 3, function () mymainmenu:toggle() end),
193     awful.button({ }, 4, awful.tag.viewnext),
194     awful.button({ }, 5, awful.tag.viewprev)
195 ))
196 -- }}}
197
198 -- {{{ Key bindings
199 globalkeys = awful.util.table.join(
200     -- awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
201     -- awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
202     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
203
204     awful.key({ modkey,           }, "j",
205         function ()
206             awful.client.focus.byidx( 1)
207             if client.focus then client.focus:raise() end
208         end),
209     awful.key({ modkey,           }, "k",
210         function ()
211             awful.client.focus.byidx(-1)
212             if client.focus then client.focus:raise() end
213         end),
214     awful.key({ modkey,           }, "w", function () mymainmenu:show(true)        end),
215
216     -- Layout manipulation
217     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1) end),
218     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1) end),
219     awful.key({ modkey,           }, "Left", function () awful.screen.focus( 1)       end),
220     awful.key({ modkey,           }, "Right", function () awful.screen.focus(-1)       end),
221     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
222     awful.key({ modkey,           }, "Tab",
223         function ()
224             awful.client.focus.history.previous()
225             if client.focus then
226                 client.focus:raise()
227             end
228         end),
229
230     -- Standard program
231     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
232     awful.key({ modkey, "Control", "Shift" }, "r", awesome.restart),
233     awful.key({ modkey, "Control", "Shift" }, "q", awesome.quit),
234
235     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
236     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
237     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
238     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
239     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
240     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
241     awful.key({ modkey,           }, "n",     function () awful.layout.inc(layouts,  1) end),
242     awful.key({ modkey, "Shift"   }, "n",     function () awful.layout.inc(layouts, -1) end),
243     
244     -- resize floats
245     awful.key({ modkey, "Shift" }, "Down",  function () awful.client.moveresize(0, 20, 0, 0) end),
246     awful.key({ modkey, "Shift" }, "Up",    function () awful.client.moveresize(0, -20, 0, 0) end),
247     awful.key({ modkey, "Shift" }, "Left",  function () awful.client.moveresize(-20, 0, 0, 0) end),
248     awful.key({ modkey, "Shift" }, "Right", function () awful.client.moveresize(20, 0, 0, 0) end),
249     awful.key({ modkey, "Control" }, "Down",  function () awful.client.moveresize(0, 0, 0, -20) end),
250     awful.key({ modkey, "Control" }, "Up",    function () awful.client.moveresize(0, 0, 0, 20) end),
251     awful.key({ modkey, "Control" }, "Left",  function () awful.client.moveresize(0, 0, -20, 0) end),
252     awful.key({ modkey, "Control" }, "Right", function () awful.client.moveresize(0, 0, 20, 0) end),
253
254     -- Prompt
255     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
256
257     awful.key({ modkey }, "x",
258               function ()
259                   awful.prompt.run({ prompt = "Run Lua code: " },
260                   mypromptbox[mouse.screen].widget,
261                   awful.util.eval, nil,
262                   awful.util.getdir("cache") .. "/history_eval")
263               end)
264 )
265
266 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
267 clientkeys = awful.util.table.join(
268     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
269     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
270     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
271     awful.key({ modkey,           }, "space",  function (c) c:swap(awful.client.getmaster()) end),
272     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
273     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
274     awful.key({ modkey }, "t", awful.client.togglemarked),
275     awful.key({ modkey, "Shift"   }, "t", function (c) c.ontop= not c.ontop end),
276     awful.key({ modkey,}, "m",
277         function (c)
278             c.maximized_horizontal = not c.maximized_horizontal
279             c.maximized_vertical   = not c.maximized_vertical
280         end)
281 )
282
283 -- Compute the maximum number of digit we need, limited to 9
284 keynumber = 0
285 for s = 1, screen.count() do
286    keynumber = math.min(9, math.max(#tags[s], keynumber));
287 end
288
289 for i = 1, keynumber do
290     globalkeys = awful.util.table.join(globalkeys,
291         awful.key({ modkey }, i,
292                   function ()
293                         local screen = mouse.screen
294                         if tags[screen][i] then
295                             awful.tag.viewonly(tags[screen][i])
296                         end
297                   end),
298         awful.key({ modkey, "Control" }, i,
299                   function ()
300                       local screen = mouse.screen
301                       if tags[screen][i] then
302                           tags[screen][i].selected = not tags[screen][i].selected
303                       end
304                   end),
305         awful.key({ modkey, "Shift" }, i,
306                   function ()
307                       if client.focus and tags[client.focus.screen][i] then
308                           awful.client.movetotag(tags[client.focus.screen][i])
309                       end
310                   end),
311         awful.key({ modkey, "Control", "Shift" }, i,
312                   function ()
313                       if client.focus and tags[client.focus.screen][i] then
314                           awful.client.toggletag(tags[client.focus.screen][i])
315                       end
316                   end),
317         awful.key({ modkey, "Shift" }, "F" .. i,
318                   function ()
319                       local screen = mouse.screen
320                       if tags[screen][i] then
321                           for k, c in pairs(awful.client.getmarked()) do
322                               awful.client.movetotag(tags[screen][i], c)
323                           end
324                       end
325                    end))
326 end
327
328 -- Set keys
329 root.keys(globalkeys)
330 -- }}}
331
332 -- {{{ Hooks
333 -- Hook function to execute when focusing a client.
334 awful.hooks.focus.register(function (c)
335     if not awful.client.ismarked(c) then
336         c.border_color = beautiful.border_focus
337     end
338 end)
339
340 -- Hook function to execute when unfocusing a client.
341 awful.hooks.unfocus.register(function (c)
342     if not awful.client.ismarked(c) then
343         c.border_color = beautiful.border_normal
344     end
345 end)
346
347 -- Hook function to execute when marking a client
348 awful.hooks.marked.register(function (c)
349     c.border_color = beautiful.border_marked
350 end)
351
352 -- Hook function to execute when unmarking a client.
353 awful.hooks.unmarked.register(function (c)
354     c.border_color = beautiful.border_focus
355 end)
356
357 -- Hook function to execute when the mouse enters a client.
358 awful.hooks.mouse_enter.register(function (c)
359     -- Sloppy focus, but disabled for magnifier layout
360     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
361         and awful.client.focus.filter(c) then
362         client.focus = c
363     end
364 end)
365
366 -- Hook function to execute when a new client appears.
367 awful.hooks.manage.register(function (c, startup)
368     -- If we are not managing this application at startup,
369     -- move it to the screen where the mouse is.
370     -- We only do it for filtered windows (i.e. no dock, etc).
371     if not startup and awful.client.focus.filter(c) then
372         c.screen = mouse.screen
373     end
374
375     if use_titlebar then
376         -- Add a titlebar
377         awful.titlebar.add(c, { modkey = modkey })
378     end
379     -- Add mouse bindings
380     c:buttons(awful.util.table.join(
381         awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
382         awful.button({ modkey }, 1, awful.mouse.client.move),
383         awful.button({ modkey }, 3, awful.mouse.client.resize)
384     ))
385     -- New client may not receive focus
386     -- if they're not focusable, so set border anyway.
387     c.border_width = beautiful.border_width
388     c.border_color = beautiful.border_normal
389
390     -- Check if the application should be floating.
391     local cls = c.class
392     local inst = c.instance
393     if floatapps[cls] ~= nil then
394         awful.client.floating.set(c, floatapps[cls])
395     elseif floatapps[inst] ~= nil then
396         awful.client.floating.set(c, floatapps[inst])
397     end
398
399     -- Check application->screen/tag mappings.
400     local target
401     if apptags[cls] then
402         target = apptags[cls]
403     elseif apptags[inst] then
404         target = apptags[inst]
405     end
406     if target then
407         c.screen = target.screen
408         awful.client.movetotag(tags[target.screen][target.tag], c)
409     end
410
411     -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
412     client.focus = c
413
414     -- Set key bindings
415     c:keys(clientkeys)
416
417     -- Set the windows at the slave,
418     -- i.e. put it at the end of others instead of setting it master.
419     -- awful.client.setslave(c)
420
421     -- Honor size hints: if you want to drop the gaps between windows, set this to false.
422     -- c.size_hints_honor = false
423 end)
424
425 -- Hook function to execute when arranging the screen.
426 -- (tag switch, new client, etc)
427 awful.hooks.arrange.register(function (screen)
428     local layout = awful.layout.getname(awful.layout.get(screen))
429     if layout and beautiful["layout_" ..layout] then
430         mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
431     else
432         mylayoutbox[screen].image = nil
433     end
434
435     -- Give focus to the latest client in history if no window has focus
436     -- or if the current window is a desktop or a dock one.
437     if not client.focus then
438         local c = awful.client.focus.history.get(screen, 0)
439         if c then client.focus = c end
440     end
441 end)
442
443 -- Hook called every minute
444 awful.hooks.timer.register(1, function ()
445     mytextbox.text = os.date(" %c ")
446 end)
447 -- }}}