aboutsummaryrefslogtreecommitdiff
path: root/bat.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-15 23:11:36 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-10-15 23:11:36 +0200
commit4d1af1e5ade06242c4a7580446781c9ab2b0f2fa (patch)
tree9386b3216698a504e27bccdab3d4ff87c908ef63 /bat.lua
parent2cfdd5aac7acd54591a7305c364eba9219fad04f (diff)
downloadvicious-legacy-4d1af1e5ade06242c4a7580446781c9ab2b0f2fa.tar.xz
bat: better fix for ACPI, from bioe007
Previous commit had redudant string > number conversions, and only covered one scenario - when battery is charged. bioe007 suggested to use math.min. Now lets explain why this is needed. Some (lousy) batteries report "remaining capacity" higher than "last full capacity" when AC is connected. That leads to battery charges like "160%".
Diffstat (limited to 'bat.lua')
-rw-r--r--bat.lua13
1 files changed, 6 insertions, 7 deletions
diff --git a/bat.lua b/bat.lua
index 6a759e9..3088ad1 100644
--- a/bat.lua
+++ b/bat.lua
@@ -7,7 +7,10 @@
local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable
-local math = { floor = math.floor }
+local math = {
+ min = math.min,
+ floor = math.floor
+}
local string = {
find = string.find,
match = string.match,
@@ -60,12 +63,8 @@ local function worker(format, batid)
local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
- -- Calculate percentage
- local percent = math.floor(remaining / capacity * 100)
- local percent = string.format("%02d", percent)
- -- Work around broken batteries and/or ACPI implementations
- if state == "↯" and tonumber(percent) > 100 then percent = 100 end
-
+ -- Calculate percentage (but work around broken BAT/ACPI implementations)
+ local percent = math.min(math.floor(remaining / capacity * 100), 100)
-- Calculate remaining (charging or discharging) time
if state == "+" then