]> git.donarmstrong.com Git - x_base.git/blob - .config/awesome/rc.lua
* update rc.lua for awesome 3.3
[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     -- Prompt
245     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
246
247     awful.key({ modkey }, "x",
248               function ()
249                   awful.prompt.run({ prompt = "Run Lua code: " },
250                   mypromptbox[mouse.screen].widget,
251                   awful.util.eval, nil,
252                   awful.util.getdir("cache") .. "/history_eval")
253               end)
254 )
255
256 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
257 clientkeys = awful.util.table.join(
258     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
259     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
260     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
261     awful.key({ modkey,           }, "space",  function (c) c:swap(awful.client.getmaster()) end),
262     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
263     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
264     awful.key({ modkey }, "t", awful.client.togglemarked),
265     awful.key({ modkey,}, "m",
266         function (c)
267             c.maximized_horizontal = not c.maximized_horizontal
268             c.maximized_vertical   = not c.maximized_vertical
269         end)
270 )
271
272 -- Compute the maximum number of digit we need, limited to 9
273 keynumber = 0
274 for s = 1, screen.count() do
275    keynumber = math.min(9, math.max(#tags[s], keynumber));
276 end
277
278 for i = 1, keynumber do
279     globalkeys = awful.util.table.join(globalkeys,
280         awful.key({ modkey }, i,
281                   function ()
282                         local screen = mouse.screen
283                         if tags[screen][i] then
284                             awful.tag.viewonly(tags[screen][i])
285                         end
286                   end),
287         awful.key({ modkey, "Control" }, i,
288                   function ()
289                       local screen = mouse.screen
290                       if tags[screen][i] then
291                           tags[screen][i].selected = not tags[screen][i].selected
292                       end
293                   end),
294         awful.key({ modkey, "Shift" }, i,
295                   function ()
296                       if client.focus and tags[client.focus.screen][i] then
297                           awful.client.movetotag(tags[client.focus.screen][i])
298                       end
299                   end),
300         awful.key({ modkey, "Control", "Shift" }, i,
301                   function ()
302                       if client.focus and tags[client.focus.screen][i] then
303                           awful.client.toggletag(tags[client.focus.screen][i])
304                       end
305                   end),
306         awful.key({ modkey, "Shift" }, "F" .. i,
307                   function ()
308                       local screen = mouse.screen
309                       if tags[screen][i] then
310                           for k, c in pairs(awful.client.getmarked()) do
311                               awful.client.movetotag(tags[screen][i], c)
312                           end
313                       end
314                    end))
315 end
316
317 -- Set keys
318 root.keys(globalkeys)
319 -- }}}
320
321 -- {{{ Hooks
322 -- Hook function to execute when focusing a client.
323 awful.hooks.focus.register(function (c)
324     if not awful.client.ismarked(c) then
325         c.border_color = beautiful.border_focus
326     end
327 end)
328
329 -- Hook function to execute when unfocusing a client.
330 awful.hooks.unfocus.register(function (c)
331     if not awful.client.ismarked(c) then
332         c.border_color = beautiful.border_normal
333     end
334 end)
335
336 -- Hook function to execute when marking a client
337 awful.hooks.marked.register(function (c)
338     c.border_color = beautiful.border_marked
339 end)
340
341 -- Hook function to execute when unmarking a client.
342 awful.hooks.unmarked.register(function (c)
343     c.border_color = beautiful.border_focus
344 end)
345
346 -- Hook function to execute when the mouse enters a client.
347 awful.hooks.mouse_enter.register(function (c)
348     -- Sloppy focus, but disabled for magnifier layout
349     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
350         and awful.client.focus.filter(c) then
351         client.focus = c
352     end
353 end)
354
355 -- Hook function to execute when a new client appears.
356 awful.hooks.manage.register(function (c, startup)
357     -- If we are not managing this application at startup,
358     -- move it to the screen where the mouse is.
359     -- We only do it for filtered windows (i.e. no dock, etc).
360     if not startup and awful.client.focus.filter(c) then
361         c.screen = mouse.screen
362     end
363
364     if use_titlebar then
365         -- Add a titlebar
366         awful.titlebar.add(c, { modkey = modkey })
367     end
368     -- Add mouse bindings
369     c:buttons(awful.util.table.join(
370         awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
371         awful.button({ modkey }, 1, awful.mouse.client.move),
372         awful.button({ modkey }, 3, awful.mouse.client.resize)
373     ))
374     -- New client may not receive focus
375     -- if they're not focusable, so set border anyway.
376     c.border_width = beautiful.border_width
377     c.border_color = beautiful.border_normal
378
379     -- Check if the application should be floating.
380     local cls = c.class
381     local inst = c.instance
382     if floatapps[cls] ~= nil then
383         awful.client.floating.set(c, floatapps[cls])
384     elseif floatapps[inst] ~= nil then
385         awful.client.floating.set(c, floatapps[inst])
386     end
387
388     -- Check application->screen/tag mappings.
389     local target
390     if apptags[cls] then
391         target = apptags[cls]
392     elseif apptags[inst] then
393         target = apptags[inst]
394     end
395     if target then
396         c.screen = target.screen
397         awful.client.movetotag(tags[target.screen][target.tag], c)
398     end
399
400     -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
401     client.focus = c
402
403     -- Set key bindings
404     c:keys(clientkeys)
405
406     -- Set the windows at the slave,
407     -- i.e. put it at the end of others instead of setting it master.
408     -- awful.client.setslave(c)
409
410     -- Honor size hints: if you want to drop the gaps between windows, set this to false.
411     -- c.size_hints_honor = false
412 end)
413
414 -- Hook function to execute when arranging the screen.
415 -- (tag switch, new client, etc)
416 awful.hooks.arrange.register(function (screen)
417     local layout = awful.layout.getname(awful.layout.get(screen))
418     if layout and beautiful["layout_" ..layout] then
419         mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
420     else
421         mylayoutbox[screen].image = nil
422     end
423
424     -- Give focus to the latest client in history if no window has focus
425     -- or if the current window is a desktop or a dock one.
426     if not client.focus then
427         local c = awful.client.focus.history.get(screen, 0)
428         if c then client.focus = c end
429     end
430 end)
431
432 -- Hook called every minute
433 awful.hooks.timer.register(60, function ()
434     mytextbox.text = os.date(" %c ")
435 end)
436 -- }}}