-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi.lua
88 lines (63 loc) · 1.95 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
local wibox = require("wibox")
local awful = require("awful")
local helpers = require("./helpers")
local widget = {}
-- {{{ Define the adapter
local adapter = "wlan0"
-- Test adapter
widget.haswifi = helpers:test("iwconfig " .. adapter)
-- Try another adapter name
if not widget.haswifi then
adapter = "wlp3s0"
widget.haswifi = helpers:test("iwconfig " .. adapter)
end
-- }}}
-- {{{ Define subwidgets
widget.text = wibox.widget.textbox()
widget.icon = wibox.widget.imagebox()
-- Change the draw method so icons can be drawn smaller
helpers:set_draw_method(widget.icon)
-- }}}
-- {{{ Define interactive behaviour
widget.icon:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.util.spawn("wicd-gtk") end)
))
-- }}}
-- {{{ Update method
function widget:update()
spacer = " "
local f = io.popen("iwconfig " .. adapter)
local wifi = f:read("*all")
local connected = string.match(wifi, "ESSID:\"(%w*)\"")
local wifiMin, wifiMax = string.match(wifi, "(%d?%d)/(%d?%d)")
wifiMin = tonumber(wifiMin) or 0
wifiMax = tonumber(wifiMax) or 70
local quality = math.floor(wifiMin / wifiMax * 100)
local text = quality .. "%"
if connected then
text = text .. " (" .. connected .. ")"
end
widget.text:set_markup(text)
local iconpath = "/home/marc/.config/awesome/themes/current/icons/gnome/scalable/status/network-wireless-signal"
if quality <= 0 then
iconpath = iconpath .. "-none"
elseif quality < 25 then
iconpath = iconpath .. "-weak"
elseif quality < 50 then
iconpath = iconpath .. "-ok"
elseif quality < 75 then
iconpath = iconpath .. "-good"
else
iconpath = iconpath .. "-excellent"
end
iconpath = iconpath .. "-symbolic.svg"
widget.icon:set_image(iconpath)
f:close()
end
-- }}}
-- {{{ Listen if signal was found
if widget.haswifi then
helpers:listen(widget)
end
-- }}}
return widget;