--- 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)
--- }}}
-
-cmdmodkey = "Mod3"
-
--- xmms2 & sound
-keybinding({ cmdmodkey }, "Prior", function () awful.util.spawn("amixer set Master 2+") end):add()
-keybinding({ cmdmodkey }, "Next", function () awful.util.spawn("amixer set Master 2-") end):add()
-keybinding({ cmdmodkey }, "Up", function () awful.util.spawn("amixer set PCM 2+") end):add()
-keybinding({ cmdmodkey }, "Down", function () awful.util.spawn("amixer set PCM 2-") end):add()
-keybinding({ cmdmodkey }, "Home", function () awful.util.spawn("amixer set Mic toggle") end):add()
-keybinding({ cmdmodkey }, "End", function () awful.util.spawn("amixer set Master toggle") end):add()
-keybinding({ cmdmodkey }, "Left", function () awful.util.spawn("xmms2 prev") end):add()
-keybinding({ cmdmodkey }, "Right", function () awful.util.spawn("xmms2 next") end):add()
-keybinding({ cmdmodkey }, "space", function () awful.util.spawn("xmms2 toggleplay") end):add()
-keybinding({ cmdmodkey }, "backslash", function () awful.util.spawn("xmms2 current | head -1 | xmessage -nearmouse -timeout 5 -file -") end):add()
-keybinding({ cmdmodkey, "Shift" }, "backslash", function () awful.util.spawn("xmms2 list | xmessage -nearmouse -timeout 5 -file -") end):add()
-
--- misc apps
-keybinding({ cmdmodkey }, "n", function () awful.util.spawn("sensible-browser") end):add()
-keybinding({ cmdmodkey }, "m", function () awful.util.spawn(terminal .. " -e mutt -f =store") end):add()
-keybinding({ cmdmodkey }, "t", function () awful.util.spawn(terminal) end):add()
-keybinding({ cmdmodkey }, "c", function () awful.util.spawn(terminal .. " -e python") end):add()
-keybinding({ cmdmodkey }, "r", function () awful.util.spawn("gmrun") end):add()
-keybinding({ cmdmodkey }, "j", function () awful.util.spawn("jpilot") end):add()
-keybinding({ cmdmodkey }, "x", function () awful.util.spawn("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end):add()
-keybinding({ cmdmodkey, "Shift" }, "x", function () awful.util.spawn("xscreensaver-command -exit") end):add()
-
--- Highlight statusbars on the screen that has focus,
--- set this to false if you only have one screen or
--- you don't like it :P
-if screen.count() > 1 then
- statusbar_highlight_focus = true
-else
- statusbar_highlight_focus = false
-end
-
-hook_battery()
-
-function displayMonth(month,year,weekStart)
- local t,wkSt=os.time{year=year, month=month+1, day=0},weekStart or 1
- local d=os.date("*t",t)
- local mthDays,stDay=d.day,(d.wday-d.day-wkSt+1)%7
-
- local lines = {}
-
- for x=0,6 do
- lines[x+1] = os.date("%a ",os.time{year=2006,month=1,day=x+wkSt})
- end
- lines[8] = " "
-
- local writeLine = 1
- while writeLine < (stDay + 1) do
- lines[writeLine] = lines[writeLine] .. " "
- writeLine = writeLine + 1
- end
-
- for x=1,mthDays do
- if writeLine == 8 then
- writeLine = 1
- end
- if writeLine == 1 or x == 1 then
- lines[8] = lines[8] .. os.date(" %V",os.time{year=year,month=month,day=x})
- end
- if (#(tostring(x)) == 1) then
- x = " " .. x
- end
- lines[writeLine] = lines[writeLine] .. " " .. x
- writeLine = writeLine + 1