--- Hook function to execute when a new client appears.
-awful.hooks.manage.register(function (c, startup)
- -- If we are not managing this application at startup,
- -- move it to the screen where the mouse is.
- -- We only do it for filtered windows (i.e. no dock, etc).
- if not startup and awful.client.focus.filter(c) then
- c.screen = mouse.screen
- end
-
- if use_titlebar then
- -- Add a titlebar
- awful.titlebar.add(c, { modkey = modkey })
- end
- -- Add mouse bindings
- c:buttons(awful.util.table.join(
- awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
- awful.button({ modkey }, 1, awful.mouse.client.move),
- awful.button({ modkey }, 3, awful.mouse.client.resize)
- ))
- -- New client may not receive focus
- -- if they're not focusable, so set border anyway.
- c.border_width = beautiful.border_width
- c.border_color = beautiful.border_normal
-
- -- Check if the application should be floating.
- -- OVERRIDDEN, SEE tiledapps BELOW
- local cls = c.class
- local inst = c.instance
- if floatapps[cls] then
- awful.client.floating.set(c, floatapps[cls])
- elseif floatapps[inst] then
- awful.client.floating.set(c, floatapps[inst])
- end
-
- -- Override with tiledapps
- awful.client.floating.set(c, not (tiledapps[inst] or tiledapps[cls]))
-
- -- Check application->screen/tag mappings.
- local target
- if apptags[cls] then
- target = apptags[cls]
- elseif apptags[inst] then
- target = apptags[inst]
- end
- if target then
- c.screen = target.screen
- awful.client.movetotag(tags[target.screen][target.tag], c)
- end
-
- -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
- client.focus = c
-
- -- Set key bindings
- c:keys(clientkeys)
-
- -- Set the windows at the slave,
- -- i.e. put it at the end of others instead of setting it master.
- -- awful.client.setslave(c)
-
- -- Honor size hints: if you want to drop the gaps between windows, set this to false.
- c.size_hints_honor = true
-
- -- Maximise some
- if maxapps[inst] or maxapps[cls] then
- c.maximized_horizontal = not c.maximized_horizontal
- c.maximized_vertical = not c.maximized_vertical
- end
-end)
-
--- Hook function to execute when arranging the screen.
--- (tag switch, new client, etc)
-awful.hooks.arrange.register(function (screen)
- local layout = awful.layout.getname(awful.layout.get(screen))
- if layout and beautiful["layout_" ..layout] then
- mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
- else
- mylayoutbox[screen].image = nil
- end
-
- -- Give focus to the latest client in history if no window has focus
- -- or if the current window is a desktop or a dock one.
- if not client.focus then
- local c = awful.client.focus.history.get(screen, 0)
- if c then client.focus = c end
- end
-end)
-
--- Hook called every second
-awful.hooks.timer.register(1, function ()
- mytimebox.text = os.date(" %a %d %b %H:%M:%S ")
-end)
-
--- Hook called every sixty seconds
-function hook_battery()
- mybatterybox.text = " " .. get_acpibatt() .. " "
-end
-
--- {{{ Statusbar battery
---
-function get_acpibatt()
-
- local f = io.popen('acpi -b', 'r')
- if not f then
- return "acpi -b failed"
- end
-
- local s = f:read('*l')
- f:close()
- if not s then
- return '-';
- end
-
- -- Battery 0: Discharging, 89%, 00:02:14 remaining
- -- Battery 0: Charging, 58%, 00:02:14 until charged
- -- Battery 0: Full, 100%
- -- so find the first bit first and then go look for the time
- local st, en, status, percent = string.find(s, '%a+%s%d:%s(%a+),%s(%d+%%)');
- local st, en, time = string.find(s, ',%s(%d+:%d+):%d+%s%a+', en);
-
- if not status or not percent then -- time can be empty if we're full
- return "couldn't parse line " .. s
- end
-
- if not time then
- return percent
- end
-
- if status == 'Charging' then
- return '↑ ' .. percent;
- elseif status == 'Discharging' then
- return '↓ '.. time;
- else
- return '';
- end
-end