update network widget to (hopefully) show ethernet/wifi accordingly
This commit is contained in:
@@ -152,6 +152,10 @@ return setmetatable(device, {
|
|||||||
if self.NetworkManagerDeviceWireless then
|
if self.NetworkManagerDeviceWireless then
|
||||||
return self.NetworkManagerDeviceWireless.Bitrate
|
return self.NetworkManagerDeviceWireless.Bitrate
|
||||||
end
|
end
|
||||||
|
elseif key == 'Speed' then
|
||||||
|
if self.NetworkManagerDeviceWired then
|
||||||
|
return self.NetworkManagerDeviceWired.Speed
|
||||||
|
end
|
||||||
elseif key == 'Managed' then
|
elseif key == 'Managed' then
|
||||||
return self.NetworkManagerDevice.Managed
|
return self.NetworkManagerDevice.Managed
|
||||||
elseif key == 'ActiveConnection' then
|
elseif key == 'ActiveConnection' then
|
||||||
|
|||||||
@@ -93,13 +93,19 @@ end
|
|||||||
--TODO: Make sure this works, I don't know how its going
|
--TODO: Make sure this works, I don't know how its going
|
||||||
--TODO: to work if there were multiple wireless devices, probably try
|
--TODO: to work if there were multiple wireless devices, probably try
|
||||||
--TODO: to find the one that is active or something like that
|
--TODO: to find the one that is active or something like that
|
||||||
|
---Returns the current wifi device, if none if found returns the ethernet devie, else nil
|
||||||
|
---@return wifi|ethernet|nil device
|
||||||
function network:get_wireless_device()
|
function network:get_wireless_device()
|
||||||
|
local ethernet_device = nil
|
||||||
for _, device in pairs(self.Devices) do
|
for _, device in pairs(self.Devices) do
|
||||||
print(device.DeviceType, device.device_path)
|
print(device.DeviceType, device.device_path)
|
||||||
if device.DeviceType == self.DeviceType.WIFI then
|
if device.DeviceType == self.DeviceType.WIFI then
|
||||||
return device
|
return device
|
||||||
|
elseif device.DeviceType == self.DeviceType.ETHERNET then
|
||||||
|
ethernet_device = device
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return ethernet_device
|
||||||
end
|
end
|
||||||
|
|
||||||
function network:get_devices()
|
function network:get_devices()
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ local wibox = require('wibox')
|
|||||||
|
|
||||||
-- Local Libs
|
-- Local Libs
|
||||||
local hover = require('src.tools.hover')
|
local hover = require('src.tools.hover')
|
||||||
local nm_widget = require('src.modules.network_controller')
|
local nm_widget = require('src.modules.network')
|
||||||
|
local networkManager = require('src.tools.network')()
|
||||||
|
|
||||||
local capi = {
|
local capi = {
|
||||||
awesome = awesome,
|
awesome = awesome,
|
||||||
@@ -62,33 +63,61 @@ return setmetatable({}, {
|
|||||||
|
|
||||||
hover.bg_hover { widget = w }
|
hover.bg_hover { widget = w }
|
||||||
|
|
||||||
capi.awesome.connect_signal('NM::AccessPointStrength', function(strength)
|
-- Little workaround because signals from nm_widget are not working?
|
||||||
strength = mfloor(strength)
|
--! Find out why the signals are not working
|
||||||
w:get_children_by_id('wifi_strength')[1].text = strength .. '%'
|
local function update_ethernet(device)
|
||||||
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir ..
|
w.tt = atooltip {
|
||||||
'wifi-strength-' .. mfloor(strength / 25) + 1 .. '.svg', beautiful.colorscheme.bg)
|
|
||||||
end)
|
|
||||||
|
|
||||||
capi.awesome.connect_signal('NM::EthernetStatus', function(connected, speed)
|
|
||||||
local tt = atooltip {
|
|
||||||
objects = { w },
|
objects = { w },
|
||||||
mode = 'outside',
|
mode = 'outside',
|
||||||
preferred_alignments = 'middle',
|
preferred_alignments = 'middle',
|
||||||
margins = dpi(10),
|
margins = dpi(10),
|
||||||
|
text = 'Connected via Ethernet at ' .. mfloor(device.Speed or 0) .. '/Mbps',
|
||||||
}
|
}
|
||||||
if connected then
|
end
|
||||||
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir .. 'ethernet.svg',
|
|
||||||
beautiful.colorscheme.bg)
|
|
||||||
tt.text = 'Connected via Ethernet at ' .. mfloor(speed or 0) .. '/Mbps'
|
|
||||||
else
|
|
||||||
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir .. 'no-internet.svg',
|
|
||||||
beautiful.colorscheme.bg)
|
|
||||||
tt.text = 'No connection found'
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local nm = nm_widget { screen = screen }
|
local nm = nm_widget { screen = screen }
|
||||||
|
|
||||||
|
local function active_access_point_strength(strength)
|
||||||
|
local s
|
||||||
|
if strength > 80 then
|
||||||
|
s = 5
|
||||||
|
elseif strength >= 60 and strength < 80 then
|
||||||
|
s = 4
|
||||||
|
elseif strength >= 40 and strength < 60 then
|
||||||
|
s = 3
|
||||||
|
elseif strength >= 20 and strength < 40 then
|
||||||
|
s = 2
|
||||||
|
else
|
||||||
|
s = 1
|
||||||
|
end
|
||||||
|
w:get_children_by_id('wifi_strength')[1].text = math.floor(strength) .. '%'
|
||||||
|
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir ..
|
||||||
|
'wifi-strength-' .. s .. '.svg', beautiful.colorscheme.bg)
|
||||||
|
end
|
||||||
|
|
||||||
|
capi.awesome.connect_signal('ActiveAccessPointStrength', active_access_point_strength)
|
||||||
|
|
||||||
|
-- Remove the wifi signals when no wifi is active/readd them when wifi is active
|
||||||
|
networkManager:connect_signal('NetworkManager::WirelessEnabled', function(enabled)
|
||||||
|
if enabled then
|
||||||
|
capi.awesome.connect_signal('ActiveAccessPointStrength', active_access_point_strength)
|
||||||
|
w:get_children_by_id('wifi_strength')[1].visible = true
|
||||||
|
w.tt = nil
|
||||||
|
else
|
||||||
|
-- If its nil then there is no internet
|
||||||
|
local dev = networkManager:get_wireless_device()
|
||||||
|
if not dev then
|
||||||
|
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir .. 'no-internet.svg', beautiful.colorscheme.bg)
|
||||||
|
else
|
||||||
|
w:get_children_by_id('wifi_icon')[1].image = gcolor.recolor_image(icondir .. 'ethernet.svg', beautiful.colorscheme.bg)
|
||||||
|
update_ethernet(dev)
|
||||||
|
w.tt = nil
|
||||||
|
end
|
||||||
|
capi.awesome.disconnect_signal('ActiveAccessPointStrength', active_access_point_strength)
|
||||||
|
w:get_children_by_id('wifi_strength')[1].visible = false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
local network_controler_popup = apopup {
|
local network_controler_popup = apopup {
|
||||||
widget = nm,
|
widget = nm,
|
||||||
visible = true,
|
visible = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user