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

changes with 3.4
[etc/awesome.git] / .config / awesome / rc.lua
1 -- Standard awesome library
2 require("awful")
3 require("awful.autofocus")
4 require("awful.rules")
5 -- Theme handling library
6 require("beautiful")
7 -- Notification library
8 require("naughty")
9
10 -- Load Debian menu entries
11 require("debian.menu")
12
13 -- {{{ Variable definitions
14 -- Themes define colours, icons, and wallpapers
15 -- The default is a dark theme
16 theme_path = "/usr/share/awesome/themes/default/theme.lua"
17 -- Uncommment this for a lighter theme
18 -- theme_path = "/usr/share/awesome/themes/sky/theme.lua"
19
20 -- Actually load theme
21 beautiful.init(theme_path)
22
23 -- This is used later as the default terminal and editor to run.
24 terminal = "x-terminal-emulator"
25 editor = os.getenv("EDITOR") or "editor"
26 editor_cmd = terminal .. " -e " .. editor
27
28 -- Default modkey.
29 -- Usually, Mod4 is the key with a logo between Control and Alt.
30 -- If you do not like this or do not have such a key,
31 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
32 -- However, you can use another modifier like Mod1, but it may interact with others.
33 modkey = "Mod4"
34
35 -- Table of layouts to cover with awful.layout.inc, order matters.
36 layouts =
37 {
38     awful.layout.suit.tile,
39     awful.layout.suit.tile.left,
40     awful.layout.suit.tile.bottom,
41     awful.layout.suit.tile.top,
42     awful.layout.suit.fair,
43     awful.layout.suit.fair.horizontal,
44     awful.layout.suit.spiral,
45     awful.layout.suit.spiral.dwindle,
46     awful.layout.suit.max,
47     awful.layout.suit.max.fullscreen,
48     awful.layout.suit.magnifier,
49     awful.layout.suit.floating
50 }
51
52 -- Table of clients that should be set floating. The index may be either
53 -- the application class or instance. The instance is useful when running
54 -- a console app in a terminal like (Music on Console)
55 --    xterm -name mocp -e mocp
56 -- OVERRULED BY TILEDAPPS BELOW
57 floatapps =
58 {
59     -- by class
60     ["MPlayer"] = true,
61     ["pinentry"] = true,
62     ["GIMP"] = true,
63     ["twinkle"] = true,
64     ["Add-ons"] = true,
65     ["Play stream"] = true,
66     ["gscan2pdf"] = true,
67 }
68
69 -- Applications that should never float, assuming everything else floats
70 -- (by instance)
71 tiledapps =
72 {
73     ["urxvt"] = true,
74 }
75
76 -- Applications that should be maximised
77 -- (by instance)
78 maxapps =
79 {
80     ["Navigator"] = true,
81     -- jpilot is -v
82     ["-v"] = true,
83     ["Xpdf"] = true,
84     ["gscan2pdf"] = true
85 }
86
87 -- Applications to be moved to a pre-defined tag by class or instance.
88 -- Use the screen and tags indices.
89 apptags =
90 {
91     ["Navigator"] = { screen = 1, tag = 9 },
92     -- jpilot is -v
93     ["-v"] = { screen = 1, tag = 8 },
94 }
95
96 -- Define if we want to use titlebar on all applications.
97 use_titlebar = false
98 -- }}}
99
100 -- {{{ Tags
101 -- Define a tag table which hold all screen tags.
102 tags = {}
103 for s = 1, screen.count() do
104     -- Each screen has its own tag table.
105     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s)
106 end
107 -- }}}
108
109 -- {{{ Menu
110 -- Create a laucher widget and a main menu
111 myawesomemenu = {
112    { "manual", terminal .. " -e man awesome" },
113    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
114    { "restart", awesome.restart },
115    { "quit", awesome.quit }
116 }
117
118 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
119                                     { "Debian", debian.menu.Debian_menu.Debian },
120                                     { "open terminal", terminal }
121                                   }
122                         })
123
124 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
125                                      menu = mymainmenu })
126 -- }}}
127
128 -- {{{ Wibox
129 -- Create a textclock widget
130 mytextclock = awful.widget.textclock({ align = "right" })
131
132 -- Create a systray
133 mysystray = widget({ type = "systray" })
134
135 -- Create a wibox for each screen and add it
136 mywibox = {}
137 mypromptbox = {}
138 mylayoutbox = {}
139 mytaglist = {}
140 mytaglist.buttons = awful.util.table.join(
141                     awful.button({ }, 1, awful.tag.viewonly),
142                     awful.button({ modkey }, 1, awful.client.movetotag),
143                     awful.button({ }, 3, awful.tag.viewtoggle),
144                     awful.button({ modkey }, 3, awful.client.toggletag),
145                     awful.button({ }, 4, awful.tag.viewnext),
146                     awful.button({ }, 5, awful.tag.viewprev)
147                     )
148 mytasklist = {}
149 mytasklist.buttons = awful.util.table.join(
150                      awful.button({ }, 1, function (c)
151                                               if not c:isvisible() then
152                                                   awful.tag.viewonly(c:tags()[1])
153                                               end
154                                               client.focus = c
155                                               c:raise()
156                                           end),
157                      awful.button({ }, 3, function ()
158                                               if instance then
159                                                   instance:hide()
160                                                   instance = nil
161                                               else
162                                                   instance = awful.menu.clients({ width=250 })
163                                               end
164                                           end),
165                      awful.button({ }, 4, function ()
166                                               awful.client.focus.byidx(1)
167                                               if client.focus then client.focus:raise() end
168                                           end),
169                      awful.button({ }, 5, function ()
170                                               awful.client.focus.byidx(-1)
171                                               if client.focus then client.focus:raise() end
172                                           end))
173
174 for s = 1, screen.count() do
175     -- Create a promptbox for each screen
176     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
177     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
178     -- We need one layoutbox per screen.
179     mylayoutbox[s] = awful.widget.layoutbox(s)
180     mylayoutbox[s]:buttons(awful.util.table.join(
181                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
182                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
183                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
184                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
185     -- Create a taglist widget
186     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
187
188     -- Create a tasklist widget
189     mytasklist[s] = awful.widget.tasklist(function(c)
190                                               return awful.widget.tasklist.label.currenttags(c, s)
191                                           end, mytasklist.buttons)
192
193     -- Create the wibox
194     mywibox[s] = awful.wibox({ position = "top", screen = s })
195     -- Add widgets to the wibox - order matters
196     mywibox[s].widgets = {
197         {
198 --            mylauncher,
199             mytaglist[s],
200             mypromptbox[s],
201             layout = awful.widget.layout.horizontal.leftright
202         },
203         mylayoutbox[s],
204         mytextclock,
205         s == 1 and mysystray or nil,
206         mytasklist[s],
207         layout = awful.widget.layout.horizontal.rightleft
208     }
209 end
210 -- }}}
211
212 --Battery widget
213 batterywidget = widget({ type = 'progressbar', name = 'batterywidget' })
214 batterywidget.width = 100
215 batterywidget.height = 0.8
216 batterywidget.gap = 1
217 batterywidget.border_padding = 1
218 batterywidget.border_width = 1
219 batterywidget.ticks_count = 10
220 batterywidget.ticks_gap = 1
221 batterywidget.vertical = false
222 batterywidget:bar_properties_set('bat', {
223   bg = 'black',
224   fg = 'blue4',
225   fg_off = 'red',
226   reverse = false,
227   min_value = 0,
228   max_value = 100
229 })
230 -- }}}
231
232
233 -- {{{ Mouse bindings
234 root.buttons(awful.util.table.join(
235     awful.button({ }, 3, function () mymainmenu:toggle() end),
236     awful.button({ }, 4, awful.tag.viewnext),
237     awful.button({ }, 5, awful.tag.viewprev)
238 ))
239 -- }}}
240
241 -- {{{ Key bindings
242 globalkeys = awful.util.table.join(
243     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
244     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
245     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
246     awful.key({ modkey, "Shift"   }, "Right", function () awful.screen.focus( 1)       end),
247     awful.key({ modkey, "Shift"   }, "Left", function () awful.screen.focus(-1)       end),
248     awful.key({ modkey, "Shift"   }, "h",   awful.tag.viewprev       ),
249     awful.key({ modkey, "Shift"   }, "l",  awful.tag.viewnext       ),
250
251     awful.key({ modkey,           }, "k",
252         function ()
253             awful.client.focus.byidx( 1)
254             if client.focus then client.focus:raise() end
255         end),
256     awful.key({ modkey,           }, "j",
257         function ()
258             awful.client.focus.byidx(-1)
259             if client.focus then client.focus:raise() end
260         end),
261     awful.key({ modkey,           }, "w", function () mymainmenu:show(true)        end),
262
263     -- Layout manipulation
264     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx(  1) end),
265     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx( -1) end),
266     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus( 1)       end),
267     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus(-1)       end),
268     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
269     awful.key({ modkey,           }, "Tab",
270         function ()
271             awful.client.focus.history.previous()
272             if client.focus then
273                 client.focus:raise()
274             end
275         end),
276
277     -- Standard program
278     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
279     awful.key({ modkey, "Control" }, "r", awesome.restart),
280     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
281
282     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
283     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
284     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
285     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
286     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
287     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
288     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
289     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
290
291     -- Prompt
292     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
293
294     awful.key({ modkey }, "x",
295               function ()
296                   awful.prompt.run({ prompt = "Run Lua code: " },
297                   mypromptbox[mouse.screen].widget,
298                   awful.util.eval, nil,
299                   awful.util.getdir("cache") .. "/history_eval")
300               end)
301 )
302
303 clientkeys = awful.util.table.join(
304     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
305     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
306     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
307     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
308     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
309     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
310     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
311     awful.key({ modkey,           }, "m",
312         function (c)
313             c.maximized_horizontal = not c.maximized_horizontal
314             c.maximized_vertical   = not c.maximized_vertical
315         end)
316 )
317
318 -- Compute the maximum number of digit we need, limited to 9
319 keynumber = 0
320 for s = 1, screen.count() do
321    keynumber = math.min(9, math.max(#tags[s], keynumber));
322 end
323
324 -- Bind all key numbers to tags.
325 -- Be careful: we use keycodes to make it works on any keyboard layout.
326 -- This should map on the top row of your keyboard, usually 1 to 9.
327 for i = 1, keynumber do
328     globalkeys = awful.util.table.join(globalkeys,
329         awful.key({ modkey }, "#" .. i + 9,
330                   function ()
331                         local screen = mouse.screen
332                         if tags[screen][i] then
333                             awful.tag.viewonly(tags[screen][i])
334                         end
335                   end),
336         awful.key({ modkey, "Control" }, "#" .. i + 9,
337                   function ()
338                       local screen = mouse.screen
339                       if tags[screen][i] then
340                           awful.tag.viewtoggle(tags[screen][i])
341                       end
342                   end),
343         awful.key({ modkey, "Shift" }, "#" .. i + 9,
344                   function ()
345                       if client.focus and tags[client.focus.screen][i] then
346                           awful.client.movetotag(tags[client.focus.screen][i])
347                       end
348                   end),
349         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
350                   function ()
351                       if client.focus and tags[client.focus.screen][i] then
352                           awful.client.toggletag(tags[client.focus.screen][i])
353                       end
354                   end))
355 end
356
357 clientbuttons = awful.util.table.join(
358     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
359     awful.button({ modkey }, 1, awful.mouse.client.move),
360     awful.button({ modkey }, 3, awful.mouse.client.resize))
361
362 cmdmodkey = "Mod3"
363
364 -- xmms2 & sound
365 globalkeys = awful.util.table.join(globalkeys,
366   awful.key({ cmdmodkey }, "Prior", function () awful.util.spawn("amixer set Master 2+") end),
367   awful.key({ cmdmodkey }, "Next", function () awful.util.spawn("amixer set Master 2-") end),
368   awful.key({ cmdmodkey }, "Up", function () awful.util.spawn("amixer set PCM 2+") end),
369   awful.key({ cmdmodkey }, "Down", function () awful.util.spawn("amixer set PCM 2-") end),
370   awful.key({ cmdmodkey }, "Home", function () awful.util.spawn("amixer set Mic toggle") end),
371   awful.key({ cmdmodkey }, "End", function () awful.util.spawn("amixer set Master toggle") end),
372   awful.key({ cmdmodkey }, "Left", function () awful.util.spawn("xmms2 prev") end),
373   awful.key({ cmdmodkey }, "Right", function () awful.util.spawn("xmms2 next") end),
374   awful.key({ cmdmodkey }, "space", function () awful.util.spawn("xmms2 toggleplay") end),
375   awful.key({ cmdmodkey }, "backslash", function () awful.util.spawn_with_shell("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end),
376   awful.key({ cmdmodkey, "Shift" }, "backslash", function () awful.util.spawn_with_shell("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end)
377 )
378
379 -- misc apps
380 globalkeys = awful.util.table.join(globalkeys,
381   awful.key({ cmdmodkey }, "n", function () awful.util.spawn("sensible-browser") end),
382   awful.key({ cmdmodkey }, "m", function () awful.util.spawn(terminal .. " -e mutt -f =store") end),
383   awful.key({ cmdmodkey }, "t", function () awful.util.spawn(terminal) end),
384   awful.key({ cmdmodkey }, "c", function () awful.util.spawn(terminal .. " -e python") end),
385 --  awful.key({ cmdmodkey }, "r", function () awful.util.spawn("gmrun") end),
386   awful.key({ cmdmodkey }, "r", function () mypromptbox[mouse.screen]:run() end),
387   awful.key({ cmdmodkey }, "j", function () awful.util.spawn("jpilot") end),
388   awful.key({ cmdmodkey }, "x", function () awful.util.spawn_with_shell("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end),
389   awful.key({ cmdmodkey, "Shift" }, "x", function () awful.util.spawn("xscreensaver-command -exit") end),
390   awful.key(nil, "XF86ScreenSaver", function () awful.util.spawn("xset dpms force off") end)
391 )
392
393 -- Set keys
394 root.keys(globalkeys)
395 -- }}}
396
397 -- {{{ Rules
398 awful.rules.rules = {
399     -- All clients will match this rule.
400     { rule = { },
401       properties = { border_width = beautiful.border_width,
402                      border_color = beautiful.border_normal,
403                      focus = true,
404                      keys = clientkeys,
405                      buttons = clientbuttons } },
406     { rule = { class = "MPlayer" },
407       properties = { floating = true } },
408     { rule = { class = "pinentry" },
409       properties = { floating = true } },
410     { rule = { class = "gimp" },
411       properties = { floating = true } },
412     -- Set Firefox to always map on tags number 2 of screen 1.
413     -- { rule = { class = "Firefox" },
414     --   properties = { tag = tags[1][2] } },
415 }
416 -- }}}
417
418 -- {{{ Signals
419 -- Signal function to execute when a new client appears.
420 client.add_signal("manage", function (c, startup)
421     -- Add a titlebar
422     -- awful.titlebar.add(c, { modkey = modkey })
423
424     -- Enable sloppy focus
425     c:add_signal("mouse::enter", function(c)
426         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
427             and awful.client.focus.filter(c) then
428             client.focus = c
429         end
430     end)
431
432     if not startup then
433         -- Set the windows at the slave,
434         -- i.e. put it at the end of others instead of setting it master.
435         -- awful.client.setslave(c)
436
437         -- Put windows in a smart way, only if they does not set an initial position.
438         if not c.size_hints.user_position and not c.size_hints.program_position then
439             awful.placement.no_overlap(c)
440             awful.placement.no_offscreen(c)
441         end
442     end
443 end)
444
445 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
446 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
447 -- }}}
448
449 --{{{ batt hook
450 local function get_bat()
451   local a = io.open("/sys/class/power_supply/BAT1/charge_full")
452   for line in a:lines() do
453     full = line
454   end
455   a:close()
456   local b = io.open("/sys/class/power_supply/BAT1/charge_now")
457   for line in b:lines() do
458     now = line
459   end
460   b:close()
461   batt=math.floor(now*100/full)
462   batterywidget:bar_data_add("bat",batt )
463 end
464 --}}}
465
466 -- Set up some hooks
467 awful.hooks.timer.register(20, hook_battery)
468 -- awful.hooks.timer.register(5, get_bat)
469 -- }}}
470
471 -- Highlight statusbars on the screen that has focus,
472 -- set this to false if you only have one screen or
473 -- you don't like it :P
474 if screen.count() > 1 then
475   statusbar_highlight_focus = true
476 else
477   statusbar_highlight_focus = false
478 end
479
480 hook_battery()