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
|
local MIN_DBM, MAX_DBM = -90, -20
local COLOR_DIM = '#709080'
local function clamp(x, lo, hi)
if x < lo then return lo end
if x > hi then return hi end
return x
end
local function make_wifi_level(dbm)
dbm = clamp(dbm, MIN_DBM, MAX_DBM)
-- Normalize to [0, 1]
local t = (dbm - MIN_DBM) / (MAX_DBM - MIN_DBM)
local level
if t < 0.25 then
level = ''
elseif t < 0.50 then
level = ''
elseif t < 0.75 then
level = ''
else
level = ''
end
return {
full_text = level,
color = COLOR_DIM,
}
end
widget = {
plugin = 'network-linux',
opts = {
wireless = true,
timeout = 10,
},
cb = function(t)
if not t then
return nil
end
local r = {}
for iface, params in pairs(t) do
if params.wireless then
if params.wireless.ssid then
r[#r + 1] = {
full_text = params.wireless.ssid,
color = COLOR_DIM,
}
end
if params.wireless.signal_dbm then
r[#r + 1] = make_wifi_level(params.wireless.signal_dbm)
end
elseif iface ~= 'lo' and (params.ipv4 or params.ipv6) then
r[#r + 1] = {
full_text = string.format('[%s]', iface),
color = COLOR_DIM,
}
end
end
return r
end,
event = [[
local t = ...
if t.button == 1 then
os.execute('~/.local/bin/rofi-wifimenu &')
end
]],
}
|