From 1e0594ee3a338c1f753df8c863d5cb56cdfda41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 20 Feb 2023 09:58:01 -0800 Subject: [PATCH 1/4] DisplayWidget: show separate icon for VPN --- src/Indicator.vala | 3 +- src/Widgets/DisplayWidget.vala | 60 +++++++++++++++++++++++++++------- src/Widgets/PopoverWidget.vala | 19 ----------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/Indicator.vala b/src/Indicator.vala index 057845f9..85264e21 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -39,7 +39,6 @@ public class Network.Indicator : Wingpanel.Indicator { popover_widget = new Widgets.PopoverWidget (is_in_session); popover_widget.notify["state"].connect (on_state_changed); - popover_widget.notify["secure"].connect (on_state_changed); popover_widget.notify["extra-info"].connect (on_state_changed); popover_widget.settings_shown.connect (() => { close (); }); @@ -75,7 +74,7 @@ public class Network.Indicator : Wingpanel.Indicator { assert (popover_widget != null); assert (display_widget != null); - display_widget.update_state (popover_widget.state, popover_widget.secure, popover_widget.extra_info); + display_widget.update_state (popover_widget.state, popover_widget.extra_info); update_tooltip (); } diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 2302b945..f8b9894c 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -20,6 +20,9 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { private Gtk.Image image; private Gtk.Label extra_info_label; private Gtk.Revealer extra_info_revealer; + private Gtk.Revealer vpn_revealer; + private NM.Client nm_client; + private NM.VpnConnection? active_vpn_connection = null; private uint wifi_animation_timeout; private int wifi_animation_state = 0; @@ -40,11 +43,29 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { }; extra_info_revealer.add (extra_info_label); + var vpn_image = new Gtk.Image.from_icon_name ("network-vpn-connected-symbolic", Gtk.IconSize.MENU) { + margin_start = 6 + }; + + vpn_revealer = new Gtk.Revealer () { + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + vpn_revealer.add (vpn_image); + add (image); add (extra_info_revealer); + + try { + nm_client = new NM.Client (); + + update_vpn_connection (); + nm_client.notify["active-connections"].connect (update_vpn_connection); + } catch (Error e) { + critical (e.message); + } } - public void update_state (Network.State state, bool secure, string? extra_info = null) { + public void update_state (Network.State state, string? extra_info = null) { extra_info_revealer.reveal_child = extra_info != null; extra_info_label.label = extra_info; @@ -66,19 +87,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { image.icon_name = "network-wired-acquiring-symbolic"; break; case Network.State.CONNECTED_WIRED: - image.icon_name = "network-wired-%ssymbolic".printf (secure? "secure-" : ""); + image.icon_name = "network-wired-symbolic"; break; case Network.State.CONNECTED_WIFI_WEAK: - image.icon_name = "network-wireless-signal-weak-%ssymbolic".printf (secure? "secure-" : ""); + image.icon_name = "network-wireless-signal-weak-symbolic"; break; case Network.State.CONNECTED_WIFI_OK: - image.icon_name = "network-wireless-signal-ok-%ssymbolic".printf (secure? "secure-" : ""); + image.icon_name = "network-wireless-signal-ok-symbolic"; break; case Network.State.CONNECTED_WIFI_GOOD: - image.icon_name = "network-wireless-signal-good-%ssymbolic".printf (secure? "secure-" : ""); + image.icon_name = "network-wireless-signal-good-symbolic"; break; case Network.State.CONNECTED_WIFI_EXCELLENT: - image.icon_name = "network-wireless-signal-excellent-%ssymbolic".printf (secure? "secure-" : ""); + image.icon_name = "network-wireless-signal-excellent-symbolic"; break; case Network.State.CONNECTING_WIFI: wifi_animation_timeout = Timeout.add (300, () => { @@ -98,21 +119,21 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { strength = "excellent"; break; } - image.icon_name = "network-wireless-signal-" + strength + (secure? "-secure" : "") + "-symbolic"; + image.icon_name = "network-wireless-signal-" + strength + "-symbolic"; return true; }); break; case Network.State.CONNECTED_MOBILE_WEAK: - image.icon_name = "network-cellular-signal-weak-%ssymbolic".printf (secure ? "secure-" : ""); + image.icon_name = "network-cellular-signal-weak-symbolic"; break; case Network.State.CONNECTED_MOBILE_OK: - image.icon_name = "network-cellular-signal-ok-%ssymbolic".printf (secure ? "secure-" : ""); + image.icon_name = "network-cellular-signal-ok-symbolic"; break; case Network.State.CONNECTED_MOBILE_GOOD: - image.icon_name = "network-cellular-signal-good-%ssymbolic".printf (secure ? "secure-" : ""); + image.icon_name = "network-cellular-signal-good-symbolic"; break; case Network.State.CONNECTED_MOBILE_EXCELLENT: - image.icon_name = "network-cellular-signal-excellent-%ssymbolic".printf (secure ? "secure-" : ""); + image.icon_name = "network-cellular-signal-excellent-symbolic"; break; case Network.State.CONNECTING_MOBILE: cellular_animation_timeout = Timeout.add (300, () => { @@ -133,7 +154,7 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; } - image.icon_name = "network-cellular-signal-" + strength + (secure ? "secure-" : "") + "-symbolic"; + image.icon_name = "network-cellular-signal-" + strength + "-symbolic"; return true; }); break; @@ -153,4 +174,19 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { break; } } + + private void update_vpn_connection () { + active_vpn_connection = null; + + nm_client.get_active_connections ().foreach ((connection) => { + if (active_vpn_connection == null && connection.vpn) { + active_vpn_connection = (NM.VpnConnection) connection; + + vpn_revealer.reveal_child = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; + active_vpn_connection.vpn_state_changed.connect (() => { + vpn_revealer.reveal_child = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; + }); + } + }); + } } diff --git a/src/Widgets/PopoverWidget.vala b/src/Widgets/PopoverWidget.vala index a394452b..1d65ae13 100644 --- a/src/Widgets/PopoverWidget.vala +++ b/src/Widgets/PopoverWidget.vala @@ -18,11 +18,9 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid { public NM.Client nm_client { get; construct; } - private NM.VpnConnection? active_vpn_connection = null; public GLib.List? network_interface { get; private owned set; } - public bool secure { private set; get; default = false; } public string? extra_info { private set; get; default = null; } public Network.State state { private set; get; default = Network.State.CONNECTING_WIRED; } @@ -139,7 +137,6 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid { toggle_revealer.reveal_child = other_box.get_children () != null; show_all (); - update_vpn_connection (); hidden_item.clicked.connect (() => { bool found = false; @@ -154,7 +151,6 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid { /* Monitor network manager */ nm_client.device_added.connect (device_added_cb); nm_client.device_removed.connect (device_removed_cb); - nm_client.notify["active-connections"].connect (update_vpn_connection); nm_client.notify["networking-enabled"].connect (update_state); vpn_interface.notify["state"].connect (update_state); @@ -324,19 +320,4 @@ public class Network.Widgets.PopoverWidget : Gtk.Grid { state = next_state; } } - - private void update_vpn_connection () { - active_vpn_connection = null; - - nm_client.get_active_connections ().foreach ((ac) => { - if (active_vpn_connection == null && ac.vpn) { - active_vpn_connection = (NM.VpnConnection) ac; - - secure = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; - active_vpn_connection.vpn_state_changed.connect (() => { - secure = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; - }); - } - }); - } } From d69062528a0504211dcf1dee3ad50f74752f369c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 20 Feb 2023 10:00:02 -0800 Subject: [PATCH 2/4] Update network.appdata.xml.in --- data/network.appdata.xml.in | 1 + 1 file changed, 1 insertion(+) diff --git a/data/network.appdata.xml.in b/data/network.appdata.xml.in index a1322f27..f2faafe3 100644 --- a/data/network.appdata.xml.in +++ b/data/network.appdata.xml.in @@ -17,6 +17,7 @@ + Separate VPN icon from network icon VPN switch jumps due to WiFi list height change Network adapter names aren't truncated From bc427464acb44740cc1f8e87116bc756953e9536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 22 Feb 2023 10:42:53 -0800 Subject: [PATCH 3/4] Connect/disconnect --- src/Widgets/DisplayWidget.vala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index a70047f8..1568cdd1 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -176,17 +176,25 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { } private void update_vpn_connection () { + active_vpn_connection.vpn_state_changed.disconnect (reveal_vpn); active_vpn_connection = null; nm_client.get_active_connections ().foreach ((connection) => { if (active_vpn_connection == null && connection.vpn) { active_vpn_connection = (NM.VpnConnection) connection; - - vpn_revealer.reveal_child = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; - active_vpn_connection.vpn_state_changed.connect (() => { - vpn_revealer.reveal_child = active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED; - }); + active_vpn_connection.vpn_state_changed.connect (reveal_vpn); } }); + + reveal_vpn (); + } + + private void reveal_vpn () { + if (active_vpn_connection != null && active_vpn_connection.get_vpn_state () == NM.VpnConnectionState.ACTIVATED) { + vpn_revealer.reveal_child = true; + } else { + vpn_revealer.reveal_child = false; + } + } } From 5f4e288eaa0778ee41dac90b493b5feeed37123c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 22 Feb 2023 10:43:17 -0800 Subject: [PATCH 4/4] remove extra line --- src/Widgets/DisplayWidget.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 1568cdd1..3b1771c0 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -195,6 +195,5 @@ public class Network.Widgets.DisplayWidget : Gtk.Grid { } else { vpn_revealer.reveal_child = false; } - } }