From 345eca1efe4694202a45a369dc3d7ec41dd01030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tyrychtr?= Date: Sun, 1 Sep 2024 11:59:47 +0000 Subject: [PATCH] a11y: Set expanded states properly when switching to a submenu --- gtk/gtkmodelbutton.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c index aaf8739078..49b5f379af 100644 --- a/gtk/gtkmodelbutton.c +++ b/gtk/gtkmodelbutton.c @@ -1067,10 +1067,29 @@ switch_menu (GtkModelButton *button) stack = gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK); if (stack != NULL) { + if (button->role == GTK_BUTTON_ROLE_NORMAL) + { + GtkWidget *title_button = gtk_widget_get_first_child (gtk_stack_get_child_by_name (GTK_STACK (stack), button->menu_name)); + gtk_accessible_update_state (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_STATE_EXPANDED, TRUE, + -1); + gtk_accessible_update_state (GTK_ACCESSIBLE (title_button), + GTK_ACCESSIBLE_STATE_EXPANDED, TRUE, + -1); + g_object_set_data (G_OBJECT (title_button), "-gtk-model-button-parent", button); + } + else if (button->role == GTK_BUTTON_ROLE_TITLE) + { + GtkWidget *parent_button = g_object_get_data (G_OBJECT (button), "-gtk-model-button-parent"); + gtk_accessible_update_state (GTK_ACCESSIBLE (parent_button), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); + gtk_accessible_update_state (GTK_ACCESSIBLE (button), + GTK_ACCESSIBLE_STATE_EXPANDED, FALSE, + -1); + g_object_set_data (G_OBJECT (button), "-gtk-model-button-parent", NULL); + } gtk_stack_set_visible_child_name (GTK_STACK (stack), button->menu_name); - gtk_accessible_update_state (GTK_ACCESSIBLE (button), - GTK_ACCESSIBLE_STATE_EXPANDED, TRUE, - -1); } }