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

ef3c331b78ddcb8a34d349fe9afb495fd187be41
[etc/awesome.git] / .config / awesome / rc.lua
1 -- Standard awesome library
2 require("awful")
3 require("beautiful")
4 require("naughty")
5
6 -- Load Debian menu entries
7 require("debian.menu")
8
9 -- {{{ Variable definitions
10 -- Themes define colours, icons, and wallpapers
11 -- The default is a dark theme
12 theme_path = "/usr/share/awesome/themes/default/theme.lua"
13 -- Uncommment this for a lighter theme
14 -- theme_path = "/usr/share/awesome/themes/sky/theme.lua"
15
16 -- Actually load theme
17 beautiful.init(theme_path)
18
19 -- This is used later as the default terminal and editor to run.
20 terminal = "x-terminal-emulator"
21 editor = os.getenv("EDITOR") or "editor"
22 editor_cmd = terminal .. " -e " .. editor
23
24 -- Default modkey.
25 -- Usually, Mod4 is the key with a logo between Control and Alt.
26 -- If you do not like this or do not have such a key,
27 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
28 -- However, you can use another modifier like Mod1, but it may interact with others.
29 modkey = "Mod4"
30
31 -- Table of layouts to cover with awful.layout.inc, order matters.
32 layouts =
33 {
34     awful.layout.suit.tile,
35     awful.layout.suit.tile.left,
36     awful.layout.suit.tile.bottom,
37     awful.layout.suit.tile.top,
38     awful.layout.suit.fair,
39     awful.layout.suit.fair.horizontal,
40     awful.layout.suit.max,
41     awful.layout.suit.max.fullscreen,
42     awful.layout.suit.magnifier,
43     awful.layout.suit.floating
44 }
45
46 -- Table of clients that should be set floating. The index may be either
47 -- the application class or instance. The instance is useful when running
48 -- a console app in a terminal like (Music on Console)
49 --    xterm -name mocp -e mocp
50 -- OVERRULED BY TILEDAPPS BELOW
51 floatapps =
52 {
53     -- by class
54     ["MPlayer"] = true,
55     ["pinentry"] = true,
56     ["GIMP"] = true,
57     ["twinkle"] = true,
58     ["Add-ons"] = true,
59     ["Play stream"] = true,
60     ["gscan2pdf"] = true,
61 }
62
63 -- Applications that should never float, assuming everything else floats
64 -- (by instance)
65 tiledapps =
66 {
67     ["urxvt"] = true,
68 }
69
70 -- Applications that should be maximised
71 -- (by instance)
72 maxapps =
73 {
74     ["Navigator"] = true,
75     -- jpilot is -v
76     ["-v"] = true,
77     ["Xpdf"] = true,
78     ["gscan2pdf"] = true
79 }
80
81 -- Applications to be moved to a pre-defined tag by class or instance.
82 -- Use the screen and tags indices.
83 apptags =
84 {
85     ["Navigator"] = { screen = 1, tag = 9 },
86     -- jpilot is -v
87     ["-v"] = { screen = 1, tag = 8 },
88 }
89
90 -- Define if we want to use titlebar on all applications.
91 use_titlebar = false
92 -- }}}
93
94 -- {{{ Tags
95 -- Define tags table.
96 tags = {}
97 for s = 1, screen.count() do
98     -- Each screen has its own tag table.
99     tags[s] = {}
100     -- Create 9 tags per screen.
101     for tagnumber = 1, 9 do
102         tags[s][tagnumber] = tag(tagnumber)
103         -- split at 0.5/50% exactly
104         tags[s][tagnumber].mwfact = 0.5
105         -- Add tags to screen one by one
106         tags[s][tagnumber].screen = s
107         awful.layout.set(layouts[5], tags[s][tagnumber])
108     end
109     -- I'm sure you want to see at least one tag.
110     tags[s][1].selected = true
111 end
112 -- }}}
113
114 -- {{{ Wibox
115 -- Create a textbox widget
116 mytextbox = widget({ type = "textbox", align = "right" })
117 -- Set the default text in textbox
118 mytextbox.text = "<b><small> " .. awesome.release .. " </small></b>"
119
120 -- Create a laucher widget and a main menu
121 myawesomemenu = {
122    { "manual", terminal .. " -e man awesome" },
123    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
124    { "restart", awesome.restart },
125    { "quit", awesome.quit }
126 }
127
128 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
129                                         { "open terminal", terminal },
130                                         { "Debian", debian.menu.Debian_menu.Debian }
131                                       }
132                             })
133
134 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
135                                      menu = mymainmenu })
136
137 -- Create a systray
138 mysystray = widget({ type = "systray", align = "right" })
139
140 -- Create textbox widgets
141 mytimebox = widget({ type = "textbox", name = "mytimebox", align = "right" })
142 mybatterybox = widget({ type = "textbox", name = "mybatterybox", align = "right" })
143
144 -- Create a wibox for each screen and add it
145 mywibox = {}
146 mypromptbox = {}
147 mylayoutbox = {}
148 mytaglist = {}
149 mytaglist.buttons = awful.util.table.join(
150                     awful.button({ }, 1, awful.tag.viewonly),
151                     awful.button({ modkey }, 1, awful.client.movetotag),
152                     awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
153                     awful.button({ modkey }, 3, awful.client.toggletag),
154                     awful.button({ }, 4, awful.tag.viewnext),
155                     awful.button({ }, 5, awful.tag.viewprev)
156                     )
157 mytasklist = {}
158 mytasklist.buttons = awful.util.table.join(
159                      awful.button({ }, 1, function (c)
160                                               if not c:isvisible() then
161                                                   awful.tag.viewonly(c:tags()[1])
162                                               end
163                                               client.focus = c
164                                               c:raise()
165                                           end),
166                      awful.button({ }, 3, function ()
167                                               if instance then
168                                                   instance:hide()
169                                                   instance = nil
170                                               else
171                                                   instance = awful.menu.clients({ width=250 })
172                                               end
173                                           end),
174                      awful.button({ }, 4, function ()
175                                               awful.client.focus.byidx(1)
176                                               if client.focus then client.focus:raise() end
177                                           end),
178                      awful.button({ }, 5, function ()
179                                               awful.client.focus.byidx(-1)
180                                               if client.focus then client.focus:raise() end
181                                           end))
182
183 for s = 1, screen.count() do
184     -- Create a promptbox for each screen
185     mypromptbox[s] = awful.widget.prompt({ align = "left" })
186     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
187     -- We need one layoutbox per screen.
188     mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
189     mylayoutbox[s]:buttons(awful.util.table.join(
190                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
191                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
192                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
193                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
194     -- Create a taglist widget
195     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
196
197     -- Create a tasklist widget
198     mytasklist[s] = awful.widget.tasklist(function(c)
199                                               return awful.widget.tasklist.label.currenttags(c, s)
200                                           end, mytasklist.buttons)
201
202     -- Create the wibox
203     mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
204     -- Add widgets to the wibox - order matters
205     mywibox[s].widgets = { mytaglist[s],
206                            mytasklist[s],
207                            mypromptbox[s],
208                            mybatterybox,
209                            mytimebox,
210                            mylayoutbox[s],
211                            s == screen.count() and mysystray or nil }
212     mywibox[s].screen = s
213 end
214 -- }}}
215
216 --Battery widget
217 batterywidget = widget({ type = 'progressbar', name = 'batterywidget' })
218 batterywidget.width = 100
219 batterywidget.height = 0.8
220 batterywidget.gap = 1
221 batterywidget.border_padding = 1
222 batterywidget.border_width = 1
223 batterywidget.ticks_count = 10
224 batterywidget.ticks_gap = 1
225 batterywidget.vertical = false
226 batterywidget:bar_properties_set('bat', {
227   bg = 'black',
228   fg = 'blue4',
229   fg_off = 'red',
230   reverse = false,
231   min_value = 0,
232   max_value = 100
233 })
234 -- }}}
235
236
237 -- {{{ Mouse bindings
238 root.buttons(awful.util.table.join(
239     awful.button({ }, 3, function () mymainmenu:toggle() end),
240     awful.button({ }, 4, awful.tag.viewnext),
241     awful.button({ }, 5, awful.tag.viewprev)
242 ))
243 -- }}}
244
245 -- {{{ Key bindings
246 globalkeys = awful.util.table.join(
247     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
248     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
249     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
250     awful.key({ modkey, "Shift"   }, "Right", function () awful.screen.focus( 1)       end),
251     awful.key({ modkey, "Shift"   }, "Left", function () awful.screen.focus(-1)       end),
252     awful.key({ modkey, "Shift"   }, "h",   awful.tag.viewprev       ),
253     awful.key({ modkey, "Shift"   }, "l",  awful.tag.viewnext       ),
254
255     awful.key({ modkey,           }, "k",
256         function ()
257             awful.client.focus.byidx( 1)
258             if client.focus then client.focus:raise() end
259         end),
260     awful.key({ modkey,           }, "j",
261         function ()
262             awful.client.focus.byidx(-1)
263             if client.focus then client.focus:raise() end
264         end),
265     awful.key({ modkey,           }, "w", function () mymainmenu:show(true)        end),
266
267     -- Layout manipulation
268     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx(  1) end),
269     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx( -1) end),
270     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus( 1)       end),
271     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus(-1)       end),
272     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
273     awful.key({ modkey,           }, "Tab",
274         function ()
275             awful.client.focus.history.previous()
276             if client.focus then
277                 client.focus:raise()
278             end
279         end),
280
281     -- Standard program
282     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
283     awful.key({ modkey, "Control" }, "r", awesome.restart),
284     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
285
286     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
287     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
288     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
289     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
290     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
291     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
292     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
293     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
294
295     -- Prompt
296     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
297
298     awful.key({ modkey }, "x",
299               function ()
300                   awful.prompt.run({ prompt = "Run Lua code: " },
301                   mypromptbox[mouse.screen].widget,
302                   awful.util.eval, nil,
303                   awful.util.getdir("cache") .. "/history_eval")
304               end)
305 )
306
307 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
308 clientkeys = awful.util.table.join(
309     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
310     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
311     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
312     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
313     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
314     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
315     awful.key({ modkey }, "t", awful.client.togglemarked),
316     awful.key({ modkey,}, "m",
317         function (c)
318 --            if not awful.client.floating then
319 --                awful.client.floating.toggle()
320 --            end
321             c.maximized_horizontal = not c.maximized_horizontal
322             c.maximized_vertical   = not c.maximized_vertical
323         end)
324 )
325
326 -- Compute the maximum number of digit we need, limited to 9
327 keynumber = 0
328 for s = 1, screen.count() do
329    keynumber = math.min(9, math.max(#tags[s], keynumber));
330 end
331
332 for i = 1, keynumber do
333     globalkeys = awful.util.table.join(globalkeys,
334         awful.key({ modkey }, i,
335                   function ()
336                         local screen = mouse.screen
337                         if tags[screen][i] then
338                             awful.tag.viewonly(tags[screen][i])
339                         end
340                   end),
341         awful.key({ modkey, "Control" }, i,
342                   function ()
343                       local screen = mouse.screen
344                       if tags[screen][i] then
345                           tags[screen][i].selected = not tags[screen][i].selected
346                       end
347                   end),
348         awful.key({ modkey, "Shift" }, i,
349                   function ()
350                       if client.focus and tags[client.focus.screen][i] then
351                           awful.client.movetotag(tags[client.focus.screen][i])
352                       end
353                   end),
354         awful.key({ modkey, "Control", "Shift" }, i,
355                   function ()
356                       if client.focus and tags[client.focus.screen][i] then
357                           awful.client.toggletag(tags[client.focus.screen][i])
358                       end
359                   end),
360         awful.key({ modkey, "Shift" }, "F" .. i,
361                   function ()
362                       local screen = mouse.screen
363                       if tags[screen][i] then
364                           for k, c in pairs(awful.client.getmarked()) do
365                               awful.client.movetotag(tags[screen][i], c)
366                           end
367                       end
368                    end))
369 end
370
371 cmdmodkey = "Mod3"
372
373 -- xmms2 & sound
374 globalkeys = awful.util.table.join(globalkeys,
375   awful.key({ cmdmodkey }, "Prior", function () awful.util.spawn("amixer set Master 2+") end),
376   awful.key({ cmdmodkey }, "Next", function () awful.util.spawn("amixer set Master 2-") end),
377   awful.key({ cmdmodkey }, "Up", function () awful.util.spawn("amixer set PCM 2+") end),
378   awful.key({ cmdmodkey }, "Down", function () awful.util.spawn("amixer set PCM 2-") end),
379   awful.key({ cmdmodkey }, "Home", function () awful.util.spawn("amixer set Mic toggle") end),
380   awful.key({ cmdmodkey }, "End", function () awful.util.spawn("amixer set Master toggle") end),
381   awful.key({ cmdmodkey }, "Left", function () awful.util.spawn("xmms2 prev") end),
382   awful.key({ cmdmodkey }, "Right", function () awful.util.spawn("xmms2 next") end),
383   awful.key({ cmdmodkey }, "space", function () awful.util.spawn("xmms2 toggleplay") end),
384   awful.key({ cmdmodkey }, "backslash", function () awful.util.spawn_with_shell("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end),
385   awful.key({ cmdmodkey, "Shift" }, "backslash", function () awful.util.spawn_with_shell("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end)
386 )
387
388 -- misc apps
389 globalkeys = awful.util.table.join(globalkeys,
390   awful.key({ cmdmodkey }, "n", function () awful.util.spawn("sensible-browser") end),
391   awful.key({ cmdmodkey }, "m", function () awful.util.spawn(terminal .. " -e mutt -f =store") end),
392   awful.key({ cmdmodkey }, "t", function () awful.util.spawn(terminal) end),
393   awful.key({ cmdmodkey }, "c", function () awful.util.spawn(terminal .. " -e python") end),
394 --  awful.key({ cmdmodkey }, "r", function () awful.util.spawn("gmrun") end),
395   awful.key({ cmdmodkey }, "r", function () mypromptbox[mouse.screen]:run() end),
396   awful.key({ cmdmodkey }, "j", function () awful.util.spawn("jpilot") end),
397   awful.key({ cmdmodkey }, "x", function () awful.util.spawn_with_shell("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end),
398   awful.key({ cmdmodkey, "Shift" }, "x", function () awful.util.spawn("xscreensaver-command -exit") end),
399   awful.key(nil, "XF86ScreenSaver", function () awful.util.spawn("xset dpms force off") end)
400 )
401
402 -- Set keys
403 root.keys(globalkeys)
404 -- }}}
405
406 -- {{{ Hooks
407 -- Hook function to execute when focusing a client.
408 awful.hooks.focus.register(function (c)
409     if not awful.client.ismarked(c) then
410         c.border_color = beautiful.border_focus
411     end
412 end)
413
414 -- Hook function to execute when unfocusing a client.
415 awful.hooks.unfocus.register(function (c)
416     if not awful.client.ismarked(c) then
417         c.border_color = beautiful.border_normal
418     end
419 end)
420
421 -- Hook function to execute when marking a client
422 awful.hooks.marked.register(function (c)
423     c.border_color = beautiful.border_marked
424 end)
425
426 -- Hook function to execute when unmarking a client.
427 awful.hooks.unmarked.register(function (c)
428     c.border_color = beautiful.border_focus
429 end)
430
431 -- Hook function to execute when the mouse enters a client.
432 awful.hooks.mouse_enter.register(function (c)
433     -- Sloppy focus, but disabled for magnifier layout
434     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
435         and awful.client.focus.filter(c) then
436         client.focus = c
437     end
438 end)
439
440 -- Hook function to execute when a new client appears.
441 awful.hooks.manage.register(function (c, startup)
442     -- If we are not managing this application at startup,
443     -- move it to the screen where the mouse is.
444     -- We only do it for filtered windows (i.e. no dock, etc).
445     if not startup and awful.client.focus.filter(c) then
446         c.screen = mouse.screen
447     end
448
449     if use_titlebar then
450         -- Add a titlebar
451         awful.titlebar.add(c, { modkey = modkey })
452     end
453     -- Add mouse bindings
454     c:buttons(awful.util.table.join(
455         awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
456         awful.button({ modkey }, 1, awful.mouse.client.move),
457         awful.button({ modkey }, 3, awful.mouse.client.resize)
458     ))
459     -- New client may not receive focus
460     -- if they're not focusable, so set border anyway.
461     c.border_width = beautiful.border_width
462     c.border_color = beautiful.border_normal
463
464     -- Check if the application should be floating.
465     -- OVERRIDDEN, SEE tiledapps BELOW
466     local cls = c.class
467     local inst = c.instance
468     if floatapps[cls] then
469         awful.client.floating.set(c, floatapps[cls])
470     elseif floatapps[inst] then
471         awful.client.floating.set(c, floatapps[inst])
472     end
473
474     -- Override with tiledapps
475     awful.client.floating.set(c, not (tiledapps[inst] or tiledapps[cls]))
476
477     -- Check application->screen/tag mappings.
478     local target
479     if apptags[cls] then
480         target = apptags[cls]
481     elseif apptags[inst] then
482         target = apptags[inst]
483     end
484     if target then
485         c.screen = target.screen
486         awful.client.movetotag(tags[target.screen][target.tag], c)
487     end
488
489     -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
490     client.focus = c
491
492     -- Set key bindings
493     c:keys(clientkeys)
494
495     -- Set the windows at the slave,
496     -- i.e. put it at the end of others instead of setting it master.
497     -- awful.client.setslave(c)
498
499     -- Honor size hints: if you want to drop the gaps between windows, set this to false.
500     c.size_hints_honor = true
501
502     -- Maximise some
503     if maxapps[inst] or maxapps[cls] then
504         c.maximized_horizontal = not c.maximized_horizontal
505         c.maximized_vertical   = not c.maximized_vertical
506     end
507 end)
508
509 -- Hook function to execute when arranging the screen.
510 -- (tag switch, new client, etc)
511 awful.hooks.arrange.register(function (screen)
512     local layout = awful.layout.getname(awful.layout.get(screen))
513     if layout and beautiful["layout_" ..layout] then
514         mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
515     else
516         mylayoutbox[screen].image = nil
517     end
518
519     -- Give focus to the latest client in history if no window has focus
520     -- or if the current window is a desktop or a dock one.
521     if not client.focus then
522         local c = awful.client.focus.history.get(screen, 0)
523         if c then client.focus = c end
524     end
525 end)
526
527 -- Hook called every second
528 awful.hooks.timer.register(1, function ()
529     mytimebox.text = os.date(" %a %d %b %H:%M:%S ")
530 end)
531
532 -- Hook called every sixty seconds
533 function hook_battery()
534     mybatterybox.text = " " .. get_acpibatt() .. " "
535 end
536
537 -- {{{ Statusbar battery
538 --
539 function get_acpibatt()
540
541     local f = io.popen('acpi -b', 'r')
542     if not f then
543       return "acpi -b failed"
544     end
545
546     local s = f:read('*l')
547     f:close()
548     if not s then
549       return '-';
550     end
551
552     -- Battery 0: Discharging, 89%, 00:02:14 remaining
553     -- Battery 0: Charging, 58%, 00:02:14 until charged
554     -- Battery 0: Full, 100%
555     -- so find the first bit first and then go look for the time
556     local st, en, status, percent = string.find(s, '%a+%s%d:%s(%a+),%s(%d+%%)');
557     local st, en, time = string.find(s, ',%s(%d+:%d+):%d+%s%a+', en);
558
559     if not status or not percent then -- time can be empty if we're full
560       return "couldn't parse line " .. s
561     end
562
563     if not time then
564       return percent
565     end
566
567     if status == 'Charging' then
568       return '↑ ' .. percent;
569     elseif status == 'Discharging' then
570       return '↓ '.. time;
571     else
572       return '';
573     end
574 end
575 -- }}}
576
577 --{{{ batt hook
578 local function get_bat()
579   local a = io.open("/sys/class/power_supply/BAT1/charge_full")
580   for line in a:lines() do
581     full = line
582   end
583   a:close()
584   local b = io.open("/sys/class/power_supply/BAT1/charge_now")
585   for line in b:lines() do
586     now = line
587   end
588   b:close()
589   batt=math.floor(now*100/full)
590   batterywidget:bar_data_add("bat",batt )
591 end
592 --}}}
593
594 -- Set up some hooks
595 awful.hooks.timer.register(20, hook_battery)
596 -- awful.hooks.timer.register(5, get_bat)
597 -- }}}
598
599 -- Highlight statusbars on the screen that has focus,
600 -- set this to false if you only have one screen or
601 -- you don't like it :P
602 if screen.count() > 1 then
603   statusbar_highlight_focus = true
604 else
605   statusbar_highlight_focus = false
606 end
607
608 hook_battery()
609
610 function displayMonth(month,year,weekStart)
611     local t,wkSt=os.time{year=year, month=month+1, day=0},weekStart or 1
612     local d=os.date("*t",t)
613     local mthDays,stDay=d.day,(d.wday-d.day-wkSt+1)%7
614
615     local lines = {}
616
617     for x=0,6 do
618         lines[x+1] = os.date("%a ",os.time{year=2006,month=1,day=x+wkSt})
619     end
620     lines[8] = "    "
621
622     local writeLine = 1
623     while writeLine < (stDay + 1) do
624         lines[writeLine] = lines[writeLine] .. "   "
625         writeLine = writeLine + 1
626     end
627
628     for x=1,mthDays do
629         if writeLine == 8 then
630             writeLine = 1
631         end
632         if writeLine == 1 or x == 1 then
633             lines[8] = lines[8] .. os.date(" %V",os.time{year=year,month=month,day=x})
634         end
635         if (#(tostring(x)) == 1) then
636             x = " " .. x
637         end
638         lines[writeLine] = lines[writeLine] .. " " .. x
639         writeLine = writeLine + 1
640     end
641     local header = os.date("%B %Y\n",os.time{year=year,month=month,day=1})
642     header = string.rep(" ", math.floor((#(lines[1]) - #header) / 2 )) .. header
643
644     return header .. table.concat(lines, '\n')
645 end
646
647 local calendar = {}
648 function switchNaughtyMonth(switchMonths)
649     if (#calendar < 3) then return end
650     local swMonths = switchMonths or 1
651     calendar[1] = calendar[1] + swMonths
652     calendar[3].box.widgets[2].text = displayMonth(calendar[1], calendar[2], 2)
653 end
654
655 mytimebox.mouse_enter = function ()
656     local month, year = os.date('%m'), os.date('%Y')
657     calendar = { month, year,
658                 naughty.notify({
659                     text = displayMonth(month, year, 2),
660                     timeout = 0, hover_timeout = 0.5,
661                     width = 200, screen = mouse.screen
662                 })
663                }
664 end
665 mytimebox.mouse_leave = function () naughty.destroy(calendar[3]) end
666
667 mytimebox.buttons = awful.util.table.join(
668     awful.button({ }, 1, function() switchNaughtyMonth(-1) end),
669     awful.button({ }, 3, function() switchNaughtyMonth(1) end),
670     awful.button({ }, 4, function() switchNaughtyMonth(-1) end),
671     awful.button({ }, 5, function() switchNaughtyMonth(1) end),
672     awful.button({ 'Shift' }, 1, function() switchNaughtyMonth(-12) end),
673     awful.button({ 'Shift' }, 3, function() switchNaughtyMonth(12) end),
674     awful.button({ 'Shift' }, 4, function() switchNaughtyMonth(-12) end),
675     awful.button({ 'Shift' }, 5, function() switchNaughtyMonth(12) end)
676 )