diff options
Diffstat (limited to 'awesome/net_widgets')
-rw-r--r-- | awesome/net_widgets/icons/wired.png | bin | 0 -> 186 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wired_na.png | bin | 0 -> 186 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wireless_0.png | bin | 0 -> 420 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wireless_1.png | bin | 0 -> 251 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wireless_2.png | bin | 0 -> 251 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wireless_3.png | bin | 0 -> 222 bytes | |||
-rw-r--r-- | awesome/net_widgets/icons/wireless_na.png | bin | 0 -> 178 bytes | |||
-rw-r--r-- | awesome/net_widgets/indicator.lua | 87 | ||||
-rw-r--r-- | awesome/net_widgets/init.lua | 8 | ||||
-rw-r--r-- | awesome/net_widgets/wireless.lua | 121 |
10 files changed, 216 insertions, 0 deletions
diff --git a/awesome/net_widgets/icons/wired.png b/awesome/net_widgets/icons/wired.png Binary files differnew file mode 100644 index 0000000..af47696 --- /dev/null +++ b/awesome/net_widgets/icons/wired.png diff --git a/awesome/net_widgets/icons/wired_na.png b/awesome/net_widgets/icons/wired_na.png Binary files differnew file mode 100644 index 0000000..9314217 --- /dev/null +++ b/awesome/net_widgets/icons/wired_na.png diff --git a/awesome/net_widgets/icons/wireless_0.png b/awesome/net_widgets/icons/wireless_0.png Binary files differnew file mode 100644 index 0000000..ef42a4a --- /dev/null +++ b/awesome/net_widgets/icons/wireless_0.png diff --git a/awesome/net_widgets/icons/wireless_1.png b/awesome/net_widgets/icons/wireless_1.png Binary files differnew file mode 100644 index 0000000..8b64b8f --- /dev/null +++ b/awesome/net_widgets/icons/wireless_1.png diff --git a/awesome/net_widgets/icons/wireless_2.png b/awesome/net_widgets/icons/wireless_2.png Binary files differnew file mode 100644 index 0000000..bd9d163 --- /dev/null +++ b/awesome/net_widgets/icons/wireless_2.png diff --git a/awesome/net_widgets/icons/wireless_3.png b/awesome/net_widgets/icons/wireless_3.png Binary files differnew file mode 100644 index 0000000..6cb0ed1 --- /dev/null +++ b/awesome/net_widgets/icons/wireless_3.png diff --git a/awesome/net_widgets/icons/wireless_na.png b/awesome/net_widgets/icons/wireless_na.png Binary files differnew file mode 100644 index 0000000..712a032 --- /dev/null +++ b/awesome/net_widgets/icons/wireless_na.png diff --git a/awesome/net_widgets/indicator.lua b/awesome/net_widgets/indicator.lua new file mode 100644 index 0000000..3e9ba33 --- /dev/null +++ b/awesome/net_widgets/indicator.lua @@ -0,0 +1,87 @@ +local wibox = require("wibox") +local awful = require("awful") +local beautiful = require("beautiful") +local naughty = require("naughty") + +local indicator = {} +local function worker(args) + local args = args or {} + local widget = wibox.widget.imagebox() + + local interfaces = args.interfaces or {"enp2s0"} + local ICON_DIR = awful.util.getdir("config").."/net_widgets/icons/" + local timeout = args.timeout or 5 + local font = args.font or beautiful.font + + local connected = false + local function text_grabber() + local msg = "" + if connected then + for _, i in pairs(interfaces) do + f = io.popen("ifconfig "..i) + + line = f:read() -- wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 + line = f:read() -- inet 192.168.1.15 netmask 255.255.255.0 broadcast 192.168.1.255 + inet = string.match(line, "inet (%d+%.%d+%.%d+%.%d+)") or " N/A " + line = f:read() -- ether 50:b7:c3:08:37:b7 txqueuelen 1000 (Ethernet) + mac = string.match(line, "(%x*:%x*:%x*:%x*:%x*:%x*)") or "N/A" + + f:close() + msg = "<span font_desc=\""..font.."\">".. + "┌["..i.."]\n".. + "├IP:\t"..inet.."\n".. + "└MAC:\t"..mac.."</span>" + end + else + msg = "<span font_desc=\""..font.."\">Wired network is disconnected</span>" + end + + return msg + end + + + widget:set_image(ICON_DIR.."wired_na.png") + local function net_update() + connected = false + for _, i in pairs(interfaces) do + state = awful.util.pread("ip link show "..i.." | awk 'NR==1 {printf \"%s\", $9}'") + if (state == "UP") then + connected = true + end + if connected then + widget:set_image(ICON_DIR.."wired.png") + else + widget:set_image(ICON_DIR.."wired_na.png") + end + end + end + + net_update() + + local net_timer = timer({ timeout = timeout }) + net_timer:connect_signal("timeout", net_update) + net_timer:start() + + local notification = nil + function widget:hide() + if notification ~= nil then + naughty.destroy(notification) + notification = nil + end + end + + function widget:show(t_out) + widget:hide() + + notification = naughty.notify({ + preset = fs_notification_preset, + text = text_grabber(), + timeout = t_out, + }) + end + + widget:connect_signal('mouse::enter', function () widget:show(0) end) + widget:connect_signal('mouse::leave', function () widget:hide() end) + return widget +end +return setmetatable(indicator, {__call = function(_,...) return worker(...) end}) diff --git a/awesome/net_widgets/init.lua b/awesome/net_widgets/init.lua new file mode 100644 index 0000000..83cd5e5 --- /dev/null +++ b/awesome/net_widgets/init.lua @@ -0,0 +1,8 @@ +package.loaded.net_widgets = nil + +local net_widgets = { + indicator = require("net_widgets.indicator"), + wireless = require("net_widgets.wireless") +} + +return net_widgets diff --git a/awesome/net_widgets/wireless.lua b/awesome/net_widgets/wireless.lua new file mode 100644 index 0000000..627274a --- /dev/null +++ b/awesome/net_widgets/wireless.lua @@ -0,0 +1,121 @@ +local wibox = require("wibox") +local awful = require("awful") +local beautiful = require("beautiful") +local naughty = require("naughty") + +local wireless = {} +local function worker(args) + local args = args or {} + + local widget = wibox.layout.fixed.horizontal() + local connected = false + + -- Settings + local ICON_DIR = awful.util.getdir("config").."/net_widgets/icons/" + local interface = args.interface or "wlan0" + local timeout = args.timeout or 5 + local font = args.font or beautiful.font + local popup_signal = args.popup_signal or false + + local net_icon = wibox.widget.imagebox() + net_icon:set_image(ICON_DIR.."wireless_na.png") + local net_text = wibox.widget.textbox() + net_text:set_text(" N/A ") + local net_timer = timer({ timeout = timeout }) + local signal_level = 0 + local function net_update() + signal_level = tonumber(awful.util.pread("awk 'NR==3 {printf \"%3.0f\" ,($3/70)*100}' /proc/net/wireless")) + if signal_level == nil then + connected = false + net_text:set_text(" N/A ") + net_icon:set_image(ICON_DIR.."wireless_na.png") + else + connected = true + net_text:set_text(string.format("%3d%%", signal_level)) + if signal_level < 25 then + net_icon:set_image(ICON_DIR.."wireless_0.png") + elseif signal_level < 50 then + net_icon:set_image(ICON_DIR.."wireless_1.png") + elseif signal_level < 75 then + net_icon:set_image(ICON_DIR.."wireless_2.png") + else + net_icon:set_image(ICON_DIR.."wireless_3.png") + end + end + end + + net_update() + net_timer:connect_signal("timeout", net_update) + net_timer:start() + + widget:add(net_icon) + -- Hide the text when we want to popup the signal instead + if not popup_signal then + widget:add(net_text) + end + + local function text_grabber() + local msg = "" + if connected then + f = io.popen("iwconfig "..interface) + line = f:read() or "" -- wlp1s0 IEEE 802.11abgn ESSID:"ESSID" + essid = string.match(line, "ESSID:\"(.+)\"") or " N/A " + line = f:read() or "" -- Mode:Managed Frequency:2.437 GHz Access Point: aa:bb:cc:dd:ee:ff + mac = string.match(line, "Access Point: (.+)") or " N/A " + line = f:read() or "" -- Bit Rate=36 Mb/s Tx-Power=15 dBm + bitrate = string.match(line, "Bit Rate=(.+/s)") or " N/A " + + f:close() + f = io.popen("ifconfig "..interface) + + line = f:read() or "" -- wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 + line = f:read() or "" -- inet 192.168.1.15 netmask 255.255.255.0 broadcast 192.168.1.255 + inet = string.match(line, "inet (%d+%.%d+%.%d+%.%d+)") or " N/A " + + f:close() + + signal = "" + if popup_signal then + signal = "├Strength\t"..signal_level.."\n" + end + msg = + "<span font_desc=\""..font.."\">".. + ""..interface.."\n".. + "├─ESSID:\t"..essid.."\n".. + "├─IP:\t\t"..inet.."\n".. + "├─BSSID:\t"..mac.."\n".. + ""..signal.. + "└─Bit rate:\t"..bitrate.."</span>" + + + else + msg = "Wireless network is disconnected" + end + + return msg + end + + local notification = nil + function widget:hide() + if notification ~= nil then + naughty.destroy(notification) + notification = nil + end + end + + function widget:show(t_out) + widget:hide() + + notification = naughty.notify({ + preset = fs_notification_preset, + text = text_grabber(), + timeout = t_out, + }) + end + + widget:connect_signal('mouse::enter', function () widget:show(0) end) + widget:connect_signal('mouse::leave', function () widget:hide() end) + return widget +end + +return setmetatable(wireless, {__call = function(_,...) return worker(...) end}) |