some work on the network manager
This commit is contained in:
BIN
awesome/src/assets/icons/ArchLogo.png
Normal file
BIN
awesome/src/assets/icons/ArchLogo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 305 KiB After Width: | Height: | Size: 310 KiB |
Submodule awesome/src/lib/dbus_proxy deleted from c9253bde3f
1
awesome/src/lib/lua-dbus_proxy
Submodule
1
awesome/src/lib/lua-dbus_proxy
Submodule
Submodule awesome/src/lib/lua-dbus_proxy added at 011306f859
@@ -19,7 +19,7 @@ return function(s)
|
||||
elseif widget == "Clock" then
|
||||
table.insert(widget_table, require("src.widgets.clock")())
|
||||
elseif widget == "Cpu Frequency" then
|
||||
table.insert(widget_table, require("src.widgets.cpu_info")("freq", User_config.cpu_frequency))
|
||||
table.insert(widget_table, require("src.widgets.cpu_info")("freq"))
|
||||
elseif widget == "Cpu Temperature" then
|
||||
table.insert(widget_table, require("src.widgets.cpu_info")("temp"))
|
||||
elseif widget == "Cpu Usage" then
|
||||
@@ -35,7 +35,7 @@ return function(s)
|
||||
elseif widget == "Tiling Layout" then
|
||||
table.insert(widget_table, require("src.widgets.layout_list")())
|
||||
elseif widget == "Network" then
|
||||
table.insert(widget_table, require("src.widgets.network")())
|
||||
table.insert(widget_table, require("src.widgets.network") { screen = s })
|
||||
elseif widget == "Power Button" then
|
||||
table.insert(widget_table, require("src.widgets.power")())
|
||||
elseif widget == "Ram Usage" then
|
||||
|
||||
@@ -55,7 +55,6 @@ return function(s, w)
|
||||
bg = Theme_config.right_bar.bg,
|
||||
visible = true,
|
||||
screen = s,
|
||||
maximum_width = dpi(650),
|
||||
placement = function(c) awful.placement.top_right(c, { margins = dpi(10) }) end
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ awful.screen.connect_for_each_screen(function(s)
|
||||
require("src.modules.notification-center.init")(s)
|
||||
require("src.modules.window_switcher.init")(s)
|
||||
require("src.modules.application_launcher.init") { screen = s }
|
||||
require("src.modules.network_controller.init") { screen = s }
|
||||
--require("src.modules.network_controller.init") { screen = s }
|
||||
end)
|
||||
|
||||
do
|
||||
|
||||
@@ -102,7 +102,7 @@ function access_point:create_profile(ap, password, auto_connect)
|
||||
}
|
||||
end
|
||||
|
||||
function access_point:disconnect_ap()
|
||||
function access_point:disconnect()
|
||||
self.NetworkManager:DeactivateConnection(self.NetworkManagerDevice.ActiveConnection)
|
||||
end
|
||||
|
||||
@@ -137,16 +137,16 @@ function access_point:connect(ap, password, auto_connect)
|
||||
end
|
||||
end
|
||||
|
||||
function access_point:toggle_access_point(ap, password, auto_connect)
|
||||
function access_point:toggle_connection(ap, password, auto_connect)
|
||||
if self:is_ap_active(ap) then
|
||||
self:disconnect_ap()
|
||||
self:disconnect()
|
||||
else
|
||||
self:connect_ap(ap, password, auto_connect)
|
||||
self:connect(ap, password, auto_connect)
|
||||
end
|
||||
end
|
||||
|
||||
function access_point:is_ap_active(ap)
|
||||
return ap.path == self.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
return ap.object_path == self.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
end
|
||||
|
||||
function access_point.new(args)
|
||||
@@ -154,14 +154,6 @@ function access_point.new(args)
|
||||
|
||||
if not args.NetworkManagerAccessPoint then return end
|
||||
|
||||
local bg, fg, icon_color = Theme_config.network_manager.access_point.bg, Theme_config.network_manager.access_point.fg,
|
||||
Theme_config.network_manager.access_point.icon_color
|
||||
|
||||
--[[ if get_active_access_point() == args.NetworkManagerAccessPoint.access_point_path then
|
||||
bg, fg, icon_color = Theme_config.network_manager.access_point.fg, Theme_config.network_manager.access_point.bg,
|
||||
Theme_config.network_manager.access_point.icon_color2
|
||||
end ]]
|
||||
|
||||
local ssid_text = awidget.inputbox {
|
||||
text = NM.utils_ssid_to_utf8(args.NetworkManagerAccessPoint.Ssid) or
|
||||
args.NetworkManagerAccessPoint.hw_address or "Unknown",
|
||||
@@ -177,7 +169,7 @@ function access_point.new(args)
|
||||
{
|
||||
image = gcolor.recolor_image(
|
||||
icondir .. "wifi-strength-" .. math.floor(args.NetworkManagerAccessPoint.Strength / 25) + 1 .. ".svg",
|
||||
icon_color),
|
||||
Theme_config.network_manager.access_point.icon_color),
|
||||
id = "icon",
|
||||
resize = true,
|
||||
valign = "center",
|
||||
@@ -245,8 +237,8 @@ function access_point.new(args)
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
bg = bg,
|
||||
fg = fg,
|
||||
bg = Theme_config.network_manager.access_point.bg,
|
||||
fg = Theme_config.network_manager.access_point.fg,
|
||||
border_color = Theme_config.network_manager.access_point.border_color,
|
||||
border_width = Theme_config.network_manager.access_point.border_width,
|
||||
id = "background",
|
||||
@@ -262,6 +254,47 @@ function access_point.new(args)
|
||||
ret.NetworkManagerDevice = args.NetworkManagerDevice
|
||||
ret.NetworkManager = args.NetworkManager
|
||||
|
||||
ret.NetworkManagerAccessPointProperties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = ret.NetworkManagerAccessPoint.object_path,
|
||||
}
|
||||
|
||||
-- Update the access point strength
|
||||
ret.NetworkManagerAccessPointProperties:connect_signal(function(_, properties, data)
|
||||
if data.Strength then
|
||||
awesome.emit_signal("NM::AccessPointStrength", data.Strength)
|
||||
if ret.is_ap_active(ret.NetworkManagerAccessPoint.object_path) then
|
||||
ret:get_children_by_id("icon")[1].image = gcolor.recolor_image(
|
||||
icondir .. "wifi-strength-" .. math.floor(data.Strength / 25) + 1 .. ".svg",
|
||||
Theme_config.network_manager.access_point.icon_color2)
|
||||
else
|
||||
ret:get_children_by_id("icon")[1].image = gcolor.recolor_image(
|
||||
icondir .. "wifi-strength-" .. math.floor(data.Strength / 25) + 1 .. ".svg",
|
||||
Theme_config.network_manager.access_point.icon_color)
|
||||
end
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
if ret:is_ap_active(ret.NetworkManagerAccessPoint) then
|
||||
ret.bg = Theme_config.network_manager.access_point.fg
|
||||
ret.fg = Theme_config.network_manager.access_point.bg
|
||||
ret:get_children_by_id("icon")[1].image = gcolor.recolor_image(
|
||||
icondir .. "wifi-strength-" .. math.floor(ret.NetworkManagerAccessPoint.Strength / 25) + 1 .. ".svg",
|
||||
Theme_config.network_manager.access_point.icon_color2)
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(
|
||||
icondir .. "link.svg", Theme_config.network_manager.access_point.icon_color2)
|
||||
else
|
||||
ret.bg = Theme_config.network_manager.access_point.bg
|
||||
ret.fg = Theme_config.network_manager.access_point.fg
|
||||
ret:get_children_by_id("icon")[1].image = gcolor.recolor_image(
|
||||
icondir .. "wifi-strength-" .. math.floor(ret.NetworkManagerAccessPoint.Strength / 25) + 1 .. ".svg",
|
||||
Theme_config.network_manager.access_point.icon_color)
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(
|
||||
icondir .. "link.svg", Theme_config.network_manager.access_point.icon_color)
|
||||
end
|
||||
|
||||
ret.ap_form = ap_form {
|
||||
screen = args.screen,
|
||||
NetworkManagerAccessPoint = args.NetworkManagerAccessPoint,
|
||||
@@ -305,27 +338,9 @@ function access_point.new(args)
|
||||
icondir .. "link.svg",
|
||||
Theme_config.network_manager.access_point.icon_color),
|
||||
callback = function()
|
||||
ret:toggle_access_point()
|
||||
ret:toggle_connection(ret.NetworkManagerAccessPoint)
|
||||
end,
|
||||
id = "connected"
|
||||
},
|
||||
{ -- Rename a device
|
||||
name = "Rename",
|
||||
icon = gcolor.recolor_image(icondir .. "edit.svg", Theme_config.network_manager.icon_color),
|
||||
callback = function()
|
||||
ssid_text:focus()
|
||||
ssid_text:connect_signal("submit", function(text)
|
||||
text = text:get_text()
|
||||
ssid_text.markup = ret:rename(text)
|
||||
end)
|
||||
end
|
||||
},
|
||||
{ -- Remove a device
|
||||
name = "Remove",
|
||||
icon = gcolor.recolor_image(icondir .. "delete.svg", Theme_config.network_manager.icon_color),
|
||||
callback = function()
|
||||
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,8 +348,11 @@ function access_point.new(args)
|
||||
ret:buttons(gtable.join(
|
||||
abutton({}, 1, nil,
|
||||
function()
|
||||
--TODO:Check if there are any connection details, else open the popup
|
||||
ret.ap_form:popup_toggle()
|
||||
if ret:is_ap_active(ret.NetworkManagerAccessPoint) then
|
||||
ret:disconnect()
|
||||
else
|
||||
ret.ap_form:popup_toggle()
|
||||
end
|
||||
end
|
||||
),
|
||||
abutton({}, 3, nil,
|
||||
@@ -344,9 +362,6 @@ function access_point.new(args)
|
||||
)
|
||||
))
|
||||
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(
|
||||
icondir .. "link.svg", icon_color)
|
||||
|
||||
Hover_signal(ret)
|
||||
|
||||
return ret
|
||||
|
||||
@@ -3,25 +3,28 @@
|
||||
------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local abutton = require("awful.button")
|
||||
local base = require("wibox.widget.base")
|
||||
local dbus_proxy = require("src.lib.lua-dbus_proxy.src.dbus_proxy")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gtable = require("gears").table
|
||||
local gtimer = require("gears").timer
|
||||
local gshape = require("gears").shape
|
||||
local gcolor = require("gears").color
|
||||
local gears = require("gears")
|
||||
local gcolor = require("gears.color")
|
||||
local gfilesystem = require("gears.filesystem")
|
||||
local gshape = require("gears.shape")
|
||||
local gtable = require("gears.table")
|
||||
local gtimer = require("gears.timer")
|
||||
local lgi = require("lgi")
|
||||
local NM = lgi.NM
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
local NM = require("lgi").NM
|
||||
local base = require("wibox.widget.base")
|
||||
|
||||
-- Third party libs
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
-- Local libs
|
||||
local access_point = require("src.modules.network_controller.access_point")
|
||||
local dnd_widget = require("awful.widget.toggle_widget")
|
||||
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/network/"
|
||||
local icondir = gfilesystem.get_configuration_dir() .. "src/assets/icons/network/"
|
||||
|
||||
local network = { mt = {} }
|
||||
|
||||
@@ -57,10 +60,17 @@ network.DeviceState = {
|
||||
FAILED = 120
|
||||
}
|
||||
|
||||
function network:get_wifi_proxy()
|
||||
---Get the wifi and or ethernet proxy and connect to their PropertiesChanged signal
|
||||
-- The signals will return the following
|
||||
-- wifi: { "Bitrate", "Strength" }
|
||||
-- ethernet: { "Carrier", "Speed" }
|
||||
function network:get_active_device()
|
||||
--Get all devices
|
||||
local devices = self._private.NetworkManager:GetDevices()
|
||||
if (not devices) or (#devices == 0) then return end
|
||||
-- Loop trough every found device
|
||||
for _, path in ipairs(devices) do
|
||||
--Create a new proxy for every device
|
||||
local NetworkManagerDevice = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
@@ -68,67 +78,108 @@ function network:get_wifi_proxy()
|
||||
path = path
|
||||
}
|
||||
|
||||
if NetworkManagerDevice.DeviceType == network.DeviceType.WIFI then
|
||||
--Check if the device is either a wifi or ethernet device, and if its activated
|
||||
-- if its activated then its currently in use
|
||||
if (NetworkManagerDevice.DeviceType == network.DeviceType.WIFI) and
|
||||
(NetworkManagerDevice.State == network.DeviceState.ACTIVATED) then
|
||||
-- Set the wifi device as the main device
|
||||
self._private.NetworkManagerDevice = NetworkManagerDevice
|
||||
--New wifi proxy to check the bitrate
|
||||
self._private.NetworkManagerDeviceWireless = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Device.Wireless",
|
||||
path = path
|
||||
}
|
||||
-- Watch PropertiesChanged and update the bitrate
|
||||
local NetworkManagerDeviceWirelessProperties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = self._private.NetworkManagerDeviceWireless.object_path
|
||||
}
|
||||
|
||||
self._private.NetworkManagerDevice:connect_signal(function(proxy, new_state, old_state, reason)
|
||||
NetworkManagerDeviceWirelessProperties:connect_signal(function(_, properties, data)
|
||||
if data.Bitrate then
|
||||
self:emit_signal("NM::Bitrate", data.Bitrate)
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
-- Watch the StateChanged signal, update and notify when a new AP is connected
|
||||
self._private.NetworkManagerDevice:connect_signal(function(proxy, new_state)
|
||||
local NetworkManagerAccessPoint = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = self._private.wifi_proxy.ActiveAccessPoint
|
||||
path = self._private.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
}
|
||||
|
||||
self:emit_signal(tostring(NetworkManagerAccessPoint.HwAddress) .. "::state", new_state, old_state)
|
||||
if new_state == network.DeviceState.ACTIVATED then
|
||||
local ssid = NM.utils_ssid_to_utf8(NetworkManagerAccessPoint.Ssid)
|
||||
self:emit_signal("NM::AccessPointConnected", ssid, NetworkManagerAccessPoint.Strength)
|
||||
print("AP Connected: ", ssid, NetworkManagerAccessPoint.Strength)
|
||||
end
|
||||
end, "StateChanged")
|
||||
|
||||
elseif (NetworkManagerDevice.DeviceType == network.DeviceType.ETHERNET) and
|
||||
(NetworkManagerDevice.State == network.DeviceState.ACTIVATED) then
|
||||
-- Create a new ethernet device and set it as the active device
|
||||
self._private.NetworkManagerDevice = NetworkManagerDevice
|
||||
self._private.NetworkManagerDeviceWired = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Device.Wired",
|
||||
path = path
|
||||
}
|
||||
|
||||
local NetworkManagerDeviceWiredProperties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = self._private.NetworkManagerDeviceWired.object_path
|
||||
}
|
||||
|
||||
-- Watch the PropertiesChanged signal and update the speed and carrier
|
||||
NetworkManagerDeviceWiredProperties:connect_signal(function(_, properties, data)
|
||||
if data.Speed then
|
||||
print(data.Speed)
|
||||
self:emit_signal("NM::Speed", data.Speed)
|
||||
elseif data.Carrier then
|
||||
print(data.Carrier)
|
||||
self:emit_signal("NM::Carrier", data.Carrier)
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
-- Connect to the StateChanged signal and notify when the wired connection is ready
|
||||
self._private.NetworkManagerDevice:connect_signal(function(proxy, new_state)
|
||||
if new_state == network.DeviceState.ACTIVATED then
|
||||
self:emit_signal("NM::EthernetActive")
|
||||
print("Ethernet active")
|
||||
end
|
||||
end, "StateChanged")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function network.device_state_to_string(state)
|
||||
local device_state_to_string = {
|
||||
[0] = "Unknown",
|
||||
[10] = "Unmanaged",
|
||||
[20] = "Unavailable",
|
||||
[30] = "Disconnected",
|
||||
[40] = "Prepare",
|
||||
[50] = "Config",
|
||||
[60] = "Need Auth",
|
||||
[70] = "IP Config",
|
||||
[80] = "IP Check",
|
||||
[90] = "Secondaries",
|
||||
[100] = "Activated",
|
||||
[110] = "Deactivated",
|
||||
[120] = "Failed"
|
||||
}
|
||||
|
||||
return device_state_to_string[state]
|
||||
end
|
||||
|
||||
---Scan for access points and create a widget for each one.
|
||||
function network:scan_access_points()
|
||||
if not self._private.NetworkManagerDeviceWireless then return end
|
||||
local ap_list = self:get_children_by_id("wifi_ap_list")[1]
|
||||
ap_list:reset()
|
||||
self._private.NetworkManagerDeviceWireless:RequestScanAsync(function(proxy, context, success, failure)
|
||||
local ap_table = {}
|
||||
self._private.NetworkManagerDeviceWireless:RequestScanAsync(function(_, _, _, failure)
|
||||
if failure then
|
||||
naughty.notification {
|
||||
app_icon = icondir .. "ethernet.svg",
|
||||
app_name = "Network Manager",
|
||||
title = "Error: Scan failed!",
|
||||
message = "Failed to scan for access points.\n" .. failure,
|
||||
icon = gcolor.recolor_image(icondir .. "ethernet.svg", Theme_config.network.icon_color),
|
||||
timeout = 5,
|
||||
}
|
||||
return
|
||||
end
|
||||
|
||||
-- Get every access point even those who hide their ssid
|
||||
for _, ap in ipairs(self._private.NetworkManagerDeviceWireless:GetAllAccessPoints()) do
|
||||
|
||||
-- Create a new proxy for every ap
|
||||
local NetworkManagerAccessPoint = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
@@ -138,34 +189,42 @@ function network:scan_access_points()
|
||||
}
|
||||
|
||||
-- We are only interested in those with a ssid
|
||||
if NetworkManagerAccessPoint.Ssid then
|
||||
ap_list:add(access_point {
|
||||
NetworkManagerAccessPoint = NetworkManagerAccessPoint,
|
||||
NetworkManagerDevice = self._private.NetworkManagerDevice,
|
||||
NetworkManagerSettings = self._private.NetworkManagerSettings,
|
||||
NetworkManager = self._private.NetworkManager,
|
||||
NetworkManagerDeviceWireless = self._private.NetworkManagerDeviceWireless
|
||||
})
|
||||
if NM.utils_ssid_to_utf8(NetworkManagerAccessPoint.Ssid) and NetworkManagerAccessPoint.Strength then
|
||||
if (ap_table[NetworkManagerAccessPoint.Ssid] == nil) or
|
||||
NetworkManagerAccessPoint.Strength > ap_table[NetworkManagerAccessPoint.Ssid].Strength then
|
||||
ap_table[NetworkManagerAccessPoint.Ssid] = NetworkManagerAccessPoint
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(ap_list, function(a, b)
|
||||
return a.NetworkManagerAccessPoint.Strength > b.NetworkManagerAccessPoint.Strength
|
||||
--sort ap_table first by strength
|
||||
local sorted_ap_table = {}
|
||||
for _, NetworkManagerAccessPoint in pairs(ap_table) do
|
||||
table.insert(sorted_ap_table, NetworkManagerAccessPoint)
|
||||
end
|
||||
--sort the table by strength but have the active_ap at the top
|
||||
table.sort(sorted_ap_table, function(a, b)
|
||||
if a.object_path == self._private.NetworkManagerDeviceWireless.ActiveAccessPoint then
|
||||
return true
|
||||
else
|
||||
return a.Strength > b.Strength
|
||||
end
|
||||
end)
|
||||
for _, NetworkManagerAccessPoint in ipairs(sorted_ap_table) do
|
||||
ap_list:add(access_point {
|
||||
NetworkManagerAccessPoint = NetworkManagerAccessPoint,
|
||||
NetworkManagerDevice = self._private.NetworkManagerDevice,
|
||||
NetworkManagerSettings = self._private.NetworkManagerSettings,
|
||||
NetworkManager = self._private.NetworkManager,
|
||||
NetworkManagerDeviceWireless = self._private.NetworkManagerDeviceWireless
|
||||
})
|
||||
end
|
||||
end, { call_id = "my-id" }, {})
|
||||
end
|
||||
|
||||
function network:is_ap_active(ap)
|
||||
return ap.path == self._private.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
end
|
||||
|
||||
---Toggles networking on or off
|
||||
function network:toggle_wifi()
|
||||
local enable = not self._private.NetworkManager.WirelessEnabled
|
||||
if enable then
|
||||
self._private.NetworkManager.Enable(true)
|
||||
end
|
||||
|
||||
self._private.NetworkManager:Set("org.freedesktop.NetworkManager", "WirelessEnabled", lgi.GLib.Variant("b", enable))
|
||||
self._private.NetworkManager.WirelessEnabled = { signature = "b", value = enable }
|
||||
end
|
||||
@@ -336,11 +395,16 @@ function network.new(args)
|
||||
}
|
||||
|
||||
ret._private.NetworkManagerProperties:connect_signal(function(_, properties, data)
|
||||
if data.WirelessEnables ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
|
||||
if data.WirelessEnabled ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
|
||||
ret._private.WirelessEnabled = data.WirelessEnabled
|
||||
|
||||
if ret._private.WirelessEnabled then
|
||||
dnd:set_enabled()
|
||||
else
|
||||
dnd:set_disabled()
|
||||
end
|
||||
|
||||
ret:emit_signal("NetworkManager::status", ret._private.WirelessEnabled)
|
||||
print(ret._private.WirelessEnabled)
|
||||
|
||||
if data.WirelessEnabled then
|
||||
gtimer {
|
||||
@@ -356,21 +420,15 @@ function network.new(args)
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
ret:get_wifi_proxy()
|
||||
ret:get_active_device()
|
||||
|
||||
ret:scan_access_points()
|
||||
|
||||
--[[ gtimer.delayed_call(function()
|
||||
local active_access_point = ret._private.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
if ret._private.NetworkManager.State == network.DeviceState.ACTIVATED and active_access_point ~= "/" then
|
||||
local active_access_point_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = active_access_point,
|
||||
}
|
||||
end
|
||||
end) ]]
|
||||
if ret._private.NetworkManager.WirelessEnabled then
|
||||
dnd:set_enabled()
|
||||
else
|
||||
dnd:set_disabled()
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
@@ -389,7 +447,7 @@ function network.new(args)
|
||||
}
|
||||
|
||||
wifi_margin:buttons(gtable.join(
|
||||
awful.button({}, 1, nil,
|
||||
abutton({}, 1, nil,
|
||||
function()
|
||||
if wifi_list.forced_height == 0 then
|
||||
if not ret:get_children_by_id("wifi_ap_list")[1].children then
|
||||
@@ -420,7 +478,7 @@ function network.new(args)
|
||||
|
||||
local refresh_button = ret:get_children_by_id("refresh")[1]
|
||||
refresh_button:buttons(gtable.join(
|
||||
awful.button({}, 1, nil,
|
||||
abutton({}, 1, nil,
|
||||
function()
|
||||
ret:scan_access_points()
|
||||
end
|
||||
|
||||
@@ -3,374 +3,109 @@
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local abutton = require("awful.button")
|
||||
local apopup = require("awful.popup")
|
||||
local atooltip = require("awful.tooltip")
|
||||
local base = require("wibox.widget.base")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local gtable = require("gears.table")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
mouse = mouse,
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/network/"
|
||||
|
||||
-- Insert your interfaces here, get the from ip a
|
||||
local interfaces = {
|
||||
wlan_interface = User_config.network.wlan,
|
||||
lan_interface = User_config.network.ethernet
|
||||
}
|
||||
|
||||
local network_mode = nil
|
||||
|
||||
local nm_widget = require("src.modules.network_controller.init")
|
||||
|
||||
-- Returns the network widget
|
||||
return function(s)
|
||||
local startup = true
|
||||
local reconnect_startup = true
|
||||
local wifi_strength
|
||||
local network_widget = wibox.widget {
|
||||
local network = { mt = {} }
|
||||
|
||||
function network.new(args)
|
||||
args = args or {}
|
||||
|
||||
local w = base.make_widget_from_value({
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
id = 'icon',
|
||||
image = gears.color.recolor_image(icondir .. "no-internet" .. ".svg", Theme_config.network.fg),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
resize = false
|
||||
},
|
||||
id = "icon_layout",
|
||||
widget = wibox.container.place
|
||||
id = 'wifi_icon',
|
||||
image = gears.color.recolor_image(icondir .. "no-internet" .. ".svg", Theme_config.network.fg),
|
||||
widget = wibox.widget.imagebox,
|
||||
resize = false
|
||||
},
|
||||
id = "icon_margin",
|
||||
top = dpi(2),
|
||||
widget = wibox.container.margin
|
||||
{
|
||||
id = "wifi_strength",
|
||||
visible = true,
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
spacing = dpi(10),
|
||||
{
|
||||
id = "label",
|
||||
visible = false,
|
||||
valign = "center",
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "network_layout",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
left = dpi(8),
|
||||
right = dpi(8),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "container",
|
||||
left = dpi(8),
|
||||
right = dpi(8),
|
||||
widget = wibox.container.margin
|
||||
widget = wibox.container.place,
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
bg = Theme_config.network.bg,
|
||||
fg = Theme_config.network.fg,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
shape = Theme_config.network.shape,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
})
|
||||
|
||||
local network_tooltip = awful.tooltip {
|
||||
text = "Loading",
|
||||
objects = { network_widget },
|
||||
mode = "inside",
|
||||
preferred_alignments = "middle",
|
||||
margins = dpi(10)
|
||||
}
|
||||
Hover_signal(w)
|
||||
|
||||
local check_for_internet = [=[
|
||||
status_ping=0
|
||||
packets="$(ping -q -w2 -c2 1.1.1.1 | grep -o "100% packet loss")"
|
||||
if [ ! -z "${packets}" ];
|
||||
then
|
||||
status_ping=0
|
||||
else
|
||||
status_ping=1
|
||||
fi
|
||||
if [ $status_ping -eq 0 ];
|
||||
then
|
||||
echo "Connected but no internet"
|
||||
fi
|
||||
]=]
|
||||
gtable.crush(w, network, true)
|
||||
|
||||
local update_startup = function()
|
||||
if startup then
|
||||
startup = false
|
||||
end
|
||||
end
|
||||
local nm = nm_widget { screen = args.screen }
|
||||
|
||||
local update_reconnect_startup = function(status)
|
||||
reconnect_startup = status
|
||||
end
|
||||
|
||||
local update_tooltip = function(message)
|
||||
network_tooltip:set_markup(message)
|
||||
end
|
||||
|
||||
local network_notify = function(message, title, app_name, icon)
|
||||
naughty.notification {
|
||||
text = message,
|
||||
title = title,
|
||||
app_name = app_name,
|
||||
icon = gears.color.recolor_image(icon, Theme_config.network.notify_icon_color),
|
||||
timeout = 3
|
||||
}
|
||||
end
|
||||
|
||||
local update_wireless = function()
|
||||
network_mode = "wireless"
|
||||
|
||||
local notify_connected = function(essid)
|
||||
local message = "You are now connected to " .. essid
|
||||
local title = "Connection successfull"
|
||||
local app_name = "System Notification"
|
||||
local icon = icondir .. "wifi-strength-4.svg"
|
||||
network_notify(message, title, app_name, icon)
|
||||
end
|
||||
|
||||
local update_wireless_data = function(healthy)
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ iw dev ]] .. interfaces.wlan_interface .. [[ link ]],
|
||||
function(stdout)
|
||||
local essid = stdout:match("SSID: (.-)\n") or "N/A"
|
||||
local bitrate = stdout:match("tx bitrate: (.+/s)") or "N/A"
|
||||
local message = "Connected to <b>" ..
|
||||
essid ..
|
||||
"</b>\nSignal strength <b>" ..
|
||||
tostring(wifi_strength) .. "%</b>\n" .. "Bit rate <b>" .. tostring(bitrate) .. "</b>"
|
||||
|
||||
if healthy then
|
||||
update_tooltip(message)
|
||||
else
|
||||
update_tooltip("You are connected but have no internet" .. message)
|
||||
end
|
||||
|
||||
if reconnect_startup or startup then
|
||||
notify_connected(essid)
|
||||
update_reconnect_startup(false)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local update_wireless_icon = function(strength)
|
||||
awful.spawn.easy_async_with_shell(
|
||||
check_for_internet,
|
||||
function(stdout)
|
||||
local icon = "wifi-strength"
|
||||
if not stdout:match("Connected but no internet") then
|
||||
if startup or reconnect_startup then
|
||||
capi.awesome.emit_signal("system::network_connected")
|
||||
end
|
||||
icon = icon .. '-' .. tostring(strength)
|
||||
update_wireless_data(true)
|
||||
else
|
||||
icon = icon .. "-" .. tostring(strength)
|
||||
update_wireless_data(false)
|
||||
end
|
||||
network_widget.container.network_layout.spacing = dpi(8)
|
||||
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir
|
||||
.. icon .. ".svg", Theme_config.network.fg))
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local update_wireless_strength = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ awk 'NR==3 {printf "%3.0f", ($3/70)*100}' /proc/net/wireless ]],
|
||||
function(stdout)
|
||||
if not tonumber(stdout) then
|
||||
return
|
||||
end
|
||||
wifi_strength = tonumber(stdout)
|
||||
network_widget.container.network_layout.spacing = dpi(8)
|
||||
network_widget.container.network_layout.label.visible = true
|
||||
network_widget.container.network_layout.label:set_text(tostring(wifi_strength .. "%"))
|
||||
local wifi_strength_rounded = math.floor(wifi_strength / 25 + 0.5)
|
||||
update_wireless_icon(wifi_strength_rounded)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
update_wireless_strength()
|
||||
update_startup()
|
||||
end
|
||||
|
||||
local update_wired = function()
|
||||
network_mode = "wired"
|
||||
|
||||
local notify_connected = function()
|
||||
local message = "You are now connected to " .. interfaces.lan_interface
|
||||
local title = "Connection successfull"
|
||||
local app_name = "System Notification"
|
||||
local icon = icondir .. "ethernet.svg"
|
||||
network_notify(message, title, app_name, icon)
|
||||
end
|
||||
|
||||
awful.spawn.easy_async_with_shell(
|
||||
check_for_internet,
|
||||
function(stdout)
|
||||
local icon = "ethernet"
|
||||
|
||||
if stdout:match("Connected but no internet") then
|
||||
icon = "no-internet"
|
||||
update_tooltip(
|
||||
"No internet"
|
||||
)
|
||||
else
|
||||
update_tooltip("You are connected to:\nEthernet Interface <b>" .. interfaces.lan_interface .. "</b>")
|
||||
if startup or reconnect_startup then
|
||||
capi.awesome.emit_signal("system::network_connected")
|
||||
notify_connected()
|
||||
update_startup()
|
||||
end
|
||||
update_reconnect_startup(false)
|
||||
end
|
||||
network_widget.container.network_layout.label.visible = false
|
||||
network_widget.container.network_layout.spacing = 0
|
||||
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(icondir .. icon .. ".svg")
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
local update_disconnected = function()
|
||||
local notify_wireless_disconnected = function()
|
||||
local message = "WiFi has been disconnected"
|
||||
local title = "Connection lost"
|
||||
local app_name = "System Notification"
|
||||
local icon = icondir .. "wifi-strength-off-outline.svg"
|
||||
network_notify(message, title, app_name, icon)
|
||||
end
|
||||
local notify_wired_disconnected = function()
|
||||
local message = "Ethernet has been unplugged"
|
||||
local title = "Connection lost"
|
||||
local app_name = "System Notification"
|
||||
local icon = icondir .. "no-internet.svg"
|
||||
network_notify(message, title, app_name, icon)
|
||||
end
|
||||
local icon = "wifi-strength-off-outline"
|
||||
if network_mode == "wireless" then
|
||||
icon = "wifi-strength-off-outline"
|
||||
if not reconnect_startup then
|
||||
update_reconnect_startup(true)
|
||||
notify_wireless_disconnected()
|
||||
end
|
||||
elseif network_mode == "wired" then
|
||||
icon = "no-internet"
|
||||
if not reconnect_startup then
|
||||
update_reconnect_startup(true)
|
||||
notify_wired_disconnected()
|
||||
end
|
||||
end
|
||||
network_widget.container.network_layout.label.visible = false
|
||||
update_tooltip("Network unreachable")
|
||||
network_widget.container.network_layout.spacing = 0
|
||||
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir ..
|
||||
icon .. ".svg", Theme_config.network.fg))
|
||||
end
|
||||
|
||||
local check_network_mode = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[=[
|
||||
wireless="]=] .. tostring(interfaces.wlan_interface) .. [=["
|
||||
wired="]=] .. tostring(interfaces.lan_interface) .. [=["
|
||||
net="/sys/class/net/"
|
||||
wireless_state="down"
|
||||
wired_state="down"
|
||||
network_mode=""
|
||||
function check_network_state(){
|
||||
if [[ "${wireless_state}" == "up" ]];
|
||||
then
|
||||
network_mode="wireless"
|
||||
elif [[ "${wired_state}" == "up" ]];
|
||||
then
|
||||
network_mode="wired"
|
||||
else
|
||||
network_mode="No internet connected"
|
||||
fi
|
||||
}
|
||||
function check_network_directory(){
|
||||
if [[ -n "${wireless}" && -d "${net}${wireless}" ]];
|
||||
then
|
||||
wireless_state="$(cat "${net}${wireless}/operstate")"
|
||||
fi
|
||||
if [[ -n "${wired}" && -d "${net}${wired}" ]];
|
||||
then
|
||||
wired_state="$(cat "${net}${wired}/operstate")"
|
||||
fi
|
||||
check_network_state
|
||||
}
|
||||
function print_network_mode(){
|
||||
check_network_directory
|
||||
printf "${network_mode}"
|
||||
}
|
||||
print_network_mode
|
||||
]=],
|
||||
function(stdout)
|
||||
if stdout:match("No internet connected") then
|
||||
update_disconnected()
|
||||
elseif stdout:match("wireless") then
|
||||
update_wireless()
|
||||
elseif stdout:match("wired") then
|
||||
update_wired()
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
gears.timer {
|
||||
timeout = 5,
|
||||
autostart = true,
|
||||
call_now = true,
|
||||
callback = function()
|
||||
check_network_mode()
|
||||
end
|
||||
}
|
||||
|
||||
local network_container = awful.popup {
|
||||
widget = nm_widget {},
|
||||
bg = Theme_config.network_manager.bg,
|
||||
screen = s,
|
||||
stretch = false,
|
||||
local network_controler_popup = apopup {
|
||||
widget = nm,
|
||||
visible = false,
|
||||
ontop = true,
|
||||
placement = function(c) awful.placement.align(c,
|
||||
{ position = "top_right", margins = { right = dpi(350), top = dpi(60) } })
|
||||
end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end
|
||||
screen = args.screen,
|
||||
}
|
||||
|
||||
-- Signals
|
||||
Hover_signal(network_widget)
|
||||
w:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
--This gets the wrong wibox, get all wiboxed and find the correct widget
|
||||
network_controler_popup.x = capi.mouse.coords().x - (network_controler_popup:geometry().width / 2)
|
||||
network_controler_popup.y = dpi(65)
|
||||
network_controler_popup.visible = not network_controler_popup.visible
|
||||
end)
|
||||
))
|
||||
|
||||
network_widget:buttons(
|
||||
gears.table.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
nil,
|
||||
function()
|
||||
network_container.visible = not network_container.visible
|
||||
end
|
||||
),
|
||||
awful.button(
|
||||
{},
|
||||
3,
|
||||
nil,
|
||||
function()
|
||||
capi.awesome.emit_signal("NM::toggle_wifi")
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
awesome.connect_signal("NM::AccessPointStrength", function(strength)
|
||||
strength = math.floor(strength)
|
||||
w:get_children_by_id("wifi_strength")[1].text = strength .. "%"
|
||||
w:get_children_by_id("wifi_icon")[1].image = gears.color.recolor_image(icondir ..
|
||||
"wifi-strength-" .. math.floor(strength / 25) + 1 .. ".svg", Theme_config.network.fg)
|
||||
end)
|
||||
|
||||
return network_widget
|
||||
nm:connect_signal("NM::Bitrate", function(_, bitrate)
|
||||
print(bitrate)
|
||||
end)
|
||||
|
||||
atooltip {
|
||||
objects = { w },
|
||||
mode = "outside",
|
||||
preferred_alignments = "middle",
|
||||
margins = dpi(10),
|
||||
text = "Connected to " .. "" .. " with " .. "" .. " signal strength"
|
||||
}
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
function network.mt:__call(...)
|
||||
return network.new(...)
|
||||
end
|
||||
|
||||
return setmetatable(network, network.mt)
|
||||
|
||||
Reference in New Issue
Block a user