finished application laucnher and bluetooth widget

This commit is contained in:
Rene Kievits
2022-11-27 10:58:27 +01:00
parent c6341f84e7
commit 10f56a7273
77 changed files with 2379 additions and 4938 deletions

View File

@@ -10,6 +10,8 @@ local gfilesystem = require("gears").filesystem
local gobject = require("gears").object
local gcolor = require("gears").color
local wibox = require("wibox")
local base = require("wibox.widget.base")
local NM = require("lgi").NM
local ap_form = require("src.modules.network_controller.ap_form")
@@ -17,39 +19,28 @@ local icondir = gfilesystem.get_configuration_dir() .. "src/assets/icons/network
local access_point = { mt = {} }
access_point.connected = false
function access_point.new(args)
args = args or {}
if not args.access_point then return end
local ret = gobject { enable_properties = true, enable_auto_signals = true }
gtable.crush(ret, access_point, true)
local strength = args.access_point.strength or 0
--normalize strength between 1 and 4
strength = math.floor(strength / 25) + 1
local icon = "wifi-strength-" .. strength .. ".svg"
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 args.active == args.access_point.access_point_path then
--[[ 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
end ]]
local ap_widget = wibox.widget {
local ret = base.make_widget_from_value(wibox.widget {
{
{
{
{
{
image = gcolor.recolor_image(
icondir .. icon, icon_color),
icondir .. "wifi-strength-" .. math.floor(args.NetworkManagerAccessPoint.Strength / 25) + 1 .. ".svg",
icon_color),
id = "icon",
resize = true,
valign = "center",
@@ -67,7 +58,8 @@ function access_point.new(args)
{
{
{
text = args.access_point.ssid or args.access_point.hw_address or "Unknown",
text = NM.utils_ssid_to_utf8(args.NetworkManagerAccessPoint.Ssid) or
args.NetworkManagerAccessPoint.hw_address or "Unknown",
id = "alias",
widget = wibox.widget.textbox
},
@@ -132,31 +124,32 @@ function access_point.new(args)
border_width = Theme_config.network_manager.access_point.border_width,
id = "background",
shape = Theme_config.network_manager.access_point.device_shape,
device = ret.access_point,
widget = wibox.container.background
}
})
ap_form { screen = args.screen, SSID = args.access_point.ssid }
gtable.crush(ret, access_point, true)
ap_widget:buttons(
ret.NetworkManagerAccessPoint = args.NetworkManagerAccessPoint
ret.ap_form = ap_form { screen = args.screen, ssid = NM.utils_ssid_to_utf8(ret.NetworkManagerAccessPoint.Ssid) }
ret:buttons(
gtable.join(
awful.button(
{},
1,
nil,
function()
ap_form:popup_toggle()
ret.ap_form:popup_toggle()
end
)
)
)
ap_widget:get_children_by_id("con")[1].image = gcolor.recolor_image(
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(
icondir .. "link.svg", icon_color)
Hover_signal(ap_widget)
ret.widget = ap_widget
Hover_signal(ret)
return ret
end

View File

@@ -15,202 +15,171 @@ local capi = {
}
local ap_form = { mt = {} }
ap_form._private = {}
ap_form.settigns_form = {
ssid = awful.widget.inputbox {
widget_template = wibox.template {
widget = wibox.widget {
{
{
{
widget = wibox.widget.textbox,
halign = "left",
valign = "center",
id = "text_role",
},
widget = wibox.container.margin,
margins = 5,
id = "marg"
},
widget = wibox.container.constraint,
strategy = "exact",
width = 400,
height = 50,
id = "const"
},
widget = wibox.container.background,
bg = "#212121",
fg = "#F0F0F0",
border_color = "#414141",
border_width = 2,
shape = gshape.rounded_rect,
forced_width = 300,
forced_height = 50,
},
update_callback = function(template_widget, args)
template_widget.widget.const.marg.text_role.markup = args.text
end
}
},
password = awful.widget.inputbox {
widget_template = wibox.template {
widget = wibox.widget {
{
{
{
widget = wibox.widget.textbox,
halign = "left",
valign = "center",
id = "text_role",
},
widget = wibox.container.margin,
margins = 5,
id = "marg"
},
widget = wibox.container.constraint,
strategy = "exact",
width = 400,
height = 50,
id = "const"
},
widget = wibox.container.background,
bg = "#212121",
fg = "#F0F0F0",
border_color = "#414141",
border_width = 2,
shape = gshape.rounded_rect,
forced_width = 300,
forced_height = 50,
},
update_callback = function(template_widget, args)
template_widget.widget.const.marg.text_role.markup = args.text
end
}
},
}
function ap_form:popup_toggle()
self._private.popup.visible = not self._private.popup.visible
self.visible = not self.visible
end
function ap_form.new(args)
args = args or {}
args.screen = args.screen or awful.screen.preferred()
local ret = gobject {}
ret._private = {}
gtable.crush(ret, ap_form, true)
gtable.crush(ret, args)
ret._private.popup = awful.popup {
widget = {
{ -- Header
{
nil,
local settigns_form = {
password = awful.widget.inputbox {
widget_template = wibox.template {
widget = wibox.widget {
{
{
widget = wibox.widget.textbox,
text = args.SSID,
halign = "center",
valign = "center",
},
widget = wibox.container.margin,
margins = dpi(5)
},
{ -- Close button
{
{
widget = wibox.widget.imagebox,
image = gcolor.recolor_image(icondir .. "close.svg", Theme_config.network_manager.form.icon_fg),
resize = false,
widget = wibox.widget.textbox,
halign = "left",
valign = "center",
halign = "center",
id = "text_role",
},
widget = wibox.container.margin,
margins = 5,
id = "marg"
},
widget = wibox.container.background,
id = "close_button",
bg = Theme_config.network_manager.form.close_bg
widget = wibox.container.constraint,
strategy = "exact",
width = 400,
height = 50,
id = "const"
},
layout = wibox.layout.align.horizontal
widget = wibox.container.background,
bg = "#212121",
fg = "#F0F0F0",
border_color = "#414141",
border_width = 2,
shape = gshape.rounded_rect,
forced_width = 300,
forced_height = 50,
},
widget = wibox.container.background,
bg = Theme_config.network_manager.form.header_bg,
fg = Theme_config.network_manager.form.header_fg,
},
{ -- Form
{ -- SSID
update_callback = function(template_widget, args)
template_widget.widget.const.marg.text_role.markup = args.text
end
}
},
}
local ret = awful.popup {
widget = {
{
{ -- Header
{
widget = wibox.widget.textbox,
text = "SSID",
halign = "center",
valign = "center"
nil,
{
{
widget = wibox.widget.textbox,
text = args.ssid,
font = User_config.font.specify .. ",extra bold 16",
halign = "center",
valign = "center",
},
widget = wibox.container.margin,
margins = dpi(5)
},
{ -- Close button
{
{
widget = wibox.widget.imagebox,
image = gcolor.recolor_image(icondir .. "close.svg", Theme_config.network_manager.form.icon_fg),
resize = false,
valign = "center",
halign = "center",
},
widget = wibox.container.margin,
margins = dpi(5),
},
widget = wibox.container.background,
shape = Theme_config.network_manager.form.close_icon_shape,
id = "close_button",
bg = Theme_config.network_manager.form.close_bg
},
layout = wibox.layout.align.horizontal
},
nil,
-- Change to inputtextbox container
ret.settigns_form.ssid,
layout = wibox.layout.align.horizontal
widget = wibox.container.background,
bg = Theme_config.network_manager.form.header_bg,
fg = Theme_config.network_manager.form.header_fg,
},
{ -- Password
{
{ -- Form
{ -- Password
widget = wibox.widget.textbox,
text = "Password",
halign = "center",
valign = "center"
},
nil,
{
widget = wibox.container.margin,
left = dpi(20),
right = dpi(20),
},
-- Change to inputtextbox container
ret.settigns_form.password,
settigns_form.password,
layout = wibox.layout.align.horizontal
},
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
},
{ -- Actions
{ -- Auto connect
{
{ -- Actions
{ -- Auto connect
{
checked = false,
shape = Theme_config.network_manager.form.checkbox_shape,
color = Theme_config.network_manager.form.checkbox_bg,
check_color = Theme_config.network_manager.form.checkbox_fg,
check_border_color = Theme_config.network_manager.form.check_border_color,
check_border_width = Theme_config.network_manager.form.check_border_width,
widget = wibox.widget.checkbox
},
widget = wibox.container.constraint,
strategy = "exact",
width = dpi(30),
height = dpi(30)
},
{
widget = wibox.widget.textbox,
text = "Auto connect",
halign = "center",
valign = "center"
},
layout = wibox.layout.fixed.horizontal
},
nil,
{ -- Connect
{
{
widget = wibox.widget.textbox,
text = "Connect",
{
{
checked = false,
shape = Theme_config.network_manager.form.checkbox_shape,
color = Theme_config.network_manager.form.checkbox_fg,
paddings = dpi(3),
check_color = Theme_config.network_manager.form.checkbox_bg,
border_color = Theme_config.network_manager.form.checkbox_bg,
border_width = 2,
id = "checkbox",
widget = wibox.widget.checkbox
},
widget = wibox.container.constraint,
strategy = "exact",
width = dpi(30),
height = dpi(30)
},
widget = wibox.container.place,
halign = "center",
valign = "center"
},
widget = wibox.container.background,
bg = Theme_config.network_manager.form.button_bg,
fg = Theme_config.network_manager.form.button_fg,
{
widget = wibox.widget.textbox,
text = "Auto connect",
halign = "center",
valign = "center"
},
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal
},
widget = wibox.container.margin,
margins = dpi(10),
nil,
{ -- Connect
{
{
{
widget = wibox.widget.textbox,
text = "Connect",
halign = "center",
valign = "center"
},
widget = wibox.container.margin,
margins = dpi(10),
},
widget = wibox.container.background,
bg = Theme_config.network_manager.form.button_bg,
fg = Theme_config.network_manager.form.button_fg,
shape = Theme_config.network_manager.form.button_shape,
id = "connect_button",
},
widget = wibox.container.margin,
margins = dpi(10),
},
layout = wibox.layout.align.horizontal
},
layout = wibox.layout.align.horizontal
spacing = dpi(20),
layout = wibox.layout.fixed.vertical
},
layout = wibox.layout.align.vertical
widget = wibox.container.margin,
margins = dpi(10)
},
placement = awful.placement.centered,
ontop = true,
@@ -220,37 +189,36 @@ function ap_form.new(args)
bg = Theme_config.network_manager.form.bg,
fg = Theme_config.network_manager.form.fg,
shape = Theme_config.network_manager.form.shape,
border_color = Theme_config.network_manager.form.border_color,
border_width = Theme_config.network_manager.form.border_width,
type = "dialog",
screen = args.screen,
}
ret._private.popup.widget:get_children_by_id("close_button")[1]:connect_signal("button::press", function()
ret:popup_toggle()
gtable.crush(ret, ap_form, true)
local checkbox = ret.widget:get_children_by_id("checkbox")[1]
checkbox:connect_signal("button::press", function()
checkbox.checked = not checkbox.checked
end)
ret.settigns_form.ssid:connect_signal(
"submit",
function(text)
end
)
local close_button = ret.widget:get_children_by_id("close_button")[1]
close_button:connect_signal("button::press", function()
ret:popup_toggle()
end)
Hover_signal(close_button)
ret.settigns_form.ssid:connect_signal(
"stopped",
function()
end
)
ret.settigns_form.password:connect_signal(
"submit",
function(text)
end
)
ret.settigns_form.password:connect_signal(
"stopped",
function()
end
)
local connect_button = ret.widget:get_children_by_id("connect_button")[1]
connect_button:connect_signal("button::press", function()
ret:emit_signal("ap_form::connect", {
ssid = args.ssid,
password = settigns_form.password:get_text(),
auto_connect = ret.widget:get_children_by_id("checkbox")[1].checked
})
print("Connect to " .. args.ssid:get_text(), "\nPassword: " .. settigns_form.password:get_text(),
"\nAuto connect: " .. tostring(ret.widget:get_children_by_id("checkbox")[1].checked))
end)
Hover_signal(connect_button)
return ret
end

View File

@@ -14,23 +14,23 @@ local gcolor = require("gears").color
local gears = require("gears")
local lgi = require("lgi")
local wibox = require("wibox")
local NM = require("lgi").NM
local base = require("wibox.widget.base")
local rubato = require("src.lib.rubato")
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 capi = {
awesome = awesome,
}
local network = { mt = {} }
network.access_points = { layout = wibox.layout.fixed.vertical }
network.NMState = {
UNKNOWN = 0,
ASLEEP = 10,
@@ -81,37 +81,45 @@ local function flags_to_security(flags, wpa_flags, rsn_flags)
return (str:gsub("^%s", ""))
end
local function get_wifi_proxy(self)
local devices = self._private.client_proxy:GetDevices()
for _, device in ipairs(devices) do
local device_proxy = dbus_proxy.Proxy:new {
local function generate_uuid()
return string.gsub('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', '[xy]', function(c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end
function network:get_wifi_proxy()
local devices = self._private.NetworkManager:GetDevices()
for _, path in ipairs(devices) do
local NetworkManagerDevice = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.Device",
path = device
path = path
}
if device_proxy.DeviceType == network.DeviceType.WIFI then
self._private.device_proxy = device_proxy
self._private.wifi_proxy = dbus_proxy.Proxy:new {
if NetworkManagerDevice.DeviceType == network.DeviceType.WIFI then
self._private.NetworkManagerDevice = NetworkManagerDevice
self._private.NetworkManagerDeviceWireless = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.Device.Wireless",
path = device
path = path
}
self._private.device_proxy:connect_signal(function(proxy, new_state, old_state, reason)
local active_access_point_proxy = dbus_proxy.Proxy:new {
self._private.NetworkManagerDevice:connect_signal(function(proxy, new_state, old_state, reason)
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
}
self:emit_signal(tostring(active_access_point_proxy.HwAddress) .. "::state", new_state, old_state)
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(active_access_point_proxy.Ssid)
self:emit_signal("NM::AccessPointConnected", ssid, active_access_point_proxy.Strength)
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")
end
@@ -119,8 +127,7 @@ local function get_wifi_proxy(self)
end
function network.device_state_to_string(state)
local device_state_to_string =
{
local device_state_to_string = {
[0] = "Unknown",
[10] = "Unmanaged",
[20] = "Unavailable",
@@ -139,63 +146,30 @@ function network.device_state_to_string(state)
return device_state_to_string[state]
end
local function get_access_point_connections(self, ssid)
local connection_proxies = {}
function network:get_access_point_connections(ssid)
local cn = {}
local connections = self._private.settings_proxy:ListConnections()
local connections = self._private.NetworkManagerSettings:ListConnections()
for _, connection_path in ipairs(connections) do
local connection_proxy = dbus_proxy.Proxy:new {
local NetworkManagerSettingsConnection = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.Settings.Connection",
path = connection_path
}
if connection_proxy.Filename:find(ssid) then
table.insert(connection_proxies, connection_proxy)
if NetworkManagerSettingsConnection.Filename:find(ssid) then
table.insert(cn, NetworkManagerSettingsConnection)
end
end
return connection_proxies
return cn
end
local function generate_uuid()
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
local uuid = string.gsub(template, '[xy]', function(c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
return uuid
end
local function create_profile(ap, password, auto_connect)
local s_con =
{
-- ["interface-name"] = lgi.GLib.Variant("s", ap.device_interface),
["uuid"] = lgi.GLib.Variant("s", generate_uuid()),
["id"] = lgi.GLib.Variant("s", ap.ssid),
["type"] = lgi.GLib.Variant("s", "802-11-wireless"),
["autoconnect"] = lgi.GLib.Variant("b", auto_connect),
}
local s_ip4 =
{
["method"] = lgi.GLib.Variant("s", "auto")
}
local s_ip6 =
{
["method"] = lgi.GLib.Variant("s", "auto"),
}
local s_wifi =
{
["mode"] = lgi.GLib.Variant("s", "infrastructure"),
}
function network:create_profile(ap, password, auto_connect)
local s_wsec = {}
if ap.security ~= "" then
if ap.security:match("WPA") ~= nil then
if ap.security:match("WPA") then
s_wsec["key-mgmt"] = lgi.GLib.Variant("s", "wpa-psk")
s_wsec["auth-alg"] = lgi.GLib.Variant("s", "open")
--s_wsec["psk"] = lgi.GLib.Variant("s", helpers.string.trim(password))
@@ -207,108 +181,85 @@ local function create_profile(ap, password, auto_connect)
end
return {
["connection"] = s_con,
["ipv4"] = s_ip4,
["ipv6"] = s_ip6,
["802-11-wireless"] = s_wifi,
["connection"] = {
-- ["interface-name"] = lgi.GLib.Variant("s", ap.device_interface),
["uuid"] = lgi.GLib.Variant("s", generate_uuid()),
["id"] = lgi.GLib.Variant("s", ap.ssid),
["type"] = lgi.GLib.Variant("s", "802-11-wireless"),
["autoconnect"] = lgi.GLib.Variant("b", auto_connect),
},
["ipv4"] = {
["method"] = lgi.GLib.Variant("s", "auto")
},
["ipv6"] = {
["method"] = lgi.GLib.Variant("s", "auto"),
},
["802-11-wireless"] = {
["mode"] = lgi.GLib.Variant("s", "infrastructure"),
},
["802-11-wireless-security"] = s_wsec
}
end
---Scan for access points and create a widget for each one.
function network:scan_access_points()
self._private.access_points = {}
local ap_list = self:get_children_by_id("wifi_ap_list")[1]
self._private.wifi_proxy:RequestScanAsync(function(proxy, context, success, failure)
if failure ~= nil then
self.access_points = { layout = wibox.layout.fixed.vertical }
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
self:emit_signal("NM::ScanFailed", tostring(failure))
self._private.NetworkManagerDeviceWireless:RequestScanAsync(function(proxy, context, success, failure)
if failure then
-- Send an error notification
print("AP Scan failed: ", failure)
return
end
local access_points = self._private.wifi_proxy:GetAllAccessPoints()
-- Get every access point even those who hide their ssid
print(#self._private.NetworkManagerDeviceWireless:GetAllAccessPoints())
for _, ap in ipairs(self._private.NetworkManagerDeviceWireless:GetAllAccessPoints()) do
self._private.access_points = {}
if (not access_point) or (#access_points == 0) then
self.access_points = { layout = wibox.layout.fixed.vertical }
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
end
for _, ap in ipairs(access_points) do
local access_point_proxy = dbus_proxy.Proxy:new {
-- Create a new proxy for every ap
local NetworkManagerAccessPoint = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.AccessPoint",
path = ap
}
if access_point_proxy.Ssid then
local appSsid = access_point_proxy.Ssid or ""
local ssid = NM.utils_ssid_to_utf8(appSsid) or ""
local security = flags_to_security(access_point_proxy.Flags, access_point_proxy.WpaFlags)
local password = ""
local connections = get_access_point_connections(self, ssid)
for _, connection in ipairs(connections) do
if connection.Filename:find(ssid) then
local secrets = connection:GetSecrets("802-11-wireless-security")
if secrets then
password = secrets["802-11-wireless-security"].psk
end
end
--[[ for _, ap2 in ipairs(ap_list.children) do
if ap2.NetworkManagerAccessPoint.HwAddress:match(ap.HwAddress or "") then
goto continue
end
end ]]
table.insert(self._private.access_points, {
ssid = ssid,
security = security,
password = password,
strength = access_point_proxy.Strength,
hw_address = access_point_proxy.HwAddress,
device_interface = self._private.device_proxy.Interface,
device_path = self._private.device_proxy.object_path,
access_point_path = ap
})
print("AP Found: ", NetworkManagerAccessPoint.HwAddress, NM.utils_ssid_to_utf8(NetworkManagerAccessPoint.Ssid),
NetworkManagerAccessPoint.Strength)
-- We are only interested in those with a ssid
if NetworkManagerAccessPoint.Ssid then
ap_list:add(access_point { NetworkManagerAccessPoint = NetworkManagerAccessPoint })
end
end
self.access_points = { layout = wibox.layout.fixed.vertical }
local seen = {}
for _, ap2 in ipairs(self._private.access_points) do
if not seen[ap2.ssid] then
seen[ap2.ssid] = true
table.insert(self.access_points,
access_point.new { access_point = ap2, active = self._private.wifi_proxy.ActiveAccessPoint }.widget)
end
end
table.sort(self._private.access_points, function(a, b)
return a.strength > b.strength
table.sort(ap_list, function(a, b)
return a.NetworkManagerAccessPoint.Strength > b.NetworkManagerAccessPoint.Strength
end)
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
print("AP_Anzahl: ", #ap_list.children)
end, { call_id = "my-id" }, {})
end
function network:toggle()
self.container.visible = not self.container.visible
end
function network:is_ap_active(ap)
print(self._private.wifi_proxy.ActiveAccessPoint)
return ap.path == self._private.wifi_proxy.ActiveAccessPoint
end
function network:disconnect_ap()
self._private.client_proxy:DeactivateConnection(self._private.device_proxy.ActiveConnection)
self._private.NetworkManager:DeactivateConnection(self._private.NetworkManagerDevice.ActiveConnection)
end
function network:connect_ap(ap, pw, auto_connect)
local connections = get_access_point_connections(self, ap.ssid)
local profile = create_profile(ap, pw, auto_connect)
local connections = self:get_access_point_connections(ap.ssid)
local profile = self:create_profile(ap, pw, auto_connect)
if #connections == 0 then
self._private.client_proxy:AddAndActivateConnectionAsync(function(proxy, context, success, failure)
self._private.NetworkManager:AddAndActivateConnectionAsync(function(proxy, context, success, failure)
if failure then
self:emit_signal("NM::AccessPointFailed", tostring(failure))
return
@@ -318,7 +269,7 @@ function network:connect_ap(ap, pw, auto_connect)
end, { call_id = "my-id", profile, ap.device_proxy_path, ap.path })
else
connections[1]:Update(profile)
self._private.client_proxy:ActivateConnectionAsync(function(proxy, context, success, failure)
self._private.NetworkManager:ActivateConnectionAsync(function(proxy, context, success, failure)
if failure then
self:emit_signal("NM::AccessPointFailed", tostring(failure))
return
@@ -337,89 +288,21 @@ function network:toggle_access_point(ap, password, auto_connect)
end
end
function network:toggle_wireless()
local enable = not self._private.client_proxy.WirelessEnabled
---Toggles networking on or off
function network:toggle_wifi()
local enable = not self._private.NetworkManager.WirelessEnabled
if enable then
self._private.client_proxy:Enable(true)
self._private.NetworkManager.Enable(true)
end
self._private.client_proxy:Set("org.freedesktop.NetworkManager", "WirelessEnabled", lgi.GLib.Variant("b", enable))
return enable
self._private.NetworkManager:Set("org.freedesktop.NetworkManager", "WirelessEnabled", lgi.GLib.Variant("b", enable))
self._private.NetworkManager.WirelessEnabled = { signature = "b", value = enable }
end
function network.new(args)
args = args or {}
local ret = gobject {}
gtable.crush(ret, network, true)
ret._private = {}
ret._private.client_proxy = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager",
path = "/org/freedesktop/NetworkManager",
}
ret._private.settings_proxy = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.Settings",
path = "/org/freedesktop/NetworkManager/Settings",
}
local property_proxy = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.DBus.Properties",
path = "/org/freedesktop/NetworkManager",
}
-- dbus proxy signals are in reversed order (function, signal)
property_proxy:connect_signal(function(_, properties, data)
if data.WirelessEnables ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
ret._private.WirelessEnabled = data.WirelessEnabled
ret:emit_signal("NM::WirelessStateChanged", ret._private.WirelessEnabled)
if data.WirelessEnabled then
gtimer {
timeout = 5,
autostart = true,
call_now = false,
single_shot = true,
callback = function()
ret:get_access_points()
end
}
end
end
end, "PropertiesChanged")
get_wifi_proxy(ret)
ret:scan_access_points()
gtimer.delayed_call(function()
ret:emit_signal("NM::WirelessStateChanged", ret._private.client_proxy.WirelessEnabled)
local active_access_point = ret._private.wifi_proxy.ActiveAccessPoint
if ret._private.device_proxy.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,
}
local ssid = NM.utils_ssid_to_utf8(active_access_point_proxy.Ssid)
ret:emit_signal("NM:AccessPointConnected", ssid, active_access_point_proxy.Strength)
end
end)
local network_widget = wibox.widget {
local ret = base.make_widget_from_value(wibox.widget {
{
{
{
@@ -488,6 +371,17 @@ function network.new(args)
},
{
{ -- action buttons
{
dnd_widget {
color = Theme_config.network_manager.power_icon_color,
size = dpi(40)
},
id = "dnd",
widget = wibox.container.place,
valign = "center",
halign = "center"
},
nil,
{ -- refresh
{
{
@@ -512,31 +406,6 @@ function network.new(args)
widget = wibox.container.background,
id = "refresh"
},
nil,
{ -- airplane mode
{
{
image = gcolor.recolor_image(icondir .. "airplane-off.svg",
Theme_config.network_manager.airplane_icon_color),
resize = false,
valign = "center",
halign = "center",
widget = wibox.widget.imagebox,
id = "icon"
},
widget = wibox.container.margin,
margins = dpi(5),
id = "center",
},
border_width = dpi(2),
border_color = Theme_config.network_manager.border_color,
shape = function(cr, width, height)
gshape.rounded_rect(cr, width, height, dpi(4))
end,
bg = Theme_config.network_manager.refresh_bg,
widget = wibox.container.background,
id = "airplane"
},
layout = wibox.layout.align.horizontal
},
widget = wibox.container.margin,
@@ -562,54 +431,82 @@ function network.new(args)
width = dpi(400),
strategy = "exact",
widget = wibox.container.constraint
})
local dnd = ret:get_children_by_id("dnd")[1]:get_widget()
dnd:connect_signal("dnd::toggle", function(enable)
ret:toggle_wifi()
end)
gtable.crush(ret, network, true)
--#region Wifi Proxies
ret._private.NetworkManager = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager",
path = "/org/freedesktop/NetworkManager",
}
local refresh_button = network_widget:get_children_by_id("refresh")[1]
ret._private.NetworkManagerSettings = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.NetworkManager.Settings",
path = "/org/freedesktop/NetworkManager/Settings",
}
refresh_button:buttons(
gtable.join(
awful.button(
{},
1,
nil,
function()
ret:scan_access_points()
end
)
)
)
ret._private.NetworkManagerProperties = dbus_proxy.Proxy:new {
bus = dbus_proxy.Bus.SYSTEM,
name = "org.freedesktop.NetworkManager",
interface = "org.freedesktop.DBus.Properties",
path = "/org/freedesktop/NetworkManager",
}
Hover_signal(refresh_button)
ret._private.NetworkManagerProperties:connect_signal(function(_, properties, data)
if data.WirelessEnables ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
ret._private.WirelessEnabled = data.WirelessEnabled
local airplane_button = network_widget:get_children_by_id("airplane")[1]
ret:emit_signal("NetworkManager::status", ret._private.WirelessEnabled)
print(ret._private.WirelessEnabled)
airplane_button:buttons(
gtable.join(
awful.button(
{},
1,
nil,
function()
if ret:toggle_wireless() then
airplane_button.center.icon.image = gcolor.recolor_image(icondir
.. "airplane-off.svg",
Theme_config.network_manager.airplane_icon_color)
else
airplane_button.center.icon.image = gcolor.recolor_image(icondir
.. "airplane-on.svg",
Theme_config.network_manager.airplane_icon_color)
if data.WirelessEnabled then
gtimer {
timeout = 5,
autostart = true,
call_now = false,
single_shot = true,
callback = function()
ret:scan_access_points()
end
ret:scan_access_points()
end
)
)
)
}
end
end
end, "PropertiesChanged")
Hover_signal(airplane_button)
ret:get_wifi_proxy()
local wifi_margin = network_widget:get_children_by_id("wifi_margin")[1]
local wifi_list = network_widget:get_children_by_id("wifi_list")[1]
local wifi = network_widget:get_children_by_id("wifi")[1].center
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)
--#endregion
--#region Dropdown logic
local wifi_margin = ret:get_children_by_id("wifi_margin")[1]
local wifi_list = ret:get_children_by_id("wifi_list")[1]
local wifi = ret:get_children_by_id("wifi")[1].center
local rubato_timer = rubato.timed {
duration = 0.2,
@@ -620,64 +517,47 @@ function network.new(args)
end
}
wifi_margin:buttons(
gtable.join(
awful.button(
{},
1,
nil,
function()
if wifi_list.forced_height == 0 then
local size = (#ret.access_points * 49) + 1
size = size > 210 and 210 or size
rubato_timer.target = dpi(size)
wifi_margin.wifi_bg.shape = function(cr, width, height)
gshape.partially_rounded_rect(cr, width, height, true, true, false, false, dpi(4))
end
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-up.svg",
Theme_config.network_manager.wifi_icon_color))
else
rubato_timer.target = 0
wifi_margin.wifi_bg.shape = function(cr, width, height)
gshape.partially_rounded_rect(cr, width, height, true, true, true, true, dpi(4))
end
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-down.svg",
Theme_config.network_manager.wifi_icon_color))
wifi_margin:buttons(gtable.join(
awful.button({}, 1, nil,
function()
if wifi_list.forced_height == 0 then
if not ret:get_children_by_id("wifi_ap_list")[1].children then
return
end
local size = (5 * 49) + 1
size = size > 210 and 210 or size
rubato_timer.target = dpi(size)
wifi_margin.wifi_bg.shape = function(cr, width, height)
gshape.partially_rounded_rect(cr, width, height, true, true, false, false, dpi(4))
end
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-up.svg",
Theme_config.network_manager.wifi_icon_color))
else
rubato_timer.target = 0
wifi_margin.wifi_bg.shape = function(cr, width, height)
gshape.partially_rounded_rect(cr, width, height, true, true, true, true, dpi(4))
end
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-down.svg",
Theme_config.network_manager.wifi_icon_color))
end
)
end
)
)
))
--#endregion
ret.widget = awful.popup {
widget = network_widget,
bg = Theme_config.network_manager.bg,
screen = args.screen,
stretch = false,
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
}
local refresh_button = ret:get_children_by_id("refresh")[1]
refresh_button:buttons(gtable.join(
awful.button({}, 1, nil,
function()
ret:scan_access_points()
end
)
))
Hover_signal(refresh_button)
capi.awesome.connect_signal("NM::toggle_container", function()
ret.widget.visible = not ret.widget.visible
ret:scan_access_points()
end)
capi.awesome.connect_signal("NM::toggle_wifi", function()
ret:toggle_wireless()
end)
ret:connect_signal("NM::AccessPointsFound", function(tab)
network_widget:get_children_by_id("wifi_ap_list")[1].children = ret.access_points
end)
return ret
end
function network.mt:__call(...)