]> git.madduck.net Git - etc/awesome.git/blob - .config/awesome/rc.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

follow config changes
[etc/awesome.git] / .config / awesome / rc.lua
1 -- awesome 3 configuration file
2
3 AWESOME_DATADIR = "/home/madduck/code/awesome"
4 package.path = AWESOME_DATADIR .. "/lib/?.lua;" .. package.path
5
6 -- Include awesome library, with lots of useful function!
7 require("awful")
8 require("tabulous")
9 require("beautiful")
10
11 -- {{{ Variable definitions
12 -- This is a file path to a theme file which will defines colors.
13 theme_path = AWESOME_DATADIR .. "/themes/default"
14
15 -- This is used later as the default terminal to run.
16 terminal = "x-terminal-emulator"
17
18 -- Default modkey.
19 -- Usually, Mod4 is the key with a logo between Control and Alt.
20 -- If you do not like this or do not have such a key,
21 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
22 -- However, you can use another modifier like Mod1, but it may interact with others.
23 modkey = "Mod4"
24
25 -- Table of layouts to cover with awful.layout.inc, order matters.
26 layouts =
27 {
28     "tile",
29     "tileleft",
30     "tilebottom",
31     "tiletop",
32 --    "magnifier",
33     "max",
34 --    "spiral",
35 --    "dwindle",
36     "floating"
37 }
38
39 -- Table of clients that should be set floating. The index may be either
40 -- the application class or instance. The instance is useful when running
41 -- a console app in a terminal like (Music on Console)
42 --    xterm -name mocp -e mocp
43 floatapps =
44 {
45     -- by class
46     ["MPlayer"] = true,
47     ["pinentry"] = true,
48     ["GIMP"] = true,
49     ["twinkle"] = true,
50     ["Add-ons"] = true,
51     ["Play stream"] = true
52 }
53
54 -- Applications to be moved to a pre-defined tag by class or instance.
55 -- Use the screen and workspace indices.
56 apptags =
57 {
58     ["Firefox"] = { screen = 1, tag = 9 },
59     ["jpilot"] = { screen = 1, tag = 8 },
60 }
61
62 -- Define if we want to use titlebar on all applications.
63 use_titlebar = false
64 -- }}}
65
66 -- {{{ Initialization
67 -- Initialize theme (colors).
68 beautiful.init(theme_path)
69
70 -- Register theme in awful.
71 -- This allows to not pass plenty of arguments to each function
72 -- to inform it about colors we want it to draw.
73 awful.beautiful.register(beautiful)
74
75 -- Uncomment this to activate autotabbing
76 -- tabulous.autotab_start()
77 -- }}}
78
79 -- {{{ Tags
80 -- Define tags table.
81 tags = {}
82 for s = 1, screen.count() do
83     -- Each screen has its own tag table.
84     tags[s] = {}
85     -- Create 9 tags per screen.
86     for tagnumber = 1, 9 do
87         tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
88         -- Add tags to screen one by one
89         -- split at 0.5/50% exactly
90         -- tags[s][tagnumber].mwfact = 0.5
91         tags[s][tagnumber].screen = s
92     end
93     -- I'm sure you want to see at least one tag.
94     tags[s][1].selected = true
95 end
96 -- }}}
97
98 -- {{{ Statusbar
99 -- Create a taglist widget
100 mytaglist = widget({ type = "taglist", name = "mytaglist" })
101 mytaglist:mouse_add(mouse({}, 1, function (object, tag) awful.tag.viewonly(tag) end))
102 mytaglist:mouse_add(mouse({ modkey }, 1, function (object, tag) awful.client.movetotag(tag) end))
103 mytaglist:mouse_add(mouse({}, 3, function (object, tag) tag.selected = not tag.selected end))
104 mytaglist:mouse_add(mouse({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end))
105 mytaglist:mouse_add(mouse({ }, 4, awful.tag.viewnext))
106 mytaglist:mouse_add(mouse({ }, 5, awful.tag.viewprev))
107 mytaglist.label = awful.widget.taglist.label.all
108
109 -- Create a tasklist widget
110 mytasklist = widget({ type = "tasklist", name = "mytasklist" })
111 mytasklist:mouse_add(mouse({ }, 1, function (object, c) client.focus = c; c:raise() end))
112 mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focusbyidx(1) end))
113 mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focusbyidx(-1) end))
114 mytasklist.label = awful.widget.tasklist.label.currenttags
115
116 -- Create a textbox widget
117 mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" })
118 -- Set the default text in textbox
119 mytextbox.text = "<b><small> awesome " .. AWESOME_VERSION .. " </small></b>"
120 mypromptbox = widget({ type = "textbox", name = "mypromptbox", align = "left" })
121
122 -- Create an iconbox widget
123 myiconbox = widget({ type = "textbox", name = "myiconbox", align = "left" })
124 myiconbox.text = "<bg image=\"" .. AWESOME_DATADIR .. "/icons/awesome16.png\" resize=\"true\"/>"
125
126 -- Create a systray
127 mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
128
129 -- Create an iconbox widget which will contains an icon indicating which layout we're using.
130 -- We need one layoutbox per screen.
131 mylayoutbox = {}
132 for s = 1, screen.count() do
133     mylayoutbox[s] = widget({ type = "textbox", name = "mylayoutbox", align = "right" })
134     mylayoutbox[s]:mouse_add(mouse({ }, 1, function () awful.layout.inc(layouts, 1) end))
135     mylayoutbox[s]:mouse_add(mouse({ }, 3, function () awful.layout.inc(layouts, -1) end))
136     mylayoutbox[s]:mouse_add(mouse({ }, 4, function () awful.layout.inc(layouts, 1) end))
137     mylayoutbox[s]:mouse_add(mouse({ }, 5, function () awful.layout.inc(layouts, -1) end))
138     mylayoutbox[s].text = "<bg image=\"" .. AWESOME_DATADIR .. "/layouts/tilew.png\" resize=\"true\"/>"
139 end
140
141 -- Create a statusbar for each screen and add it
142 mystatusbar = {}
143 for s = 1, screen.count() do
144     mystatusbar[s] = statusbar({ position = "top", name = "mystatusbar" .. s,
145                                    fg = beautiful.fg_normal, bg = beautiful.bg_normal })
146     -- Add widgets to the statusbar - order matters
147     mystatusbar[s]:widgets({
148         mytaglist,
149         mytasklist,
150         mypromptbox,
151         mytextbox,
152         mylayoutbox[s],
153         s == screen.count() and mysystray or nil
154     })
155     mystatusbar[s].screen = s
156 end
157 -- }}}
158
159 -- {{{ Mouse bindings
160 awesome.mouse_add(mouse({ }, 3, function () awful.spawn(terminal) end))
161 awesome.mouse_add(mouse({ }, 4, awful.tag.viewnext))
162 awesome.mouse_add(mouse({ }, 5, awful.tag.viewprev))
163 -- }}}
164
165 -- {{{ Key bindings
166
167 -- Bind keyboard digits
168 -- Compute the maximum number of digit we need, limited to 9
169 keynumber = 0
170 for s = 1, screen.count() do
171    keynumber = math.min(9, math.max(#tags[s], keynumber));
172 end
173
174 for i = 1, keynumber do
175     keybinding({ modkey }, i,
176                    function ()
177                        local screen = mouse.screen
178                        if tags[screen][i] then
179                            awful.tag.viewonly(tags[screen][i])
180                        end
181                    end):add()
182     keybinding({ modkey, "Control" }, i,
183                    function ()
184                        local screen = mouse.screen
185                        if tags[screen][i] then
186                            tags[screen][i].selected = not tags[screen][i].selected
187                        end
188                    end):add()
189     keybinding({ modkey, "Shift" }, i,
190                    function ()
191                        local sel = client.focus
192                        if sel then
193                            if tags[sel.screen][i] then
194                                awful.client.movetotag(tags[sel.screen][i])
195                            end
196                        end
197                    end):add()
198     keybinding({ modkey, "Control", "Shift" }, i,
199                    function ()
200                        local sel = client.focus
201                        if sel then
202                            if tags[sel.screen][i] then
203                                awful.client.toggletag(tags[sel.screen][i])
204                            end
205                        end
206                    end):add()
207 end
208
209 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
210 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
211 keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
212
213 -- Standard program
214 keybinding({ modkey }, "Return", function () awful.spawn(terminal) end):add()
215
216 keybinding({ modkey, "Control" }, "r", awesome.restart):add()
217 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
218
219 -- Client manipulation
220 keybinding({ modkey }, "m", awful.client.maximize):add()
221 keybinding({ modkey, "Shift" }, "c", function () client.focus:kill() end):add()
222 keybinding({ modkey }, "j", function () awful.client.focusbyidx(1); client.focus:raise() end):add()
223 keybinding({ modkey }, "k", function () awful.client.focusbyidx(-1);  client.focus:raise() end):add()
224 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
225 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add()
226 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
227 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
228 keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
229 keybinding({ modkey, "Control" }, "Return", function () client.focus:swap(awful.client.master()) end):add()
230 keybinding({ modkey }, "o", awful.client.movetoscreen):add()
231 keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
232 keybinding({ modkey }, "u", awful.client.urgent.jumpto):add()
233 keybinding({ modkey, "Shift" }, "r", function () client.focus:redraw() end):add()
234
235 -- Layout manipulation
236 keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
237 keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
238 keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
239 keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
240 keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
241 keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
242 keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
243 keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
244
245 -- Prompt
246 keybinding({ modkey }, "F1", function ()
247                                  awful.prompt.run({ prompt = "Run: " }, mypromptbox, awful.spawn, awful.completion.bash,
248 os.getenv("HOME") .. "/.cache/awesome/history") end):add()
249 keybinding({ modkey }, "F4", function ()
250                                  awful.prompt.run({ prompt = "Run Lua code: " }, mypromptbox, awful.eval, awful.prompt.bash,
251 os.getenv("HOME") .. "/.cache/awesome/history_eval") end):add()
252 keybinding({ modkey, "Ctrl" }, "i", function ()
253                                         if mypromptbox.text then
254                                             mypromptbox.text = nil
255                                         else
256                                             mypromptbox.text = "Class: " .. client.focus.class .. " Instance: ".. client.focus.instance
257                                         end
258                                     end):add()
259
260 --- Tabulous, tab manipulation
261 keybinding({ modkey, "Control" }, "y", function ()
262     local tabbedview = tabulous.tabindex_get()
263     local nextclient = awful.client.next(1)
264
265     if not tabbedview then
266         tabbedview = tabulous.tabindex_get(nextclient)
267
268         if not tabbedview then
269             tabbedview = tabulous.tab_create()
270             tabulous.tab(tabbedview, nextclient)
271         else
272             tabulous.tab(tabbedview, client.focus)
273         end
274     else
275         tabulous.tab(tabbedview, nextclient)
276     end
277 end):add()
278
279 keybinding({ modkey, "Shift" }, "y", tabulous.untab):add()
280
281 keybinding({ modkey }, "y", function ()
282    local tabbedview = tabulous.tabindex_get()
283
284    if tabbedview then
285        local n = tabulous.next(tabbedview)
286        tabulous.display(tabbedview, n)
287    end
288 end):add()
289
290 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
291 keybinding({ modkey }, "t", awful.client.togglemarked):add()
292 keybinding({ modkey, 'Shift' }, "t", function ()
293     local tabbedview = tabulous.tabindex_get()
294     local clients = awful.client.getmarked()
295
296     if not tabbedview then
297         tabbedview = tabulous.tab_create(clients[1])
298         table.remove(clients, 1)
299     end
300
301     for k,c in pairs(clients) do
302         tabulous.tab(tabbedview, c)
303     end
304
305 end):add()
306
307 for i = 1, keynumber do
308     keybinding({ modkey, "Shift" }, "F" .. i,
309                    function ()
310                        local screen = mouse.screen
311                        if tags[screen][i] then
312                            for k, c in pairs(awful.client.getmarked()) do
313                                awful.client.movetotag(tags[screen][i], c)
314                            end
315                        end
316                    end):add()
317 end
318 -- }}}
319
320 -- {{{ Hooks
321 -- Hook function to execute when focusing a client.
322 function hook_focus(c)
323     if not awful.client.ismarked(c) then
324         c.border_color = beautiful.border_focus
325     end
326 end
327
328 -- Hook function to execute when unfocusing a client.
329 function hook_unfocus(c)
330     if not awful.client.ismarked(c) then
331         c.border_color = beautiful.border_normal
332     end
333 end
334
335 -- Hook function to execute when marking a client
336 function hook_marked(c)
337     c.border_color = beautiful.border_marked
338 end
339
340 -- Hook function to execute when unmarking a client
341 function hook_unmarked(c)
342     c.border_color = beautiful.border_focus
343 end
344
345 -- Hook function to execute when the mouse is over a client.
346 function hook_mouseover(c)
347     -- Sloppy focus, but disabled for magnifier layout
348     if awful.layout.get(c.screen) ~= "magnifier" then
349         client.focus = c
350     end
351 end
352
353 -- Hook function to execute when a new client appears.
354 function hook_manage(c)
355     -- Set floating placement to be smart!
356     c.floating_placement = "smart"
357     if use_titlebar then
358         -- Add a titlebar
359         awful.titlebar.add(c, { modkey = modkey })
360     end
361     -- Add mouse bindings
362     c:mouse_add(mouse({ }, 1, function (c) client.focus = c; c:raise() end))
363     c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
364     c:mouse_add(mouse({ modkey }, 3, function (c) c:mouse_resize() end))
365     -- New client may not receive focus
366     -- if they're not focusable, so set border anyway.
367     c.border_width = beautiful.border_width
368     c.border_color = beautiful.border_normal
369     client.focus = c
370
371     -- Check if the application should be floating.
372     local cls = c.class
373     local inst = c.instance
374     if floatapps[cls] then
375         c.floating = floatapps[cls]
376     elseif floatapps[inst] then
377         c.floating = floatapps[inst]
378     end
379
380     -- Check application->screen/tag mappings.
381     local target
382     if apptags[cls] then
383         target = apptags[cls]
384     elseif apptags[inst] then
385         target = apptags[inst]
386     end
387     if target then
388         c.screen = target.screen
389         awful.client.movetotag(tags[target.screen][target.tag], c)
390     end
391
392     -- Honor size hints
393     c.honorsizehints = true
394 end
395
396 -- Hook function to execute when arranging the screen
397 -- (tag switch, new client, etc)
398 function hook_arrange(screen)
399     local layout = awful.layout.get(screen)
400     if layout then
401         mylayoutbox[screen].text =
402             "<bg image=\"/home/madduck/code/awesome/share/awesome/icons/layouts/" .. awful.layout.get(screen) .. "w.png\" resize=\"true\"/>"
403         else
404             mylayoutbox[screen].text = "No layout."
405     end
406
407     -- If no window has focus, give focus to the latest in history
408     if not client.focus then
409         local c = awful.client.focus.history.get(screen, 0)
410         if c then client.focus = c end
411     end
412
413     -- Uncomment if you want mouse warping
414     --[[
415     local sel = client.focus
416     if sel then
417         local c_c = sel:coords()
418         local m_c = mouse.coords()
419
420         if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
421             m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
422             if table.maxn(m_c.buttons) == 0 then
423                 mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
424             end
425         end
426     end
427     ]]
428 end
429
430 -- Hook called every second
431 function hook_timer ()
432     -- For unix time_t lovers
433     -- mytextbox.text = " " .. os.time() .. " time_t "
434     -- Otherwise use:
435     mytextbox.text = " " .. os.date() .. " "
436 end
437
438 -- Set up some hooks
439 awful.hooks.focus.register(hook_focus)
440 awful.hooks.unfocus.register(hook_unfocus)
441 awful.hooks.marked.register(hook_marked)
442 awful.hooks.unmarked.register(hook_unmarked)
443 awful.hooks.manage.register(hook_manage)
444 awful.hooks.mouseover.register(hook_mouseover)
445 awful.hooks.arrange.register(hook_arrange)
446 awful.hooks.timer.register(1, hook_timer)
447 -- }}}
448
449 cmdmodkey = "Mod3"
450
451 -- xmms2 & sound
452 keybinding({ cmdmodkey }, "Prior", function () awful.spawn("amixer set Master 2+") end):add()
453 keybinding({ cmdmodkey }, "Next", function () awful.spawn("amixer set Master 2-") end):add()
454 keybinding({ cmdmodkey }, "Up", function () awful.spawn("amixer set PCM 2+") end):add()
455 keybinding({ cmdmodkey }, "Down", function () awful.spawn("amixer set PCM 2-") end):add()
456 keybinding({ cmdmodkey }, "Home", function () awful.spawn("amixer set Mic toggle") end):add()
457 keybinding({ cmdmodkey }, "End", function () awful.spawn("amixer set Master toggle") end):add()
458 keybinding({ cmdmodkey }, "Left", function () awful.spawn("xmms2 prev") end):add()
459 keybinding({ cmdmodkey }, "Right", function () awful.spawn("xmms2 next") end):add()
460 keybinding({ cmdmodkey }, "space", function () awful.spawn("xmms2 toggleplay") end):add()
461 keybinding({ cmdmodkey }, "backslash", function () awful.spawn("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end):add()
462 keybinding({ cmdmodkey, "Shift" }, "backslash", function () awful.spawn("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end):add()
463
464 -- misc apps
465 keybinding({ cmdmodkey }, "n", function () awful.spawn("sensible-browser") end):add()
466 keybinding({ cmdmodkey }, "m", function () awful.spawn(terminal .. " -e mutt -f =store") end):add()
467 keybinding({ cmdmodkey }, "t", function () awful.spawn(terminal) end):add()
468 keybinding({ cmdmodkey }, "c", function () awful.spawn(terminal .. " -e python") end):add()
469 keybinding({ cmdmodkey }, "r", function () awful.spawn("gmrun") end):add()
470 keybinding({ cmdmodkey }, "j", function () awful.spawn("jpilot") end):add()
471 keybinding({ cmdmodkey }, "x", function () awful.spawn("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end):add()
472 keybinding({ cmdmodkey, "Shift" }, "x", function () awful.spawn("xscreensaver-command -exit") end):add()
473
474 -- Highlight statusbars on the screen that has focus, 
475 -- set this to false if you only have one screen or 
476 -- you don't like it :P
477 if screen.count() > 1 then
478   statusbar_highlight_focus = true
479 else
480   statusbar_highlight_focus = false
481 end