diff options
| author | Tim Keller <tjk@tjkeller.xyz> | 2024-10-19 00:57:36 -0500 | 
|---|---|---|
| committer | Tim Keller <tjk@tjkeller.xyz> | 2024-10-19 00:57:36 -0500 | 
| commit | d36142293084f6e677427022da56cd9e58f1f15f (patch) | |
| tree | 091b0429836f971403db8afc0f6e9d6b4cd0d41d /widgets | |
| parent | 923eb46350b1102749eb05cd2120c96cc6a715d0 (diff) | |
| download | awesome-d36142293084f6e677427022da56cd9e58f1f15f.tar.xz awesome-d36142293084f6e677427022da56cd9e58f1f15f.zip | |
battery info tooltip
Diffstat (limited to 'widgets')
| -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", { | 
