From 75c3e11708d4b1fbf8bc78a3dba30b128a82173a Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 20 May 2021 16:34:38 +0200 Subject: [PATCH] bluetooth: Fix bluetooth switch transitions This commit changes the switch to do a proper delayed state change using the state-set signal. Also changed is that we always update the switch state rather than avoiding an update when it is not powered. Avoiding this update was introduced in commit 4a009da483 (bluetooth: Don't change the switch status when transitioning), however, the current implementation causes us to get stuck in the wrong visual state sometimes. Also, with this patch I am unable to see any visual glitch on hardware that should be affected, and even if there was a glitch, getting the final state right is more important. Closes: #607, #1272 --- panels/bluetooth/cc-bluetooth-panel.c | 25 +++++++++---------------- panels/bluetooth/cc-bluetooth-panel.ui | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/panels/bluetooth/cc-bluetooth-panel.c b/panels/bluetooth/cc-bluetooth-panel.c index a95ea58fbf..f346d36dcb 100644 --- a/panels/bluetooth/cc-bluetooth-panel.c +++ b/panels/bluetooth/cc-bluetooth-panel.c @@ -104,11 +104,8 @@ airplane_mode_changed_cb (GObject *source_object, } static void -enable_switch_changed_cb (CcBluetoothPanel *self) +enable_switch_state_set_cb (CcBluetoothPanel *self, gboolean state) { - gboolean state; - - state = gtk_switch_get_active (self->enable_switch); g_debug ("Power switched to %s", state ? "on" : "off"); g_dbus_proxy_call (self->properties, "Set", @@ -117,20 +114,19 @@ enable_switch_changed_cb (CcBluetoothPanel *self) G_DBUS_CALL_FLAGS_NONE, -1, cc_panel_get_cancellable (CC_PANEL (self)), - airplane_mode_changed_cb, GUINT_TO_POINTER(state)); + airplane_mode_changed_cb, self); } static void adapter_status_changed_cb (CcBluetoothPanel *self) { GtkAlign valign; - gboolean sensitive, powered, change_powered; + gboolean sensitive, powered; GtkWidget *page; g_debug ("Updating airplane mode: BluetoothHasAirplaneMode %d, BluetoothHardwareAirplaneMode %d, BluetoothAirplaneMode %d, AirplaneMode %d", self->has_airplane_mode, self->hardware_airplane_mode, self->bt_airplane_mode, self->airplane_mode); - change_powered = TRUE; valign = GTK_ALIGN_CENTER; if (self->has_airplane_mode == FALSE) { @@ -150,9 +146,9 @@ adapter_status_changed_cb (CcBluetoothPanel *self) page = GTK_WIDGET (self->airplane_box); } else if (self->bt_airplane_mode || !bluetooth_settings_widget_get_default_adapter_powered (self->settings_widget)) { - g_debug ("Default adapter is unpowered, but should be available"); + g_debug ("Default adapter is unpowered"); sensitive = TRUE; - change_powered = FALSE; + powered = FALSE; page = GTK_WIDGET (self->disabled_box); } else { g_debug ("Bluetooth is available and powered"); @@ -164,12 +160,9 @@ adapter_status_changed_cb (CcBluetoothPanel *self) gtk_widget_set_valign (GTK_WIDGET (self->stack), valign); gtk_widget_set_sensitive (GTK_WIDGET (self->header_box), sensitive); - - if (change_powered) { - g_signal_handlers_block_by_func (self->enable_switch, enable_switch_changed_cb, self); - gtk_switch_set_active (self->enable_switch, powered); - g_signal_handlers_unblock_by_func (self->enable_switch, enable_switch_changed_cb, self); - } + g_signal_handlers_block_by_func (self->enable_switch, enable_switch_state_set_cb, self); + gtk_switch_set_state (self->enable_switch, powered); + g_signal_handlers_unblock_by_func (self->enable_switch, enable_switch_state_set_cb, self); gtk_stack_set_visible_child (self->stack, page); } @@ -249,7 +242,7 @@ cc_bluetooth_panel_class_init (CcBluetoothPanelClass *klass) gtk_widget_class_bind_template_callback (widget_class, adapter_status_changed_cb); gtk_widget_class_bind_template_callback (widget_class, airplane_mode_off_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, enable_switch_changed_cb); + gtk_widget_class_bind_template_callback (widget_class, enable_switch_state_set_cb); gtk_widget_class_bind_template_callback (widget_class, panel_changed_cb); } diff --git a/panels/bluetooth/cc-bluetooth-panel.ui b/panels/bluetooth/cc-bluetooth-panel.ui index c4f36cecb9..6825f835c6 100644 --- a/panels/bluetooth/cc-bluetooth-panel.ui +++ b/panels/bluetooth/cc-bluetooth-panel.ui @@ -186,7 +186,7 @@ True True center - + False -- GitLab