aboutsummaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2011-11-20 17:44:04 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2011-11-20 17:44:04 +0100
commit45c6ebaeb685ba4ed402353ec3de95719d0c6a7e (patch)
tree220a7f05f4a75d7e0a0e6d98c69a74642fd2e002 /widgets
parentcd4b04df44023f9c81885978522f337763dcf7a9 (diff)
downloadvicious-legacy-45c6ebaeb685ba4ed402353ec3de95719d0c6a7e.tar.xz
bat: fix time calculation, bug introduced in 350e924
Diffstat (limited to 'widgets')
-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