]> 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:

b819f023f34d3f58f0d96be1a24ceddf084db97f
[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
10 -- Uncomment this to activate autotabbing
11 -- tabulous.autotab_start()
12
13 -- {{{ Variable definitions
14 -- This is used later as the default terminal to run.
15 terminal = "x-terminal-emulator"
16
17 -- Default modkey.
18 -- Usually, Mod4 is the key with a logo between Control and Alt.
19 -- If you do not like this or do not have such a key,
20 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
21 -- However, you can use another modifier like Mod1, but it may interact with others.
22 modkey = "Mod4"
23
24 -- Table of layouts to cover with awful.layout.inc, order matters.
25 layouts =
26 {
27     "tile",
28     "tileleft",
29     "tilebottom",
30     "tiletop",
31     "magnifier",
32     "max",
33     "spiral",
34     "dwindle",
35     "floating"
36 }
37
38 -- Table of clients that should be set floating
39 floatings =
40 {
41     ["mplayer"] = true,
42     ["pinentry"] = true,
43     ["GIMP"] = true,
44     ["twinkle"] = true,
45     ["Add-ons"] = true,
46     ["Play stream"] = true
47 }
48
49 -- Color & Appearance definitions, we use these later to display things
50 font = "RotisSansSerif 10"
51 border_width = 1
52
53 bg_normal = "#222222"
54 fg_normal = "#aaaaaa"
55 border_normal = "#000000"
56
57 bg_focus = "#535d6c"
58 fg_focus = "#ffffff"
59 border_focus = bg_focus
60 border_marked = "#91231C"
61
62 awesome.font_set(font)
63 awesome.colors_set({ fg = fg_normal, bg = bg_normal })
64
65 -- }}}
66
67 -- {{{ Tags
68 -- Define tags table
69 tags = {}
70 for s = 1, screen.count() do
71     -- Each screen has its own tag table
72     tags[s] = {}
73     -- Create 9 tags per screen
74     for tagnumber = 1, 9 do
75         tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
76         -- Add tags to screen one by one
77         -- split at 0.5/50% exactly
78         tags[s][tagnumber].mwfact = 0.5
79         tags[s][tagnumber]:add(s)
80     end
81     -- I'm sure you want to see at least one tag.
82     tags[s][1].selected = true
83 end
84 -- }}}
85
86 -- {{{ Statusbar
87 -- Create a taglist widget
88 mytaglist = widget({ type = "taglist", name = "mytaglist" })
89 mytaglist:mouse_add(mouse({}, 1, function (object, tag) awful.tag.viewonly(tag) end))
90 mytaglist:mouse_add(mouse({ modkey }, 1, function (object, tag) awful.client.movetotag(tag) end))
91 mytaglist:mouse_add(mouse({}, 3, function (object, tag) tag.selected = not tag.selected end))
92 mytaglist:mouse_add(mouse({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end))
93 mytaglist:mouse_add(mouse({ }, 4, awful.tag.viewnext))
94 mytaglist:mouse_add(mouse({ }, 5, awful.tag.viewprev))
95 function mytaglist.label(t)
96     local text = ""
97     if t.selected then
98         text = "<bg color='"..bg_focus.."'/> <span color='"..fg_focus.."'>"..t.name.."</span> "
99     else
100         text = " "..t.name.." "
101     end
102     return text
103 end
104
105 -- Create a tasklist widget
106 mytasklist = widget({ type = "tasklist", name = "mytasklist" })
107 mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end))
108 mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focus(1) end))
109 mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focus(-1) end))
110 function mytasklist.label(c)
111     local text = ""
112     if c.floating then
113         text = "<bg image=\"" .. AWESOME_DATADIR .. "/icons/floatingw.png\" align=\"right\"/>"
114     end
115     if client.focus_get() == c then
116         text = text .. " <bg color='"..bg_focus.."'/><span color='"..awful.escape(fg_focus).."'>"..c.name.."</span> "
117     else
118         text = text .. " "..awful.escape(c.name).." "
119     end
120     return text
121 end
122
123 -- Create a textbox widget
124 mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" })
125 -- Set the default text in textbox
126 mytextbox.text = "<b><small> awesome " .. AWESOME_VERSION .. " </small></b>"
127 mypromptbox = widget({ type = "textbox", name = "mypromptbox", align = "left" })
128
129 -- Create an iconbox widget
130 myiconbox = widget({ type = "textbox", name = "myiconbox", align = "left" })
131 myiconbox.text = "<bg image=\"" .. AWESOME_DATADIR .. "/icons/awesome16.png\" resize=\"true\"/>"
132
133 -- Create a systray
134 mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
135
136 -- Create an iconbox widget which will contains an icon indicating which layout we're using.
137 -- We need one layoutbox per screen.
138 mylayoutbox = {}
139 for s = 1, screen.count() do
140     mylayoutbox[s] = widget({ type = "textbox", name = "mylayoutbox", align = "right" })
141     mylayoutbox[s]:mouse_add(mouse({ }, 1, function () awful.layout.inc(layouts, 1) end))
142     mylayoutbox[s]:mouse_add(mouse({ }, 3, function () awful.layout.inc(layouts, -1) end))
143     mylayoutbox[s]:mouse_add(mouse({ }, 4, function () awful.layout.inc(layouts, 1) end))
144     mylayoutbox[s]:mouse_add(mouse({ }, 5, function () awful.layout.inc(layouts, -1) end))
145     mylayoutbox[s].text = "<bg image=\"" .. AWESOME_DATADIR .. "/layouts/tilew.png\" resize=\"true\"/>"
146 end
147
148 -- Create a statusbar for each screen and add it
149 mystatusbar = {}
150 for s = 1, screen.count() do
151     mystatusbar[s] = statusbar({ position = "top", name = "mystatusbar" .. s,
152                                    fg = fg_normal, bg = bg_normal })
153     -- Add widgets to the statusbar - order matters
154     mystatusbar[s]:widget_add(mytaglist)
155     mystatusbar[s]:widget_add(mytasklist)
156     mystatusbar[s]:widget_add(mypromptbox)
157     mystatusbar[s]:widget_add(mytextbox)
158     mystatusbar[s]:widget_add(mylayoutbox[s])
159     mystatusbar[s]:add(s)
160 end
161 mystatusbar[screen.count()]:widget_add(mysystray)
162 -- }}}
163
164 -- {{{ Mouse bindings
165 awesome.mouse_add(mouse({ }, 3, function () awful.spawn(terminal) end))
166 awesome.mouse_add(mouse({ }, 4, awful.tag.viewnext))
167 awesome.mouse_add(mouse({ }, 5, awful.tag.viewprev))
168 -- }}}
169
170 -- {{{ Key bindings
171
172 -- Bind keyboard digits
173 -- Compute the maximum number of digit we need, limited to 9
174 keynumber = 0
175 for s = 1, screen.count() do
176    keynumber = math.min(9, math.max(#tags[s], keynumber));
177 end
178
179 for i = 1, keynumber do
180     keybinding({ modkey }, i,
181                    function ()
182                        local screen = mouse.screen
183                        if tags[screen][i] then
184                            awful.tag.viewonly(tags[screen][i])
185                        end
186                    end):add()
187     keybinding({ modkey, "Control" }, i,
188                    function ()
189                        local screen = mouse.screen
190                        if tags[screen][i] then
191                            tags[screen][i].selected = not tags[screen][i].selected
192                        end
193                    end):add()
194     keybinding({ modkey, "Shift" }, i,
195                    function ()
196                        local sel = client.focus_get()
197                        if sel then
198                            if tags[sel.screen][i] then
199                                awful.client.movetotag(tags[sel.screen][i])
200                            end
201                        end
202                    end):add()
203     keybinding({ modkey, "Control", "Shift" }, i,
204                    function ()
205                        local sel = client.focus_get()
206                        if sel then
207                            if tags[sel.screen][i] then
208                                awful.client.toggletag(tags[sel.screen][i])
209                            end
210                        end
211                    end):add()
212 end
213
214 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
215 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
216
217 -- Standard program
218 keybinding({ modkey }, "Return", function () awful.spawn(terminal) end):add()
219
220 keybinding({ modkey, "Control" }, "r", awesome.restart):add()
221 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
222
223 -- Client manipulation
224 keybinding({ modkey, "Shift" }, "c", function () client.focus_get():kill() end):add()
225 keybinding({ modkey }, "j", function () awful.client.focus(1); client.focus_get():raise() end):add()
226 keybinding({ modkey }, "k", function () awful.client.focus(-1);  client.focus_get():raise() end):add()
227 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
228 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add()
229 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
230 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
231 keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
232 keybinding({ modkey, "Control" }, "Return", function () client.focus_get():swap(awful.client.master()) end):add()
233 keybinding({ modkey }, "o", awful.client.movetoscreen):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({ prompt = "Run: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.spawn, awful.completion.bash)
248                                  end):add()
249 keybinding({ modkey }, "F4", function ()
250                                      awful.prompt({ prompt = "Run Lua code: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.eval, awful.prompt.bash)
251                                  end):add()
252
253 --- Tabulous, tab manipulation
254 keybinding({ modkey, "Control" }, "y", function ()
255     local tabbedview = tabulous.tabindex_get()
256     local nextclient = awful.client.next(1)
257
258     if tabbedview == nil then
259         tabbedview = tabulous.tabindex_get(nextclient)
260
261         if tabbedview == nil then
262             tabbedview = tabulous.tab_create()
263             tabulous.tab(tabbedview, nextclient)
264         else
265             tabulous.tab(tabbedview, client.focus_get())
266         end
267     else
268         tabulous.tab(tabbedview, nextclient)
269     end
270 end):add()
271
272 keybinding({ modkey, "Shift" }, "y", tabulous.untab):add()
273
274 keybinding({ modkey }, "y", function ()
275    local tabbedview = tabulous.tabindex_get()
276
277    if tabbedview ~= nil then
278        local n = tabulous.next(tabbedview)
279        tabulous.display(tabbedview, n)
280    end
281 end):add()
282
283 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
284 keybinding({ modkey }, "t", awful.client.togglemarked):add()
285 keybinding({ modkey, 'Shift' }, "t", function ()
286     local tabbedview = tabulous.tabindex_get()
287     local clients = awful.client.getmarked()
288
289     if tabbedview == nil then
290         tabbedview = tabulous.tab_create(clients[1])
291         table.remove(clients, 1)
292     end
293
294     for k,c in pairs(clients) do
295         tabulous.tab(tabbedview, c)
296     end
297
298 end):add()
299
300 for i = 1, keynumber do
301     keybinding({ modkey, "Shift" }, "F" .. i,
302                    function ()
303                        local screen = mouse.screen
304                        if tags[screen][i] then
305                            for k, c in pairs(awful.client.getmarked()) do
306                                awful.client.movetotag(tags[screen][i], c)
307                            end
308                        end
309                    end):add()
310 end
311 -- }}}
312
313 -- {{{ Hooks
314 -- Hook function to execute when focusing a client.
315 function hook_focus(c)
316     if not awful.client.ismarked(c) then
317         c.border_color = border_focus
318     end
319 end
320
321 -- Hook function to execute when unfocusing a client.
322 function hook_unfocus(c)
323     if not awful.client.ismarked(c) then
324         c.border_color = border_normal
325     end
326 end
327
328 -- Hook function to execute when marking a client
329 function hook_marked(c)
330     c.border_color = border_marked
331 end
332
333 -- Hook function to execute when unmarking a client
334 function hook_unmarked(c)
335     c.border_color = border_focus
336 end
337
338 -- Hook function to execute when the mouse is over a client.
339 function hook_mouseover(c)
340     -- Sloppy focus, but disabled for magnifier layout
341     if awful.layout.get(c.screen) ~= "magnifier" then
342         c:focus_set()
343     end
344 end
345
346 -- Hook function to execute when a new client appears.
347 function hook_manage(c)
348     -- Add mouse bindings
349     c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
350     c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
351     c:mouse_add(mouse({ modkey }, 3, function (c) c:mouse_resize() end))
352     -- New client may not receive focus
353     -- if they're not focusable, so set border anyway.
354     c.border_width = border_width
355     c.border_color = border_normal
356     c:focus_set()
357     if floatings[c.name:lower()] then
358         c.floating = true
359     end
360     -- Honor size hints
361     c.honorsizehints = true
362 end
363
364 -- Hook function to execute when arranging the screen
365 -- (tag switch, new client, etc)
366 function hook_arrange(screen)
367     local layout = awful.layout.get(screen)
368     mylayoutbox[screen].text = "<bg image=\"" .. AWESOME_DATADIR .. "/icons/layouts/" .. layout .. "w.png\" resize=\"true\"/>"
369
370     -- Uncomment if you want mouse warping
371     --[[
372     local sel = client.focus_get()
373     if sel then
374         local c_c = sel.coords
375         local m_c = mouse.coords
376
377         if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
378             m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
379             if table.maxn(m_c.buttons) == 0 then
380                 mouse.coords = { x = c_c.x + 5, y = c_c.y + 5}
381             end
382         end
383     end
384     ]]
385 end
386
387 -- Hook called every second
388 function hook_timer ()
389     -- For unix time_t lovers
390     -- mytextbox.text = " " .. os.time() .. " time_t "
391     -- Otherwise use:
392     mytextbox.text = " " .. os.date() .. " "
393 end
394
395 -- Set up some hooks
396 awful.hooks.focus(hook_focus)
397 awful.hooks.unfocus(hook_unfocus)
398 awful.hooks.marked(hook_marked)
399 awful.hooks.unmarked(hook_unmarked)
400 awful.hooks.manage(hook_manage)
401 awful.hooks.mouseover(hook_mouseover)
402 awful.hooks.arrange(hook_arrange)
403 awful.hooks.timer(1, hook_timer)
404 -- }}}
405
406 cmdmodkey = "Mod3"
407
408 -- xmms2 & sound
409 keybinding({ cmdmodkey }, "Prior", function () awful.spawn("amixer set Master 2+") end):add()
410 keybinding({ cmdmodkey }, "Next", function () awful.spawn("amixer set Master 2-") end):add()
411 keybinding({ cmdmodkey }, "Up", function () awful.spawn("amixer set PCM 2+") end):add()
412 keybinding({ cmdmodkey }, "Down", function () awful.spawn("amixer set PCM 2-") end):add()
413 keybinding({ cmdmodkey }, "Home", function () awful.spawn("amixer set Mic toggle") end):add()
414 keybinding({ cmdmodkey }, "End", function () awful.spawn("amixer set Master toggle") end):add()
415 keybinding({ cmdmodkey }, "Left", function () awful.spawn("xmms2 prev") end):add()
416 keybinding({ cmdmodkey }, "Right", function () awful.spawn("xmms2 next") end):add()
417 keybinding({ cmdmodkey }, "space", function () awful.spawn("xmms2 toggleplay") end):add()
418 keybinding({ cmdmodkey }, "backslash", function () awful.spawn("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end):add()
419 keybinding({ cmdmodkey, "Shift" }, "backslash", function () awful.spawn("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end):add()
420
421 -- misc apps
422 keybinding({ cmdmodkey }, "n", function () awful.spawn("sensible-browser") end):add()
423 keybinding({ cmdmodkey }, "m", function () awful.spawn(terminal .. " -e mutt -f =store") end):add()
424 keybinding({ cmdmodkey }, "t", function () awful.spawn(terminal) end):add()
425 keybinding({ cmdmodkey }, "c", function () awful.spawn(terminal .. " -e python") end):add()
426 keybinding({ cmdmodkey }, "r", function () awful.spawn("gmrun") end):add()
427 keybinding({ cmdmodkey }, "j", function () awful.spawn("jpilot") end):add()
428 keybinding({ cmdmodkey }, "x", function () awful.spawn("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end):add()
429 keybinding({ cmdmodkey, "Shift" }, "x", function () awful.spawn("xscreensaver-command -exit") end):add()