From: aajjbb Date: Tue, 17 May 2016 01:19:26 +0000 (-0300) Subject: fixing battery percentage going above 100 X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/726bf16543bd5a0e949aed7e59f9f4b967fdf123?hp=-c fixing battery percentage going above 100 --- 726bf16543bd5a0e949aed7e59f9f4b967fdf123 diff --git a/widgets/bat.lua b/widgets/bat.lua index 152fa12..43b7a5f 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -13,7 +13,7 @@ local first_line = require("lain.helpers").first_line local naughty = require("naughty") local wibox = require("wibox") -local math = { floor = math.floor } +local math = { floor = math.floor, min = math.min } local string = { format = string.format } local tonumber = tonumber @@ -98,7 +98,7 @@ local function worker(args) local minutes = math.floor((rate_time - hours) * 60) local watt = rate_power and (rate_power / 1e6) or (rate_voltage * rate_current) / 1e12 - bat_now.perc = string.format("%d", energy_percentage) + bat_now.perc = string.format("%d", math.min(100, energy_percentage)) bat_now.time = string.format("%02d:%02d", hours, minutes) bat_now.watt = string.format("%.2fW", watt) end