1 local wibox = require("wibox")
2 local vicious = require("vicious")
3 local naughty = require("naughty")
4 local beautiful = require("beautiful")
7 module("battery_widget")
9 -- Battery (based on https://bitbucket.org/skrattaren/awesome/src/)
11 local limits = { {25, 5},
16 local function getnextlim (num)
17 for ind, pair in pairs(limits) do
18 lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0
31 local function batclosure ()
32 local nextlim = limits[1][1]
33 return function (_, args)
35 local state, charge = args[1], args[2]
36 if not charge then return end
40 if charge <= nextlim then
41 naughty.notify({title = "⚡ Warning! ⚡",
42 text = "Battery has leaked most of its power ( ⚡ "..charge.."%)!",
44 position = "top_right",
45 fg = beautiful.fg_focus,
46 bg = beautiful.bg_focus
48 nextlim = getnextlim(charge)
50 elseif state == "+" then
52 nextlim = limits[1][1]
56 if dir ~= 0 then charge = charge.."%" end
57 return " "..prefix.." "..dirsign..charge..dirsign.." "
61 batterywidget = wibox.widget.textbox()
62 vicious.register(batterywidget, vicious.widgets.bat, batclosure(), 31, "BAT0")