-- my widgets
local volume_widget = require("widgets/volume_widget")
+local battery_widget = require("widgets/battery_widget")
-- Create a textclock widget
mytextclock = awful.widget.textclock()
local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(volume_widget)
+ right_layout:add(battery_widget)
right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s])
--- /dev/null
+local wibox = require("wibox")
+local vicious = require("vicious")
+local naughty = require("naughty")
+local beautiful = require("beautiful")
+local pairs = pairs
+
+module("battery_widget")
+
+-- Battery (based on https://bitbucket.org/skrattaren/awesome/src/)
+
+local limits = { {25, 5},
+ {12, 3},
+ { 7, 1},
+ {0}}
+
+local function getnextlim (num)
+ for ind, pair in pairs(limits) do
+ lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0
+ if num > nextlim then
+ repeat
+ lim = lim - step
+ until num > lim
+ if lim < nextlim then
+ lim = nextlim
+ end
+ return lim
+ end
+ end
+end
+
+local function batclosure ()
+ local nextlim = limits[1][1]
+ return function (_, args)
+ local prefix = "⚡"
+ local state, charge = args[1], args[2]
+ if not charge then return end
+ if state == "-" then
+ dirsign = "↓"
+ prefix = "Bat:"
+ if charge <= nextlim then
+ naughty.notify({title = "⚡ Warning! ⚡",
+ text = "Battery has leaked most of its power ( ⚡ "
+ ..charge.."%)!",
+ timeout = 7,
+ position = "bottom_right",
+ fg = beautiful.fg_focus,
+ bg = beautiful.bg_focus
+ })
+ nextlim = getnextlim(charge)
+ end
+ elseif state == "+" then
+ dirsign = "↑"
+ nextlim = limits[1][1]
+ else
+ return " ⚡ "
+ end
+ if dir ~= 0 then charge = charge.."%" end
+ return " "..prefix.." "..dirsign..charge..dirsign.." "
+ end
+end
+
+batterywidget = wibox.widget.textbox()
+vicious.register(batterywidget, vicious.widgets.bat, batclosure(),
+ 31, "BAT0")
+
+return batterywidget