function batteryInfoUpdate(adapter, warn, widget) spacer = " " local fcap = io.open("/sys/class/power_supply/"..adapter.."/capacity") local fsta = io.open("/sys/class/power_supply/"..adapter.."/status") local cap = fcap:read() local sta = fsta:read() fcap:close() fsta:close() if sta:match("Charging") then state = 1 icon = "▴" else state = -1 icon = "▾" end if tonumber(cap) < 10 and warn then naughty.notify({ title = "Battery Warning", text = "Battery "..adapter.." low at "..cap.."%!", timeout = 15, position = "top_right", fg = beautiful.fg_focus, bg = beautiful.bg_focus, }) end if tonumber(cap) < 10 then color='red' elseif tonumber(cap) < 25 then color='orange' else color='green' end widget:set_markup(spacer..""..icon..cap..'%'..spacer) end local wibox = require("wibox") bat0_widget = wibox.widget.textbox() bat0_widget:set_align("right") bat1_widget = wibox.widget.textbox() bat1_widget:set_align("right") battery_timer = timer({timeout = 20}) battery_timer:connect_signal("timeout", function() batteryInfoUpdate("BAT0", true, bat0_widget) batteryInfoUpdate("BAT1", false, bat1_widget) end) battery_timer:start() -- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1: