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

change to my own theme
[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/madduck"
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) c:focus_set(); 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     {
149         mytaglist,
150         mytasklist,
151         mypromptbox,
152         mytextbox,
153         mylayoutbox[s],
154         s == screen.count() and mysystray or nil
155     }
156     mystatusbar[s].screen = s
157 end
158 -- }}}
159
160 -- {{{ Mouse bindings
161 awesome.mouse_add(mouse({ }, 3, function () awful.spawn(terminal) end))
162 awesome.mouse_add(mouse({ }, 4, awful.tag.viewnext))
163 awesome.mouse_add(mouse({ }, 5, awful.tag.viewprev))
164 -- }}}
165
166 -- {{{ Key bindings
167
168 -- Bind keyboard digits
169 -- Compute the maximum number of digit we need, limited to 9
170 keynumber = 0
171 for s = 1, screen.count() do
172    keynumber = math.min(9, math.max(#tags[s], keynumber));
173 end
174
175 for i = 1, keynumber do
176     keybinding({ modkey }, i,
177                    function ()
178                        local screen = mouse.screen
179                        if tags[screen][i] then
180                            awful.tag.viewonly(tags[screen][i])
181                        end
182                    end):add()
183     keybinding({ modkey, "Control" }, i,
184                    function ()
185                        local screen = mouse.screen
186                        if tags[screen][i] then
187                            tags[screen][i].selected = not tags[screen][i].selected
188                        end
189                    end):add()
190     keybinding({ modkey, "Shift" }, i,
191                    function ()
192                        local sel = client.focus_get()
193                        if sel then
194                            if tags[sel.screen][i] then
195                                awful.client.movetotag(tags[sel.screen][i])
196                            end
197                        end
198                    end):add()
199     keybinding({ modkey, "Control", "Shift" }, i,
200                    function ()
201                        local sel = client.focus_get()
202                        if sel then
203                            if tags[sel.screen][i] then
204                                awful.client.toggletag(tags[sel.screen][i])
205                            end
206                        end
207                    end):add()
208 end
209
210 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
211 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
212 keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
213
214 -- Standard program
215 keybinding({ modkey }, "Return", function () awful.spawn(terminal) end):add()
216
217 keybinding({ modkey, "Control" }, "r", awesome.restart):add()
218 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
219
220 -- Client manipulation
221 keybinding({ modkey }, "m", awful.client.maximize):add()
222 keybinding({ modkey, "Shift" }, "c", function () client.focus_get():kill() end):add()
223 keybinding({ modkey }, "j", function () awful.client.focusbyidx(1); client.focus_get():raise() end):add()
224 keybinding({ modkey }, "k", function () awful.client.focusbyidx(-1);  client.focus_get():raise() end):add()
225 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
226 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add()
227 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
228 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
229 keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
230 keybinding({ modkey, "Control" }, "Return", function () client.focus_get():swap(awful.client.master()) end):add()
231 keybinding({ modkey }, "o", awful.client.movetoscreen):add()
232 keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
233
234 -- Layout manipulation
235 keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
236 keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
237 keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
238 keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
239 keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
240 keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
241 keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
242 keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
243
244 -- Prompt
245 keybinding({ modkey }, "F1", function ()
246                                      awful.prompt({ prompt = "Run: " }, mypromptbox, awful.spawn, awful.completion.bash)
247                                  end):add()
248 keybinding({ modkey }, "F4", function ()
249                                      awful.prompt({ prompt = "Run Lua code: " }, mypromptbox, awful.eval)
250                                  end):add()
251
252 --- Tabulous, tab manipulation
253 keybinding({ modkey, "Control" }, "y", function ()
254     local tabbedview = tabulous.tabindex_get()
255     local nextclient = awful.client.next(1)
256
257     if not tabbedview then
258         tabbedview = tabulous.tabindex_get(nextclient)
259
260         if not tabbedview then
261             tabbedview = tabulous.tab_create()
262             tabulous.tab(tabbedview, nextclient)
263         else
264             tabulous.tab(tabbedview, client.focus_get())
265         end
266     else
267         tabulous.tab(tabbedview, nextclient)
268     end
269 end):add()
270
271 keybinding({ modkey, "Shift" }, "y", tabulous.untab):add()
272
273 keybinding({ modkey }, "y", function ()
274    local tabbedview = tabulous.tabindex_get()
275
276    if tabbedview then
277        local n = tabulous.next(tabbedview)
278        tabulous.display(tabbedview, n)
279    end
280 end):add()
281
282 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
283 keybinding({ modkey }, "t", awful.client.togglemarked):add()
284 keybinding({ modkey, 'Shift' }, "t", function ()
285     local tabbedview = tabulous.tabindex_get()
286     local clients = awful.client.getmarked()
287
288     if not tabbedview then
289         tabbedview = tabulous.tab_create(clients[1])
290         table.remove(clients, 1)
291     end
292
293     for k,c in pairs(clients) do
294         tabulous.tab(tabbedview, c)
295     end
296
297 end):add()
298
299 for i = 1, keynumber do
300     keybinding({ modkey, "Shift" }, "F" .. i,
301                    function ()
302                        local screen = mouse.screen
303                        if tags[screen][i] then
304                            for k, c in pairs(awful.client.getmarked()) do
305                                awful.client.movetotag(tags[screen][i], c)
306                            end
307                        end
308                    end):add()
309 end
310 -- }}}
311
312 -- {{{ Hooks
313 -- Hook function to execute when focusing a client.
314 function hook_focus(c)
315     if not awful.client.ismarked(c) then
316         c.border_color = beautiful.border_focus
317     end
318 end
319
320 -- Hook function to execute when unfocusing a client.
321 function hook_unfocus(c)
322     if not awful.client.ismarked(c) then
323         c.border_color = beautiful.border_normal
324     end
325 end
326
327 -- Hook function to execute when marking a client
328 function hook_marked(c)
329     c.border_color = beautiful.border_marked
330 end
331
332 -- Hook function to execute when unmarking a client
333 function hook_unmarked(c)
334     c.border_color = beautiful.border_focus
335 end
336
337 -- Hook function to execute when the mouse is over a client.
338 function hook_mouseover(c)
339     -- Sloppy focus, but disabled for magnifier layout
340     if awful.layout.get(c.screen) ~= "magnifier" then
341         c:focus_set()
342     end
343 end
344
345 -- Hook function to execute when a new client appears.
346 function hook_manage(c)
347     -- Set floating placement to be smart!
348     c.floating_placement = "smart"
349     if use_titlebar then
350         -- Add a titlebar
351         awful.titlebar.add(c, { modkey = modkey })
352     end
353     -- Add mouse bindings
354     c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
355     c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
356     c:mouse_add(mouse({ modkey }, 3, function (c) c:mouse_resize() end))
357     -- New client may not receive focus
358     -- if they're not focusable, so set border anyway.
359     c.border_width = beautiful.border_width
360     c.border_color = beautiful.border_normal
361     c:focus_set()
362
363     -- Check if the application should be floating.
364     local cls = c.class
365     local inst = c.instance
366     if floatapps[cls] then
367         c.floating = floatapps[cls]
368     elseif floatapps[inst] then
369         c.floating = floatapps[inst]
370     end
371
372     -- Check application->screen/tag mappings.
373     local target
374     if apptags[cls] then
375         target = apptags[cls]
376     elseif apptags[inst] then
377         target = apptags[inst]
378     end
379     if target then
380         c.screen = target.screen
381         awful.client.movetotag(tags[target.screen][target.tag], c)
382     end
383
384     -- Honor size hints
385     c.honorsizehints = true
386 end
387
388 -- Hook function to execute when arranging the screen
389 -- (tag switch, new client, etc)
390 function hook_arrange(screen)
391     mylayoutbox[screen].text =
392         "<bg image=\"" .. AWESOME_DATADIR .. "/icons/layouts/" .. awful.layout.get(screen) .. "w.png\" resize=\"true\"/>"
393
394     -- If no window has focus, give focus to the latest in history
395     if not client.focus_get() then
396         local c = awful.client.focus.history.get(screen, 0)
397         if c then c:focus_set() end
398     end
399
400     -- Uncomment if you want mouse warping
401     --[[
402     local sel = client.focus_get()
403     if sel then
404         local c_c = sel.coords
405         local m_c = mouse.coords
406
407         if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
408             m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
409             if table.maxn(m_c.buttons) == 0 then
410                 mouse.coords = { x = c_c.x + 5, y = c_c.y + 5}
411             end
412         end
413     end
414     ]]
415 end
416
417 -- Hook called every second
418 function hook_timer ()
419     -- For unix time_t lovers
420     -- mytextbox.text = " " .. os.time() .. " time_t "
421     -- Otherwise use:
422     mytextbox.text = " " .. os.date() .. " "
423 end
424
425 -- Set up some hooks
426 awful.hooks.focus.register(hook_focus)
427 awful.hooks.unfocus.register(hook_unfocus)
428 awful.hooks.marked.register(hook_marked)
429 awful.hooks.unmarked.register(hook_unmarked)
430 awful.hooks.manage.register(hook_manage)
431 awful.hooks.mouseover.register(hook_mouseover)
432 awful.hooks.arrange.register(hook_arrange)
433 awful.hooks.timer.register(1, hook_timer)
434 -- }}}
435
436 cmdmodkey = "Mod3"
437
438 -- xmms2 & sound
439 keybinding({ cmdmodkey }, "Prior", function () awful.spawn("amixer set Master 2+") end):add()
440 keybinding({ cmdmodkey }, "Next", function () awful.spawn("amixer set Master 2-") end):add()
441 keybinding({ cmdmodkey }, "Up", function () awful.spawn("amixer set PCM 2+") end):add()
442 keybinding({ cmdmodkey }, "Down", function () awful.spawn("amixer set PCM 2-") end):add()
443 keybinding({ cmdmodkey }, "Home", function () awful.spawn("amixer set Mic toggle") end):add()
444 keybinding({ cmdmodkey }, "End", function () awful.spawn("amixer set Master toggle") end):add()
445 keybinding({ cmdmodkey }, "Left", function () awful.spawn("xmms2 prev") end):add()
446 keybinding({ cmdmodkey }, "Right", function () awful.spawn("xmms2 next") end):add()
447 keybinding({ cmdmodkey }, "space", function () awful.spawn("xmms2 toggleplay") end):add()
448 keybinding({ cmdmodkey }, "backslash", function () awful.spawn("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end):add()
449 keybinding({ cmdmodkey, "Shift" }, "backslash", function () awful.spawn("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end):add()
450
451 -- misc apps
452 keybinding({ cmdmodkey }, "n", function () awful.spawn("sensible-browser") end):add()
453 keybinding({ cmdmodkey }, "m", function () awful.spawn(terminal .. " -e mutt -f =store") end):add()
454 keybinding({ cmdmodkey }, "t", function () awful.spawn(terminal) end):add()
455 keybinding({ cmdmodkey }, "c", function () awful.spawn(terminal .. " -e python") end):add()
456 keybinding({ cmdmodkey }, "r", function () awful.spawn("gmrun") end):add()
457 keybinding({ cmdmodkey }, "j", function () awful.spawn("jpilot") end):add()
458 keybinding({ cmdmodkey }, "x", function () awful.spawn("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end):add()
459 keybinding({ cmdmodkey, "Shift" }, "x", function () awful.spawn("xscreensaver-command -exit") end):add()