2023-01-29 02:59:52 -06:00
|
|
|
local awful = require "awful"
|
|
|
|
local xresources = require "beautiful.xresources"
|
2023-03-04 15:04:55 -06:00
|
|
|
local vars = require "misc.vars"
|
2023-01-29 02:59:52 -06:00
|
|
|
local wibox = require "wibox"
|
2023-03-04 15:04:55 -06:00
|
|
|
local h = require "misc.helpers"
|
2023-01-29 02:59:52 -06:00
|
|
|
|
|
|
|
local battery_inner = awful.widget.watch("cat /sys/class/power_supply/BAT0/capacity", 1, function(widget, stdout)
|
|
|
|
local icon = ""
|
|
|
|
local color = vars.colors.red
|
|
|
|
|
|
|
|
if io.popen("cat /sys/class/power_supply/BAT0/status"):read("*a"):sub(0, -2) == "Charging" then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.green
|
|
|
|
widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local percent = tonumber(stdout)
|
|
|
|
|
|
|
|
if percent <= 5 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.red
|
|
|
|
elseif percent <= 10 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.red
|
|
|
|
elseif percent <= 20 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.red
|
|
|
|
elseif percent <= 30 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.yellow
|
|
|
|
elseif percent <= 40 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.yellow
|
|
|
|
elseif percent <= 50 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.yellow
|
|
|
|
elseif percent <= 60 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.yellow
|
|
|
|
elseif percent <= 70 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.yellow
|
|
|
|
elseif percent <= 80 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.green
|
|
|
|
elseif percent <= 90 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.green
|
|
|
|
elseif percent <= 100 then
|
|
|
|
icon = ""
|
|
|
|
color = vars.colors.green
|
|
|
|
end
|
|
|
|
|
|
|
|
widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
|
|
|
|
end)
|
|
|
|
|
|
|
|
local battery = wibox.widget {
|
|
|
|
widget = wibox.container.place,
|
|
|
|
battery_inner
|
|
|
|
}
|
|
|
|
|
2023-03-04 15:04:55 -06:00
|
|
|
h.tooltip({ battery }, function()
|
|
|
|
return io.popen("cat /sys/class/power_supply/BAT0/capacity"):read("*a"):sub(0, -2) .. "%"
|
|
|
|
end)
|
2023-01-29 02:59:52 -06:00
|
|
|
|
|
|
|
return battery
|