local naughty = require("naughty") local beautiful = require("beautiful") 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 icon = "▴" elseif sta:match("Discharging") then icon = "▾" else icon = "‐" end if tonumber(cap) < 10 and warn then local bg = beautiful.bg_focus local fg = beautiful.fg_focus if tonumber(cap) <= 5 then bg = beautiful.bg_urgent fg = beautiful.fg_urgent end naughty.notify({ title = "Battery Warning", text = "Battery "..adapter.." low at "..cap.."%!", timeout = 15, position = "top_right", fg = fg, bg = bg }) end local color=nil if warn then if tonumber(cap) < 10 then color='red' elseif tonumber(cap) < 20 then color='orange' end end local s = cap..'%'..icon if color then s = ""..s..'' end widget:set_markup(spacer..s..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") batteryInfoUpdate("BAT0", true, bat0_widget) batteryInfoUpdate("BAT1", false, bat1_widget) 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: