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:

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