Added generic battery widget that uses acpi
This commit is contained in:
parent
40d22733d3
commit
4699f4d592
|
@ -8,35 +8,21 @@ local beautiful = require("beautiful")
|
||||||
|
|
||||||
local previous_percent = 0
|
local previous_percent = 0
|
||||||
|
|
||||||
function batteryInfo(adapter)
|
function batteryInfo()
|
||||||
local fcur = io.open("/sys/class/power_supply/"..adapter.."/energy_now")
|
local fd = io.popen('acpi | cut -d ":" -f 2 | cut -d "," -f 2 | tr -d "%"')
|
||||||
local fcap = io.open("/sys/class/power_supply/"..adapter.."/energy_full")
|
local percentage = fd:read('*all')
|
||||||
local cur = fcur:read()
|
fd:close()
|
||||||
local cap = fcap:read()
|
return tonumber(percentage)
|
||||||
fcur:close()
|
|
||||||
fcap:close()
|
|
||||||
|
|
||||||
local battery = math.floor(cur * 100 / cap)
|
|
||||||
|
|
||||||
if battery > 100 then
|
|
||||||
battery = 100
|
|
||||||
end
|
|
||||||
|
|
||||||
return battery
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function isCharging(adapter)
|
function isCharging()
|
||||||
|
local _,_,error = os.execute('acpi | grep Discharging')
|
||||||
local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
|
return error ~= 0
|
||||||
local sta = fsta:read()
|
|
||||||
fsta:close()
|
|
||||||
return not sta:match("Discharging")
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_battery()
|
function update_battery()
|
||||||
|
|
||||||
local percent = batteryInfo('BAT0')
|
local percent = batteryInfo()
|
||||||
local color
|
local color
|
||||||
local symbol
|
local symbol
|
||||||
|
|
||||||
|
@ -50,7 +36,7 @@ function update_battery()
|
||||||
color="white"
|
color="white"
|
||||||
end
|
end
|
||||||
|
|
||||||
if isCharging('BAT0') then
|
if isCharging() then
|
||||||
color = 'green'
|
color = 'green'
|
||||||
symbol = '⚡'
|
symbol = '⚡'
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue