diff options
Diffstat (limited to 'widgets/battery.lua')
| -rw-r--r-- | widgets/battery.lua | 11 | 
1 files changed, 9 insertions, 2 deletions
| 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 = [[  <b>%s (%s)</b>  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 | 
