-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget-battery.lua
49 lines (47 loc) · 1.8 KB
/
widget-battery.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Create a textbox widget for the battery widget
mybatterywidget = wibox.widget.textbox()
mybatterywidget:set_align("left")
mybatterywidget:set_text(" Battery status ")
function batteryInfo(adapter)
spacer = " "
local fcur = io.open("/sys/class/power_supply/"..adapter.."/energy_now")
local fcap = io.open("/sys/class/power_supply/"..adapter.."/energy_full")
local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
local cur = fcur:read()
local cap = fcap:read()
local sta = fsta:read()
local battery = math.floor(cur * 100 / cap)
if sta:match("Charging") then
dir = "^"
battery = "A/C ("..battery..")"
elseif sta:match("Discharging") then
dir = "v"
if tonumber(battery) > 25 and tonumber(battery) < 75 then
battery = battery
elseif tonumber(battery) < 25 then
if tonumber(battery) < 10 then
naughty.notify({ title = "Battery Warning"
, text = "Battery low!"..spacer..battery.."%"..spacer.."left!"
, timeout = 5
, position = "top_right"
, fg = beautiful.fg_focus
, bg = beautiful.bg_focus
})
end
battery = battery
else
battery = battery
end
else
dir = "="
battery = "A/C"
end
mybatterywidget:set_text(spacer .. "Batterie :" .. spacer ..dir..battery..dir..spacer)
fcur:close()
fcap:close()
fsta:close()
end
-- Timer --
mybatterytimer = timer({ timeout = 30 })
mybatterytimer:connect_signal("timeout", function() batteryInfo('BAT0') end )
mybatterytimer:start()