-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi.lua
74 lines (55 loc) · 1.41 KB
/
wifi.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
local async = awful.spawn.easy_async
local wifi = {
widget = wibox.widget.textbox(),
interface = "",
}
-- Update textbox
local function set_status(text)
if wifi.widget == nil then
return
end
wifi.widget.markup = text
end
-- Show infromation popup
local function info()
-- TODO
end
function wifi.reload()
async("iw "..wifi.interface.." link", function (output)
local ssid = output:match("SSID: ([%w%p ]+)")
if not ssid then ssid = "-" end
local signal = output:match("signal: (%-%d+)")
if not signal then signal = "-" end
local bitrate = output:match("bitrate: (%d+)")
if not bitrate then bitrate = "-" end
local color = beautiful.fg_focus
local text = ""
if ssid ~= "-" then
text = "<span color='"..color.."'>"..ssid.."</span>"
text = text .." / <span color='"..color.."'>"..signal.." dBm</span>"
text = text .." / <span color='"..color.."'>"..bitrate.." mbit/s</span>"
else
text = "<span color='#ff0000'>Wifi off</span>"
end
set_status(text)
end)
end
-- Setup widget
local function init()
async("iw dev", function (output)
local interface = output:match("Interface (%w+)")
if not interface then
wifi.widget = nil
return
end
wifi.interface = interface
wifi.widget:buttons(gears.table.join(
awful.button({ }, 1, function() info() end),
awful.button({ }, 3, function() wifi.reload() end)
))
wifi.reload()
end)
end
init()
return wifi
-- vim:ts=4:sw=4