From efc595cccd4a4c25a78a4466d9894d0ae4c13d43 Mon Sep 17 00:00:00 2001 From: velsinki <112010-velsinki@users.noreply.gitlab.gnome.org> Date: Tue, 25 Apr 2023 01:35:13 +0200 Subject: sharing: Fix visual bug for active indicators The switch for the current network was only updated to TRUE after a network change. However, if a new network was not enabled, the switch should be set to FALSE. This is now properly handled. Furthermore, the Off/Enabled/Active indicator was also inconsistent after network changes due to the is_visible check failing sometimes, even after changing to an already enabled network. Because the actual current network state is now better tracked, we can just check the state of the switch instead. --- panels/sharing/cc-sharing-networks.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/panels/sharing/cc-sharing-networks.c b/panels/sharing/cc-sharing-networks.c index 7b977f585..2ef502b42 100644 --- a/panels/sharing/cc-sharing-networks.c +++ b/panels/sharing/cc-sharing-networks.c @@ -85,8 +85,7 @@ cc_sharing_networks_update_status (CcSharingNetworks *self) if (self->networks == NULL) status = CC_SHARING_STATUS_OFF; - else if (gtk_widget_is_visible (self->current_switch) && - gtk_switch_get_active (GTK_SWITCH (self->current_switch))) + else if (gtk_switch_get_active (GTK_SWITCH (self->current_switch))) status = CC_SHARING_STATUS_ACTIVE; else status = CC_SHARING_STATUS_ENABLED; @@ -280,7 +279,7 @@ static void cc_sharing_update_networks_box (CcSharingNetworks *self) { GtkWidget *child; - gboolean current_visible; + gboolean current_visible, current_network_enabled = FALSE; const char *current_network; GList *l; @@ -334,11 +333,7 @@ cc_sharing_update_networks_box (CcSharingNetworks *self) GtkWidget *row; if (g_strcmp0 (net->uuid, current_network) == 0) { - g_signal_handlers_block_by_func (self->current_switch, - cc_sharing_networks_enable_network, self); - gtk_switch_set_active (GTK_SWITCH (self->current_switch), TRUE); - g_signal_handlers_unblock_by_func (self->current_switch, - cc_sharing_networks_enable_network, self); + current_network_enabled = TRUE; continue; } @@ -350,6 +345,12 @@ cc_sharing_update_networks_box (CcSharingNetworks *self) gtk_list_box_insert (GTK_LIST_BOX (self->listbox), row, -1); } + g_signal_handlers_block_by_func (self->current_switch, + cc_sharing_networks_enable_network, self); + gtk_switch_set_active (GTK_SWITCH (self->current_switch), current_network_enabled); + g_signal_handlers_unblock_by_func (self->current_switch, + cc_sharing_networks_enable_network, self); + if (self->networks == NULL && !current_visible) { gtk_widget_set_visible (self->no_network_row, TRUE); -- cgit v1.2.1