diff --git a/home/.config/awesome/icons/vpn.png b/home/.config/awesome/icons/vpn.png new file mode 100644 index 0000000..ee285ff Binary files /dev/null and b/home/.config/awesome/icons/vpn.png differ diff --git a/home/.config/awesome/rc.lua b/home/.config/awesome/rc.lua index c2f2510..9b1f4eb 100644 --- a/home/.config/awesome/rc.lua +++ b/home/.config/awesome/rc.lua @@ -206,6 +206,8 @@ awful.screen.connect_for_each_screen(function(s) widgets.tearstop, widgets.redshift, widgets.bluetooth, + widgets.vpn.icon, + widgets.vpn.widget, widgets.netdown_icon, widgets.netdown.widget, widgets.netup_icon, diff --git a/home/.config/awesome/widgets.lua b/home/.config/awesome/widgets.lua index 766c64c..35545b3 100644 --- a/home/.config/awesome/widgets.lua +++ b/home/.config/awesome/widgets.lua @@ -66,6 +66,30 @@ widgets.bat = lain.widget.bat({ end }) +widgets.vpn = {} +widgets.vpn.icon = wibox.widget.imagebox(iconsdir .. "vpn.png") +widgets.vpn.widget = wibox.widget.textbox() +widgets.vpn.update = function() + helpers.async({ "/bin/ip", "link" }, function(output) + connected = false + for line in output:gmatch("[^\r\n]+") do + vpn_server = string.match(line, "^%d+: mullvad%-(%a%a%d+):") + if vpn_server then + widgets.vpn.widget:set_markup(markup.fontfg(theme.font, theme.colors.blue, vpn_server .. " ")) + connected = true + end + end + + if connected then + widgets.vpn.icon.visible = true + else + widgets.vpn.widget:set_markup(markup.fontfg(theme.font, theme.colors.blue, "")) + widgets.vpn.icon.visible = false + end + end) +end +helpers.newtimer("vpn", 5, widgets.vpn.update) + widgets.bluetooth = wibox.widget.imagebox(iconsdir .. "bluetooth-on.png") widgets.bluetooth.pass_state = function(callback) helpers.async_with_shell("/sbin/rfkill -n -o SOFT list bluetooth|uniq", function(state)