aboutsummaryrefslogtreecommitdiff
path: root/widgets/bat.lua
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/bat.lua')
-rw-r--r--widgets/bat.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/widgets/bat.lua b/widgets/bat.lua
index 2f93518..cf953a9 100644
--- a/widgets/bat.lua
+++ b/widgets/bat.lua
@@ -10,6 +10,7 @@ local string = { format = string.format }
local helpers = require("vicious.helpers")
local math = {
min = math.min,
+ max = math.max,
floor = math.floor
}
-- }}}
@@ -65,6 +66,7 @@ local function worker(format, warg)
-- Calculate remaining (charging or discharging) time
local time = "N/A"
+
if tonumber(rate) then
if state == "+" then
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
@@ -73,9 +75,11 @@ local function worker(format, warg)
else
return {state, percent, time}
end
+
-- Calculate time (but work around broken BAT/ACPI implementations)
- local hoursleft = math.min(math.floor(timeleft), 0)
- local minutesleft = math.min(math.floor((timeleft - hoursleft) * 60 ), 0)
+ local hoursleft = math.max(math.floor(timeleft), 0)
+ local minutesleft = math.max(math.floor((timeleft - hoursleft) * 60 ), 0)
+
time = string.format("%02d:%02d", hoursleft, minutesleft)
end