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

5eadc2dbb7569ceaa3a23c7fe4a78eb52992940b
[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 require("vicious")
11
12 -- Load Debian menu entries
13 require("debian.menu")
14
15 -- {{{ Variable definitions
16 -- Themes define colours, icons, and wallpapers
17 -- The default is a dark theme
18 theme_path = "/usr/share/awesome/themes/default/theme.lua"
19 -- Uncommment this for a lighter theme
20 -- theme_path = "/usr/share/awesome/themes/sky/theme.lua"
21
22 wallpaper_cmd = { "awsetbg -t .config/awesome/bgstripes.png" } 
23
24 -- Actually load theme
25 beautiful.init(theme_path)
26
27 -- This is used later as the default terminal and editor to run.
28 terminal = "x-terminal-emulator"
29 editor = os.getenv("EDITOR") or "editor"
30 editor_cmd = terminal .. " -e " .. editor
31
32 -- Default modkey.
33 -- Usually, Mod4 is the key with a logo between Control and Alt.
34 -- If you do not like this or do not have such a key,
35 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
36 -- However, you can use another modifier like Mod1, but it may interact with others.
37 modkey = "Mod4"
38
39 -- Table of layouts to cover with awful.layout.inc, order matters.
40 layouts =
41 {
42 --    awful.layout.suit.tile,
43 --    awful.layout.suit.tile.left,
44 --    awful.layout.suit.tile.bottom,
45 --    awful.layout.suit.tile.top,
46     awful.layout.suit.fair,
47     awful.layout.suit.fair.horizontal,
48 --    awful.layout.suit.spiral,
49 --    awful.layout.suit.spiral.dwindle,
50     awful.layout.suit.max,
51 --    awful.layout.suit.max.fullscreen,
52     awful.layout.suit.magnifier,
53     awful.layout.suit.floating
54 }
55
56 ---- Table of clients that should be set floating. The index may be either
57 ---- the application class or instance. The instance is useful when running
58 ---- a console app in a terminal like (Music on Console)
59 ----    xterm -name mocp -e mocp
60 ---- OVERRULED BY TILEDAPPS BELOW
61 --floatapps =
62 --{
63 --    -- by class
64 --    ["MPlayer"] = true,
65 --    ["pinentry"] = true,
66 --    ["GIMP"] = true,
67 --    ["twinkle"] = true,
68 --    ["Add-ons"] = true,
69 --    ["Play stream"] = true,
70 --    ["gscan2pdf"] = true,
71 --}
72 --
73 ---- Applications that should never float, assuming everything else floats
74 ---- (by instance)
75 --tiledapps =
76 --{
77 --    ["urxvt"] = true,
78 --}
79 --
80 ---- Applications that should be maximised
81 ---- (by instance)
82 --maxapps =
83 --{
84 --    ["Navigator"] = true,
85 --    -- jpilot is -v
86 --    ["-v"] = true,
87 --    ["Xpdf"] = true,
88 --    ["gscan2pdf"] = true
89 --}
90 --
91 ---- Applications to be moved to a pre-defined tag by class or instance.
92 ---- Use the screen and tags indices.
93 --apptags =
94 --{
95 --    ["Navigator"] = { screen = 1, tag = 9 },
96 --    -- jpilot is -v
97 --    ["-v"] = { screen = 1, tag = 8 },
98 --}
99
100 -- Define if we want to use titlebar on all applications.
101 use_titlebar = false
102 -- }}}
103
104 -- {{{ Tags
105 tags = {}
106 tags.settings = {
107     { name = "1", layout = layouts[1] },
108     { name = "2", layout = layouts[1] },
109     { name = "3", layout = layouts[1] },
110     { name = "4", layout = layouts[1] },
111     { name = "5", layout = layouts[5] },
112     { name = "6", layout = layouts[3] },
113     { name = "7", layout = layouts[3] },
114     { name = "8", layout = layouts[3] },
115     { name = "9", layout = layouts[3] },
116 }
117
118 -- Define a tag table which hold all screen tags.
119 for s = 1, screen.count() do
120     tags[s] = {}
121     for i, v in ipairs(tags.settings) do
122         tags[s][i] = tag({ name = v.name })
123         tags[s][i].screen = s
124         awful.tag.setproperty(tags[s][i], "layout", v.layout)
125         awful.tag.setproperty(tags[s][i], "mwfact", v.mwfact)
126         awful.tag.setproperty(tags[s][i], "hide",   v.hide)
127     end
128     tags[s][1].selected = true
129 end
130
131 if screen.count() == 3 then
132   tags[1][1].selected = false
133   tags[1][9].selected = true
134 end
135 -- }}}
136
137 -- {{{ Menu
138 -- Create a laucher widget and a main menu
139 myawesomemenu = {
140    { "manual", terminal .. " -e man awesome" },
141    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
142    { "restart", awesome.restart },
143    { "quit", awesome.quit }
144 }
145
146 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
147                                     { "Debian", debian.menu.Debian_menu.Debian },
148                                     { "open terminal", terminal }
149                                   }
150                         })
151
152 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
153                                      menu = mymainmenu })
154 -- }}}
155
156 -- {{{ Wibox
157
158 -- {{{ Reusable separators
159 spacer         = widget({ type = "textbox", name = "spacer" })
160 separator      = widget({ type = "textbox", name = "separator" })
161 spacer.text    = " "
162 separator.text = "٭"
163 -- }}}
164
165 ---- {{{ CPU usage and temperature
166 ---- Widget icon
167 --cpuicon        = widget({ type = "imagebox", name = "cpuicon" })
168 --cpuicon.image  = image(beautiful.widget_cpu)
169 ---- Initialize widgets
170 --thermalwidget  = widget({ type = "textbox", name = "thermalwidget" })
171 --cpuwidget      = awful.widget.graph({ layout = awful.widget.layout.horizontal.rightleft })
172 ---- Graph properties
173 --cpuwidget:set_width(50)
174 ----cpuwidget:set_scale(false)
175 --cpuwidget:set_max_value(100)
176 --cpuwidget:set_background_color(beautiful.fg_off_widget)
177 --cpuwidget:set_border_color(beautiful.border_widget)
178 --cpuwidget:set_color(beautiful.fg_end_widget)
179 --cpuwidget:set_gradient_angle(0)
180 --cpuwidget:set_gradient_colors({
181 --    beautiful.fg_end_widget,
182 --    beautiful.fg_center_widget,
183 --    beautiful.fg_widget })
184 ---- Register widgets
185 --vicious.register(cpuwidget, vicious.widgets.cpu, "$1")
186 --vicious.register(thermalwidget, vicious.widgets.thermal, "CPU: $1°C", 19, "hwmon0")
187 ---- }}}
188
189 -- Battery widget
190 --batterywidget = widget({ type = 'progressbar', name = 'batterywidget' })
191 --batterywidget.width = 100
192 --batterywidget.height = 0.8
193 --batterywidget.gap = 1
194 --batterywidget.border_padding = 1
195 --batterywidget.border_width = 1
196 --batterywidget.ticks_count = 10
197 --batterywidget.ticks_gap = 1
198 --batterywidget.vertical = false
199 --batterywidget:bar_properties_set('bat', {
200 --  bg = 'black',
201 --  fg = 'blue4',
202 --  fg_off = 'red',
203 --  reverse = false,
204 --  min_value = 0,
205 --  max_value = 100
206 --})
207
208 -- Create a textclock widget
209 mytextclock = awful.widget.textclock({ align = "right" }, "%a %d %b %H:%M:%S", 1)
210
211 -- Create a systray
212 mysystray = widget({ type = "systray", align = "right" })
213
214 mybatterybox = widget({ type = "textbox", name = "mybatterybox", align = "right" })
215
216 -- Create a wibox for each screen and add it
217 mywibox = {}
218 mypromptbox = {}
219 mylayoutbox = {}
220 mytaglist = {}
221 mytaglist.buttons = awful.util.table.join(
222                     awful.button({ }, 1, awful.tag.viewonly),
223                     awful.button({ modkey }, 1, awful.client.movetotag),
224                     awful.button({ }, 3, awful.tag.viewtoggle),
225                     awful.button({ modkey }, 3, awful.client.toggletag),
226                     awful.button({ }, 4, awful.tag.viewnext),
227                     awful.button({ }, 5, awful.tag.viewprev)
228                     )
229 mytasklist = {}
230 mytasklist.buttons = awful.util.table.join(
231                      awful.button({ }, 1, function (c)
232                                               if not c:isvisible() then
233                                                   awful.tag.viewonly(c:tags()[1])
234                                               end
235                                               client.focus = c
236                                               c:raise()
237                                           end),
238                      awful.button({ }, 3, function ()
239                                               if instance then
240                                                   instance:hide()
241                                                   instance = nil
242                                               else
243                                                   instance = awful.menu.clients({ width=250 })
244                                               end
245                                           end),
246                      awful.button({ }, 4, function ()
247                                               awful.client.focus.byidx(1)
248                                               if client.focus then client.focus:raise() end
249                                           end),
250                      awful.button({ }, 5, function ()
251                                               awful.client.focus.byidx(-1)
252                                               if client.focus then client.focus:raise() end
253                                           end))
254
255 for s = 1, screen.count() do
256     -- Create a promptbox for each screen
257     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
258     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
259     -- We need one layoutbox per screen.
260     mylayoutbox[s] = awful.widget.layoutbox(s)
261     mylayoutbox[s]:buttons(awful.util.table.join(
262                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
263                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
264                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
265                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
266     -- Create a taglist widget
267     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
268
269     -- Create a tasklist widget
270     mytasklist[s] = awful.widget.tasklist(function(c)
271                                               return awful.widget.tasklist.label.currenttags(c, s)
272                                           end, mytasklist.buttons)
273
274     -- Create the wibox
275     mywibox[s] = awful.wibox({ position = "top", screen = s })
276     -- Add widgets to the wibox - order matters
277     mywibox[s].widgets = {
278         {
279 --            mylauncher,
280             mytaglist[s],
281             mypromptbox[s],
282             layout = awful.widget.layout.horizontal.leftright
283         },
284         mylayoutbox[s],
285         spacer,
286         mytextclock,
287         spacer, separator, spacer,
288         mybatterybox,
289 --        batterywidget,
290 --        spacer, separator, spacer,
291 --        cpuwidget.widget,
292 --        spacer, separator, spacer,
293 --        thermalwidget.widget,
294         spacer,
295         s == screen.count() and mysystray or nil,
296         mytasklist[s],
297         layout = awful.widget.layout.horizontal.rightleft
298     }
299 end
300
301 -- }}}
302
303 -- {{{ Mouse bindings
304 root.buttons(awful.util.table.join(
305     awful.button({ }, 3, function () mymainmenu:toggle() end),
306     awful.button({ }, 4, awful.tag.viewnext),
307     awful.button({ }, 5, awful.tag.viewprev)
308 ))
309 -- }}}
310
311 -- {{{ Key bindings
312 globalkeys = awful.util.table.join(
313     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
314     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
315     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
316     awful.key({ modkey, "Shift"   }, "Right", function () awful.screen.focus( 1)       end),
317     awful.key({ modkey, "Shift"   }, "Left", function () awful.screen.focus(-1)       end),
318     awful.key({ modkey, "Shift"   }, "h",   awful.tag.viewprev       ),
319     awful.key({ modkey, "Shift"   }, "l",  awful.tag.viewnext       ),
320
321     awful.key({ modkey,           }, "k",
322         function ()
323             awful.client.focus.byidx( 1)
324             if client.focus then client.focus:raise() end
325         end),
326     awful.key({ modkey,           }, "j",
327         function ()
328             awful.client.focus.byidx(-1)
329             if client.focus then client.focus:raise() end
330         end),
331     awful.key({ modkey,           }, "w", function () mymainmenu:show(true)        end),
332
333     -- Layout manipulation
334     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx(  1) end),
335     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx( -1) end),
336     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus( 1)       end),
337     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus(-1)       end),
338     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
339     awful.key({ modkey,           }, "Tab",
340         function ()
341             awful.client.focus.history.previous()
342             if client.focus then
343                 client.focus:raise()
344             end
345         end),
346
347     -- Standard program
348     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
349     awful.key({ modkey, "Control" }, "r", awesome.restart),
350     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
351
352     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
353     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
354     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
355     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
356     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
357     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
358     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
359     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
360
361     -- Prompt
362     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
363
364     awful.key({ modkey }, "x",
365               function ()
366                   awful.prompt.run({ prompt = "Run Lua code: " },
367                   mypromptbox[mouse.screen].widget,
368                   awful.util.eval, nil,
369                   awful.util.getdir("cache") .. "/history_eval")
370               end)
371 )
372
373 clientkeys = awful.util.table.join(
374     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
375     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
376     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
377     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
378     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
379     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
380     awful.key({ modkey            }, "t",      awful.client.togglemarked                        ),
381     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
382     awful.key({ modkey,           }, "m",
383         function (c)
384             c.maximized_horizontal = not c.maximized_horizontal
385             c.maximized_vertical   = not c.maximized_vertical
386         end)
387 )
388
389 -- Compute the maximum number of digit we need, limited to 9
390 keynumber = 0
391 for s = 1, screen.count() do
392    keynumber = math.min(9, math.max(#tags[s], keynumber));
393 end
394
395 -- Bind all key numbers to tags.
396 -- Be careful: we use keycodes to make it works on any keyboard layout.
397 -- This should map on the top row of your keyboard, usually 1 to 9.
398 for i = 1, keynumber do
399     globalkeys = awful.util.table.join(globalkeys,
400         awful.key({ modkey }, "#" .. i + 9,
401                   function ()
402                         local screen = mouse.screen
403                         if tags[screen][i] then
404                             awful.tag.viewonly(tags[screen][i])
405                         end
406                   end),
407         awful.key({ modkey, "Control" }, "#" .. i + 9,
408                   function ()
409                       local screen = mouse.screen
410                       if tags[screen][i] then
411                           awful.tag.viewtoggle(tags[screen][i])
412                       end
413                   end),
414         awful.key({ modkey, "Shift" }, "#" .. i + 9,
415                   function ()
416                       if client.focus and tags[client.focus.screen][i] then
417                           awful.client.movetotag(tags[client.focus.screen][i])
418                       end
419                   end),
420         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
421                   function ()
422                       if client.focus and tags[client.focus.screen][i] then
423                           awful.client.toggletag(tags[client.focus.screen][i])
424                       end
425                   end))
426 end
427
428 clientbuttons = awful.util.table.join(
429     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
430     awful.button({ modkey }, 1, awful.mouse.client.move),
431     awful.button({ modkey }, 3, awful.mouse.client.resize))
432
433 cmdmodkey = "Mod3"
434
435 -- xmms2 & sound
436 globalkeys = awful.util.table.join(globalkeys,
437   awful.key({ cmdmodkey }, "Prior", function () awful.util.spawn("amixer set Master 2+") end),
438   awful.key({ cmdmodkey }, "Next", function () awful.util.spawn("amixer set Master 2-") end),
439   awful.key({ cmdmodkey }, "Up", function () awful.util.spawn("amixer set PCM 2+") end),
440   awful.key({ cmdmodkey }, "Down", function () awful.util.spawn("amixer set PCM 2-") end),
441   awful.key({ cmdmodkey }, "Home", function () awful.util.spawn("amixer set Mic toggle") end),
442   awful.key({ cmdmodkey }, "End", function () awful.util.spawn("amixer set Master toggle") end),
443   awful.key({ cmdmodkey }, "Left", function () awful.util.spawn("xmms2 prev") end),
444   awful.key({ cmdmodkey }, "Right", function () awful.util.spawn("xmms2 next") end),
445   awful.key({ cmdmodkey }, "space", function () awful.util.spawn("xmms2 toggleplay") end),
446   awful.key({ cmdmodkey }, "backslash", function ()
447     local f = io.popen('xmms2 current', 'r')
448     naughty.notify({ title = "Now playing", text = f:read(), timeout = 5 })
449     f:close()
450   end),
451   awful.key({ cmdmodkey, "Shift" }, "backslash", function ()
452     local f = io.popen('xmms2 list', 'r')
453     naughty.notify({ title = "Playlist", text = f:read(), timeout = 15 })
454     f:close()
455   end)
456 )
457
458 -- misc apps
459 globalkeys = awful.util.table.join(globalkeys,
460   awful.key({ cmdmodkey }, "n", function () awful.util.spawn("sensible-browser") end),
461   awful.key({ cmdmodkey }, "m", function () awful.util.spawn(terminal .. " -e mutt -f =store") end),
462   awful.key({ cmdmodkey }, "t", function () awful.util.spawn(terminal) end),
463   awful.key({ cmdmodkey }, "c", function () awful.util.spawn(terminal .. " -e python") end),
464   awful.key({ cmdmodkey }, "r", function () mypromptbox[mouse.screen]:run() end),
465   awful.key({ cmdmodkey }, "j", function () awful.util.spawn("jpilot") end),
466   awful.key({ cmdmodkey }, "i", function () awful.util.spawn(terminal .. " -title irc -name irc -e ssh -t irc screen -dr irc") end),
467   awful.key({ cmdmodkey }, "x", function () awful.util.spawn_with_shell("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver; xscreensaver-command -lock") end),
468   awful.key({ cmdmodkey, "Shift" }, "x", function () awful.util.spawn("xscreensaver-command -exit") end),
469   awful.key(nil, "XF86ScreenSaver", function () awful.util.spawn("xset dpms force off") end)
470 )
471
472 -- Set keys
473 root.keys(globalkeys)
474 -- }}}
475
476 -- {{{ Rules
477 awful.rules.rules = {
478     -- All clients will match this rule.
479     { rule = { },
480       properties = { border_width = beautiful.border_width,
481                      border_color = beautiful.border_normal,
482                      focus = true,
483                      floating = true,
484                      keys = clientkeys,
485                      buttons = clientbuttons } },
486     { rule = { class = "URxvt" },
487       properties = { floating = false } },
488     { rule = { class = "URxvt", instance = "irc" },
489       properties = { floating = false, tag = tags[screen.count()][screen.count() == 1 and 2 or 1], switchtotag = true } },
490     { rule = { class = "Iceweasel" },
491       properties = { tag = tags[screen.count() == 3 and 1 or screen.count()][9], switchtotag = false, floating = false } },
492     { rule = { class = "Iceweasel", instance = "Dialog" },
493       properties = { floating = true }, callback = awful.placement.centered },
494     { rule = { class = "Jpilot" },
495       properties = { tag = tags[screen.count() == 3 and 1 or screen.count()][8], switchtotag = true, floating = false } },
496 }
497 -- }}}
498
499 -- {{{ Signals
500 -- Signal function to execute when a new client appears.
501 client.add_signal("manage", function (c, startup)
502     -- Add a titlebar
503     -- awful.titlebar.add(c, { modkey = modkey })
504
505     -- Enable sloppy focus
506     c:add_signal("mouse::enter", function(c)
507         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
508             and awful.client.focus.filter(c) then
509             client.focus = c
510         end
511     end)
512
513     if not startup then
514         -- Set the windows at the slave,
515         -- i.e. put it at the end of others instead of setting it master.
516         -- awful.client.setslave(c)
517
518         -- Put windows in a smart way, only if they does not set an initial position.
519         if not c.size_hints.user_position and not c.size_hints.program_position then
520             --awful.placement.center_vertical(c)
521             --awful.placement.center_horizontal(c)
522             awful.placement.no_overlap(c)
523             awful.placement.no_offscreen(c)
524         end
525     end
526 end)
527
528 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
529 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
530
531 -- Hook called every sixty seconds
532 function hook_battery()
533     mybatterybox.text = " " .. get_acpibatt() .. " "
534 end
535 -- }}}
536
537 -- {{{ Statusbar battery
538 --
539 function get_acpibatt()
540     local f = io.popen('acpi -b', 'r')
541     if not f then
542       return "acpi -b failed"
543     end
544
545     local s = f:read('*l')
546     f:close()
547     if not s then
548       return '-';
549     end
550
551     -- Battery 0: Discharging, 89%, 00:02:14 remaining
552     -- Battery 0: Charging, 58%, 00:02:14 until charged
553     -- Battery 0: Full, 100%
554     -- so find the first bit first and then go look for the time
555     local st, en, status, percent = string.find(s, '%a+%s%d:%s(%a+),%s(%d+%%)');
556     local st, en, time = string.find(s, ',%s(%d+:%d+):%d+%s%a+', en);
557
558     if not status or not percent then -- time can be empty if we're full
559       return "couldn't parse line " .. s
560     end
561
562     if not time then
563       return percent
564     end
565
566     if status == 'Charging' then
567       return '↑ ' .. percent;
568     elseif status == 'Discharging' then
569       return '↓ '.. time;
570     else
571       return '';
572     end
573 end
574 t = timer({ timeout = 20 })
575 t:add_signal('timeout', hook_battery)
576 t:start()
577 hook_battery()
578 -- }}}
579
580 --{{{ batt hook
581 local function get_bat()
582   local a = io.open("/sys/class/power_supply/BAT1/charge_full")
583   for line in a:lines() do
584     full = line
585   end
586   a:close()
587   local b = io.open("/sys/class/power_supply/BAT1/charge_now")
588   for line in b:lines() do
589     now = line
590   end
591   b:close()
592   batt=math.floor(now*100/full)
593   batterywidget:bar_data_add("bat",batt )
594 end
595 -- awful.hooks.timer.register(5, get_bat)
596 --}}}