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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
local naughty = require("naughty")
local beautiful = require("beautiful")
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
icon = "▴"
elseif sta:match("Discharging") then
icon = "▾"
else
icon = "‐"
end
if tonumber(cap) < 10 and warn then
local bg = beautiful.bg_focus
local fg = beautiful.fg_focus
if tonumber(cap) <= 5 then
bg = beautiful.bg_urgent
fg = beautiful.fg_urgent
end
naughty.notify({ title = "Battery Warning",
text = "Battery "..adapter.." low at "..cap.."%!",
timeout = 15,
position = "top_right",
fg = fg,
bg = bg
})
end
local color=nil
if warn then
if tonumber(cap) < 10 then
color='red'
elseif tonumber(cap) < 20 then
color='orange'
end
end
local s = cap..'%'..icon
if color then
s = "<span color='"..color.."'>"..s..'</span>'
end
widget:set_markup(spacer..s..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")
batteryInfoUpdate("BAT0", true, bat0_widget)
batteryInfoUpdate("BAT1", false, bat1_widget)
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:
|