-- TODO: switch to async IO: https://github.com/Elv13/awesome-configs/blob/master/widgets/battery.lua local gears = require("gears") local naughty = require("naughty") local beautiful = require("beautiful") function batteryInfoUpdate(adapters, widget) spacer = " " local total_cur = 0.0 local total_max = 0.0 local status = '' for i = 1, #adapters do local fcap = io.open("/sys/class/power_supply/"..adapters[i].."/capacity") local fsta = io.open("/sys/class/power_supply/"..adapters[i].."/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 status = status .. cap..'%'..icon if i < #adapters then status = status ..',' end total_cur = total_cur + tonumber(cap) total_max = total_max + 1.0 end local cap = total_cur/total_max if cap < 10 then local bg = beautiful.bg_focus local fg = beautiful.fg_focus if cap <= 5 then bg = beautiful.bg_urgent fg = beautiful.fg_urgent end naughty.notify({ title = "Battery Warning", text = "Battery low at "..cap.."%!", timeout = 15, position = "top_right", fg = fg, bg = bg }) end local color=nil if tonumber(cap) < 10 then color='red' elseif tonumber(cap) < 20 then color='orange' end if color then status = ""..status..'' end widget:set_markup(spacer..status..spacer) end local wibox = require("wibox") battery_widget = wibox.widget.textbox() battery_widget:set_align("right") battery_timer = gears.timer({timeout = 20, call_now = true, autostart = true, callback = function() batteryInfoUpdate( {"BAT0", "BAT1"}, battery_widget) end, }) -- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1: