From 70b9fde16239f855f985071bb3c60c16f05e59c0 Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Fri, 27 Jun 2025 13:55:27 -0400 Subject: [PATCH] event-editor/multi-choice: Implement GtkAccessible This is needed to have the toggle button communicate with the screen reader to use the parent widget to retrieve accessible information, rather than the toggle button itself. Part-of: --- src/gui/event-editor/gcal-multi-choice.blp | 12 ++------- src/gui/event-editor/gcal-multi-choice.c | 31 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/gui/event-editor/gcal-multi-choice.blp b/src/gui/event-editor/gcal-multi-choice.blp index 8b8c952e..c4210960 100644 --- a/src/gui/event-editor/gcal-multi-choice.blp +++ b/src/gui/event-editor/gcal-multi-choice.blp @@ -2,6 +2,7 @@ using Gtk 4.0; template $GcalMultiChoice: Box { spacing: 6; + accessible-role: spin_button; Button down_button { icon-name: "pan-start-symbolic"; @@ -15,6 +16,7 @@ template $GcalMultiChoice: Box { } ToggleButton button { + accessible-role: none; toggled => $button_toggled_cb() swapped; styles [ @@ -23,16 +25,6 @@ template $GcalMultiChoice: Box { "popup", ] - accessibility { - labelled-by: [ - template, - ]; - - described-by: [ - template, - ]; - } - Stack stack { hexpand: true; vexpand: true; diff --git a/src/gui/event-editor/gcal-multi-choice.c b/src/gui/event-editor/gcal-multi-choice.c index 713b64ff..ff103db7 100644 --- a/src/gui/event-editor/gcal-multi-choice.c +++ b/src/gui/event-editor/gcal-multi-choice.c @@ -73,7 +73,10 @@ enum static guint signals[LAST_SIGNAL] = { 0, }; static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; -G_DEFINE_TYPE (GcalMultiChoice, gcal_multi_choice, GTK_TYPE_BOX) +static void gcal_multi_choice_accessible_init (GtkAccessibleInterface *iface); + +G_DEFINE_TYPE_WITH_CODE (GcalMultiChoice, gcal_multi_choice, GTK_TYPE_BOX, + G_IMPLEMENT_INTERFACE (GTK_TYPE_ACCESSIBLE, gcal_multi_choice_accessible_init)) /* * Auxiliary methods @@ -195,15 +198,15 @@ update_sensitivity (GcalMultiChoice *self) gtk_widget_set_can_target (self->button, has_popup); - gtk_accessible_update_property (GTK_ACCESSIBLE (self->button), + gtk_accessible_update_property (GTK_ACCESSIBLE (self), GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, has_popup, -1); if (self->popover != NULL) - gtk_accessible_update_relation (GTK_ACCESSIBLE (self->button), + gtk_accessible_update_relation (GTK_ACCESSIBLE (self), GTK_ACCESSIBLE_RELATION_CONTROLS, self->popover, NULL, -1); else - gtk_accessible_reset_relation (GTK_ACCESSIBLE (self->button), + gtk_accessible_reset_relation (GTK_ACCESSIBLE (self), GTK_ACCESSIBLE_RELATION_CONTROLS); } @@ -466,6 +469,19 @@ gcal_multi_choice_grab_focus (GtkWidget *widget) return gtk_widget_grab_focus (self->button); } +/* + * GtkAccessible overrides + */ + +static gboolean +gcal_multi_choice_accessible_get_platform_state (GtkAccessible *accessible, + GtkAccessiblePlatformState state) +{ + GcalMultiChoice *self = GCAL_MULTI_CHOICE (accessible); + + return gtk_accessible_get_platform_state (GTK_ACCESSIBLE (self->button), state); +} + /* * Init */ @@ -552,6 +568,12 @@ gcal_multi_choice_class_init (GcalMultiChoiceClass *class) gtk_widget_class_set_css_name (widget_class, "navigator"); } +static void +gcal_multi_choice_accessible_init (GtkAccessibleInterface *iface) +{ + iface->get_platform_state = gcal_multi_choice_accessible_get_platform_state; +} + static void gcal_multi_choice_init (GcalMultiChoice *self) { @@ -733,3 +755,4 @@ gcal_multi_choice_get_popover (GcalMultiChoice *self) return GTK_POPOVER (self->popover); } +