[libadwaita/wip/exalm/view-switcher-button: 2/2] view-switcher-button: Only set mnemonic for the visible label




commit 7173467772c54349cb7373bad1119cf47707d057
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Oct 29 22:01:31 2021 +0500

    view-switcher-button: Only set mnemonic for the visible label
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/303

 src/adw-view-switcher-button.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/src/adw-view-switcher-button.c b/src/adw-view-switcher-button.c
index 519e43bd..df5d3558 100644
--- a/src/adw-view-switcher-button.c
+++ b/src/adw-view-switcher-button.c
@@ -68,6 +68,35 @@ adw_view_switcher_button_switch_timeout (AdwViewSwitcherButton *self)
   return G_SOURCE_REMOVE;
 }
 
+static void
+update_mnemonic (AdwViewSwitcherButton *self)
+{
+  GtkLabel *label;
+
+  g_assert (ADW_IS_VIEW_SWITCHER_BUTTON (self));
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self))) {
+    if (self->orientation == GTK_ORIENTATION_VERTICAL)
+      label = self->vertical_label_active;
+    else
+      label = self->horizontal_label_active;
+  } else {
+    if (self->orientation == GTK_ORIENTATION_VERTICAL)
+      label = self->vertical_label_inactive;
+    else
+      label = self->horizontal_label_inactive;
+  }
+
+  gtk_label_set_mnemonic_widget (self->horizontal_label_active,
+                                 (label == self->horizontal_label_active) ? GTK_WIDGET (self) : NULL);
+  gtk_label_set_mnemonic_widget (self->horizontal_label_inactive,
+                                 (label == self->horizontal_label_inactive) ? GTK_WIDGET (self) : NULL);
+  gtk_label_set_mnemonic_widget (self->vertical_label_active,
+                                 (label == self->vertical_label_active) ? GTK_WIDGET (self) : NULL);
+  gtk_label_set_mnemonic_widget (self->vertical_label_inactive,
+                                 (label == self->vertical_label_inactive) ? GTK_WIDGET (self) : NULL);
+}
+
 static void
 active_changed_cb (AdwViewSwitcherButton *self)
 {
@@ -80,6 +109,8 @@ active_changed_cb (AdwViewSwitcherButton *self)
     gtk_stack_set_visible_child (self->horizontal_label_stack, GTK_WIDGET (self->horizontal_label_inactive));
     gtk_stack_set_visible_child (self->vertical_label_stack, GTK_WIDGET (self->vertical_label_inactive));
   }
+
+  update_mnemonic (self);
 }
 
 static void
@@ -123,6 +154,8 @@ set_orientation (AdwViewSwitcherButton *self,
                                GTK_WIDGET (self->orientation == GTK_ORIENTATION_VERTICAL ?
                                              self->vertical_box :
                                              self->horizontal_box));
+
+  update_mnemonic (self);
 }
 
 static gchar *
@@ -368,11 +401,6 @@ adw_view_switcher_button_init (AdwViewSwitcherButton *self)
 
   gtk_widget_set_focus_on_click (GTK_WIDGET (self), FALSE);
 
-  gtk_label_set_mnemonic_widget (self->horizontal_label_active, GTK_WIDGET (self));
-  gtk_label_set_mnemonic_widget (self->horizontal_label_inactive, GTK_WIDGET (self));
-  gtk_label_set_mnemonic_widget (self->vertical_label_active, GTK_WIDGET (self));
-  gtk_label_set_mnemonic_widget (self->vertical_label_inactive, GTK_WIDGET (self));
-
   active_changed_cb (self);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]