-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget_fun.lua
78 lines (68 loc) · 2.32 KB
/
widget_fun.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local naughty = require("naughty")
local beautiful = require("beautiful")
local math = require("math")
local pairs = pairs
module("widget_fun")
-- Battery (based on http://awesome.naquadah.org/wiki/Gigamo_Battery_Widget)
local limits = { {25, 5},
{12, 3},
{ 7, 1},
{0}}
local function getnextlim (num)
for ind, pair in pairs(limits) do
lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0
if num > nextlim then
repeat
lim = lim - step
until num > lim
if lim < nextlim then
lim = nextlim
end
return lim
end
end
end
function batclosure ()
local nextlim = limits[1][1]
return function (_, args)
local prefix = "⚡"
local state, charge = args[1], args[2]
if not charge then return end
if state == "−" then
dirsign = "↓"
prefix = "Bat:"
if charge <= nextlim then
naughty.notify({title = "⚡ Lystring! ⚡",
text = "Batteriet har nått låg nivå ( ⚡ "
..charge.."%)!",
timeout = 7,
position = "bottom_right",
fg = beautiful.fg_focus,
bg = beautiful.bg_focus
})
nextlim = getnextlim(charge)
end
elseif state == "+" then
dirsign = "↑"
nextlim = limits[1][1]
else
return " ⚡ "
end
if dir ~= 0 then charge = charge.."%" end
return " "..prefix.." "..dirsign..charge..dirsign.." "
end
end
function watch_temp (thermowidget, args)
local temp = args[1]
if temp > 87 then
naughty.notify({title = "Värmgång i systemet!",
text = "Temperatur är för hög ("..temp.."°C)",
timeout = 3,
position = "bottom_left",
fg = beautiful.fg_focus,
bg = beautiful.bg_focus
})
end
return " "..math.ceil(temp).."°"
end
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80