blob: 988f9fa7b5b762375f96ae6d6fd7ef44ca163f68 (
plain)
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
50
51
52
53
|
function batteryInfoUpdate(adapter, warn, widget)
spacer = " "
local fcap = io.open("/sys/class/power_supply/"..adapter.."/capacity")
local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
local cap = fcap:read()
local sta = fsta:read()
fcap:close()
fsta:close()
if sta:match("Charging") then
state = 1
icon = "▴"
else
state = -1
icon = "▾"
end
if tonumber(cap) < 10 and warn then
naughty.notify({ title = "Battery Warning",
text = "Battery "..adapter.." low at "..cap.."%!",
timeout = 15,
position = "top_right",
fg = beautiful.fg_focus,
bg = beautiful.bg_focus,
})
end
if tonumber(cap) < 10 then
color='red'
elseif tonumber(cap) < 25 then
color='orange'
else
color='green'
end
widget:set_markup(spacer.."<span color='"..color.."'>"..icon..cap..'%</span>'..spacer)
end
local wibox = require("wibox")
bat0_widget = wibox.widget.textbox()
bat0_widget:set_align("right")
bat1_widget = wibox.widget.textbox()
bat1_widget:set_align("right")
battery_timer = timer({timeout = 20})
battery_timer:connect_signal("timeout", function()
batteryInfoUpdate("BAT0", true, bat0_widget)
batteryInfoUpdate("BAT1", false, bat1_widget)
end)
battery_timer:start()
-- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1:
|