From 6f93af52865d7fad6333601b5aff84391dee81bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 2 May 2025 18:46:19 -0700 Subject: [PATCH 1/4] AirplaneMode: use RFKill Set state based on rfkill device change Change to airplane mode less namespace Try all rather than any All hardware OR all software --- src/Indicator.vala | 24 ++++++++++-------------- src/Widgets/PopoverWidget.vala | 1 - src/rfkill.vala | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Indicator.vala b/src/Indicator.vala index fd71ded81..e54a05b79 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -22,6 +22,7 @@ public class Network.Indicator : Wingpanel.Indicator { NetworkMonitor network_monitor; + private RFKillManager rfkill; private Gtk.GestureMultiPress gesture_click; private SimpleAction airplane_action; @@ -65,19 +66,16 @@ public class Network.Indicator : Wingpanel.Indicator { }); } - airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (popover_widget.nm_client.networking_get_enabled ())); + rfkill = new RFKillManager (); + rfkill.open (); + + airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (rfkill.get_airplane_mode ())); airplane_action.activate.connect (() => { - popover_widget.nm_client.dbus_call.begin ( - NM.DBUS_PATH, NM.DBUS_INTERFACE, - "Enable", new Variant.tuple ({new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ())}), - null, -1, null, (obj, res) => { - try { - ((NM.Client) obj).dbus_set_property.end (res); - } catch (Error e) { - warning ("Error setting airplane mode: %s", e.message); - } - } - ); + rfkill.set_software_lock (ALL, !rfkill.get_airplane_mode ()); + }); + + rfkill.device_changed.connect (() => { + airplane_action.set_state (new Variant.boolean (rfkill.get_airplane_mode ())); }); var action_group = (SimpleActionGroup) popover_widget.get_action_group ("network"); @@ -102,8 +100,6 @@ public class Network.Indicator : Wingpanel.Indicator { display_widget.update_state (popover_widget.state, popover_widget.secure, popover_widget.extra_info); - airplane_action.set_state (new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ())); - update_tooltip (); } diff --git a/src/Widgets/PopoverWidget.vala b/src/Widgets/PopoverWidget.vala index f77e48369..7bbfc74cf 100644 --- a/src/Widgets/PopoverWidget.vala +++ b/src/Widgets/PopoverWidget.vala @@ -65,7 +65,6 @@ public class Network.Widgets.PopoverWidget : Gtk.Box { var action_group = new SimpleActionGroup (); action_group.action_state_changed.connect ((action_name, state) => { - critical ("got a state change"); if (action_name == "airplane-mode") { if (state.get_boolean ()) { airplane_toggle.icon_name = "airplane-mode-symbolic"; diff --git a/src/rfkill.vala b/src/rfkill.vala index 935892f52..ab505c86c 100644 --- a/src/rfkill.vala +++ b/src/rfkill.vala @@ -80,6 +80,29 @@ public class RFKillManager : Object { return devices; } + /* + * Checks for Airplane mode + * Setting airplane mode from here does all software lock, whereas setting + * from a key press does all hardware lock. We need one of these two things— + * all devices to be locked somehow—to consider it Airplane Mode + */ + public bool get_airplane_mode () { + var all_hardware_locked = true; + var all_software_locked = true; + + foreach (unowned var device in get_devices ()) { + if (!device.software_lock) { + all_software_locked = false; + } + + if (!device.hardware_lock) { + all_hardware_locked = false; + } + } + + return all_hardware_locked || all_software_locked; + } + public void set_software_lock (RFKillDeviceType type, bool lock_enabled) { var event = RFKillEvent (); event.type = type; From 5c5038e384fd272740f5b1cbf7dfc24e5799e62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 3 May 2025 12:37:25 -0700 Subject: [PATCH 2/4] Skip bluetooth --- src/Indicator.vala | 6 +++--- src/rfkill.vala | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/Indicator.vala b/src/Indicator.vala index e54a05b79..eda2b30e3 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -69,13 +69,13 @@ public class Network.Indicator : Wingpanel.Indicator { rfkill = new RFKillManager (); rfkill.open (); - airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (rfkill.get_airplane_mode ())); + airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (rfkill.airplane_mode)); airplane_action.activate.connect (() => { - rfkill.set_software_lock (ALL, !rfkill.get_airplane_mode ()); + rfkill.airplane_mode = !rfkill.airplane_mode; }); rfkill.device_changed.connect (() => { - airplane_action.set_state (new Variant.boolean (rfkill.get_airplane_mode ())); + airplane_action.set_state (new Variant.boolean (rfkill.airplane_mode)); }); var action_group = (SimpleActionGroup) popover_widget.get_action_group ("network"); diff --git a/src/rfkill.vala b/src/rfkill.vala index ab505c86c..c7a42208b 100644 --- a/src/rfkill.vala +++ b/src/rfkill.vala @@ -81,26 +81,42 @@ public class RFKillManager : Object { } /* - * Checks for Airplane mode + * Toggle Airplane Mode + * + * Modern mobile platforms don't disable Bluetooth, we skip it too + * * Setting airplane mode from here does all software lock, whereas setting * from a key press does all hardware lock. We need one of these two things— * all devices to be locked somehow—to consider it Airplane Mode */ - public bool get_airplane_mode () { - var all_hardware_locked = true; - var all_software_locked = true; - - foreach (unowned var device in get_devices ()) { - if (!device.software_lock) { - all_software_locked = false; + public bool airplane_mode { + get { + var all_hardware_locked = true; + var all_software_locked = true; + + foreach (unowned var device in get_devices ()) { + if (device.device_type == BLUETOOTH) { + continue; + } + + if (!device.software_lock) { + all_software_locked = false; + } + + if (!device.hardware_lock) { + all_hardware_locked = false; + } } - if (!device.hardware_lock) { - all_hardware_locked = false; - } + return all_hardware_locked || all_software_locked; } - return all_hardware_locked || all_software_locked; + set { + set_software_lock (WLAN, value); + set_software_lock (UWB, value); + set_software_lock (WIMAX, value); + set_software_lock (WMAN, value); + } } public void set_software_lock (RFKillDeviceType type, bool lock_enabled) { From 95b2df8b66ab0c4d9b2c570af0872cec49218b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 3 May 2025 12:45:55 -0700 Subject: [PATCH 3/4] Turn bluetooth on, not off --- src/rfkill.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rfkill.vala b/src/rfkill.vala index c7a42208b..2bbb07210 100644 --- a/src/rfkill.vala +++ b/src/rfkill.vala @@ -116,6 +116,11 @@ public class RFKillManager : Object { set_software_lock (UWB, value); set_software_lock (WIMAX, value); set_software_lock (WMAN, value); + + // Some hardware keys still turn off bluetooth + if (value) { + set_software_lock (BLUETOOTH, value); + } } } From 6c7e7e48720db4eec8e1620ac26e1ccbcffbbb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 3 May 2025 12:46:48 -0700 Subject: [PATCH 4/4] inverted logic --- src/rfkill.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rfkill.vala b/src/rfkill.vala index 2bbb07210..4b9683c96 100644 --- a/src/rfkill.vala +++ b/src/rfkill.vala @@ -118,8 +118,8 @@ public class RFKillManager : Object { set_software_lock (WMAN, value); // Some hardware keys still turn off bluetooth - if (value) { - set_software_lock (BLUETOOTH, value); + if (!value) { + set_software_lock (BLUETOOTH, false); } } }