diff options
-rw-r--r-- | widgets/battery.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/widgets/battery.lua b/widgets/battery.lua index f6e6860..83a7fd0 100644 --- a/widgets/battery.lua +++ b/widgets/battery.lua @@ -2,7 +2,65 @@ local awful = require("awful") local wibox = require("wibox") local naughty = require("naughty") +-- tooltip function +local tooltip_text_format = [[ +<b>%s (%s)</b> +Status: %s +Charge: %.1f%% +Health: %.1f%% +Cycle Count: %d +Rated Capacity: %.0fmAh (%.1fWh) +Voltage Min: %.1fV +Voltage Now: %.1fV +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 = "" + for uevent in uevents:lines() do + local ueventf = io.open(uevent) + local ueventc = ueventf:read('a') --:gmatch("%d+") + ueventf:close() + local a = {} + for k, v in ueventc:gmatch("POWER_SUPPLY_(.-)=%s*(.-)\n") do + a[k] = v + end + if a.TYPE == "Battery" then + local capacity = a.ENERGY_NOW * 100 / a.ENERGY_FULL + local health = a.ENERGY_FULL * 100 / a.ENERGY_FULL_DESIGN + local mah = a.ENERGY_FULL_DESIGN * 1000 / a.VOLTAGE_MIN_DESIGN + text = text .. tooltip_text_format:format( + a.NAME, + a.MODEL_NAME, + a.STATUS, + capacity, + health, + a.CYCLE_COUNT, + mah, + a.ENERGY_FULL_DESIGN / 1000000, + a.VOLTAGE_MIN_DESIGN / 1000000, + a.VOLTAGE_NOW / 1000000, + a.TECHNOLOGY, + a.MANUFACTURER, + a.SERIAL_NUMBER + ) + end + end + uevents:close() + return text +end + +-- vars local widget = wibox.widget.textbox() +local tooltip = awful.tooltip { + objects = {widget}, + delay_show = 1, + timeout = 2, + timer_function = bat_uevents, +} -- update widget on lowbat output local lowbat_pid = awful.spawn.with_line_callback("lowbat", { |