--- 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({
- button({ }, 1, function (c) client.focus = c; c:raise() end),
- button({ modkey }, 1, awful.mouse.client.move),
- 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
- awful.client.maximize(c)
- 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
-
- -- Uncomment if you want mouse warping
- --[[
- if client.focus then
- local c_c = client.focus:fullgeometry()
- local m_c = mouse.coords()
-
- if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
- m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
- if table.maxn(m_c.buttons) == 0 then
- mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
- end
- end
- end
- ]]
-end)
-
--- Hook called every second
-awful.hooks.timer.register(1, function ()
- -- For unix time_t lovers
- -- mytextbox.text = " " .. os.time() .. " time_t "
- -- Otherwise use:
- mytimebox.text = " " .. os.date() .. " "
-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
- status = 'c';
- elseif status == 'Discarching' then
- status = 'd';
- else
- status = '-';
- end
-
- return percent; -- .. ' (' .. status .. ')'; -- .. ' ' .. time .. ' left';
-end
--- }}}
-
---{{{ batt hook
-local function get_bat()
- local a = io.open("/sys/class/power_supply/BAT1/charge_full")
- for line in a:lines() do
- full = line
- end
- a:close()
- local b = io.open("/sys/class/power_supply/BAT1/charge_now")
- for line in b:lines() do
- now = line
- end
- b:close()
- batt=math.floor(now*100/full)
- batterywidget:bar_data_add("bat",batt )
-end
---}}}
-
--- Set up some hooks
-awful.hooks.timer.register(120, hook_battery)
--- awful.hooks.timer.register(5, get_bat)