From cc68c3adcde665ca63ae0873e4dfca8c94a7c9e0 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 19 Oct 2024 19:18:03 -0500 Subject: bat upd --- widgets/battery.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'widgets') diff --git a/widgets/battery.lua b/widgets/battery.lua index 83a7fd0..873f1ba 100644 --- a/widgets/battery.lua +++ b/widgets/battery.lua @@ -2,7 +2,7 @@ local awful = require("awful") local wibox = require("wibox") local naughty = require("naughty") --- tooltip function +-- tooltip text function local tooltip_text_format = [[ %s (%s) Status: %s @@ -16,18 +16,22 @@ Technology: %s Manufacturer: %s Serial Number: %s ]] + function bat_uevents() -- TODO io.popen will stop execution local uevents = io.popen("ls /sys/class/power_supply/*/uevent") local text = "" + -- loop over uevent files for uevent in uevents:lines() do local ueventf = io.open(uevent) - local ueventc = ueventf:read('a') --:gmatch("%d+") + local ueventc = ueventf:read('a') ueventf:close() + -- get attributes local a = {} for k, v in ueventc:gmatch("POWER_SUPPLY_(.-)=%s*(.-)\n") do a[k] = v end + -- add to tooltip text if a.TYPE == "Battery" then local capacity = a.ENERGY_NOW * 100 / a.ENERGY_FULL local health = a.ENERGY_FULL * 100 / a.ENERGY_FULL_DESIGN @@ -50,6 +54,9 @@ function bat_uevents() end end uevents:close() + if text == "" then + return "No Batteries Installed" + end return text end -- cgit v1.2.3