gtk4-demo: Some a11y improvements
authorMatthias Clasen <mclasen@redhat.com>
Sun, 11 Jun 2023 11:04:56 +0000 (07:04 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 12 Jun 2023 00:29:25 +0000 (20:29 -0400)
Add some labels in the pickers demo.

demos/gtk-demo/assistant.c
demos/gtk-demo/listbox_controls.ui
demos/gtk-demo/main.c
demos/gtk-demo/main.ui
demos/gtk-demo/password_entry.c
demos/gtk-demo/pickers.c

index 322cd5c944f17ab0ee9d84565470b265172b23a1..1bb260d99da0e361b1a208b48c26f6e57d1bf53b 100644 (file)
@@ -162,6 +162,10 @@ create_page4 (GtkWidget *assistant)
   gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), progress_bar, GTK_ASSISTANT_PAGE_PROGRESS);
   gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), progress_bar, "Applying changes");
 
+  gtk_accessible_update_property (GTK_ACCESSIBLE (progress_bar),
+                                  GTK_ACCESSIBLE_PROPERTY_LABEL, "Applying changes",
+                                  -1);
+
   /* This prevents the assistant window from being
    * closed while we're "busy" applying changes.
    */
index ab4419e54db825947445f1f7aa060472abf1b378..2d833ab32e40076bce711a864137397412db085d 100644 (file)
@@ -49,6 +49,7 @@
                                 <property name="halign">start</property>
                                 <property name="valign">center</property>
                                 <property name="hexpand">1</property>
+                                <property name="mnemonic-widget">switch</property>
                               </object>
                             </child>
                             <child>
@@ -73,6 +74,7 @@
                                 <property name="halign">start</property>
                                 <property name="valign">center</property>
                                 <property name="hexpand">1</property>
+                                <property name="mnemonic-widget">check</property>
                               </object>
                             </child>
                             <child>
                                 <property name="margin-start">10</property>
                                 <property name="margin-end">10</property>
                                 <property name="opacity">0</property>
+                                <property name="accessible-role">status</property>
                               </object>
                             </child>
                           </object>
                                   <property name="halign">start</property>
                                   <property name="valign">center</property>
                                   <property name="hexpand">1</property>
+                                  <property name="mnemonic-widget">scale</property>
                                 </object>
                               </child>
                               <child>
-                                <object class="GtkScale">
+                                <object class="GtkScale" id="scale">
                                   <property name="halign">end</property>
                                   <property name="valign">center</property>
                                   <property name="draw-value">0</property>
                                   <property name="halign">start</property>
                                   <property name="valign">center</property>
                                   <property name="hexpand">1</property>
+                                  <property name="mnemonic-widget">spin</property>
                                 </object>
                               </child>
                               <child>
-                                <object class="GtkSpinButton">
+                                <object class="GtkSpinButton" id="spin">
                                   <property name="halign">end</property>
                                   <property name="valign">center</property>
                                   <property name="adjustment">
                                   <property name="halign">start</property>
                                   <property name="valign">center</property>
                                   <property name="hexpand">1</property>
+                                  <property name="mnemonic-widget">dropdown</property>
                                 </object>
                               </child>
                               <child>
-                                <object class="GtkDropDown">
+                                <object class="GtkDropDown" id="dropdown">
                                   <property name="halign">end</property>
                                   <property name="valign">center</property>
                                   <property name="model">
                                   <property name="halign">start</property>
                                   <property name="valign">center</property>
                                   <property name="hexpand">1</property>
+                                  <property name="mnemonic-widget">entry</property>
                                 </object>
                               </child>
                               <child>
-                                <object class="GtkEntry">
+                                <object class="GtkEntry" id="entry">
                                   <property name="halign">end</property>
                                   <property name="valign">center</property>
                                   <property name="placeholder-text">Type here…</property>
index 430091fb0024abcb663d065ba03ca3358d983485..5957e751d3f1446f1835d431597c21677de454f4 100644 (file)
@@ -18,7 +18,6 @@
 #include <string.h>
 
 #include "config.h"
-
 #include <gtk/gtk.h>
 #include <glib/gstdio.h>
 
@@ -268,9 +267,9 @@ activate_run (GSimpleAction *action,
 }
 
 static GtkWidget *
-display_image (const char  *format,
-               const char  *resource,
-               char       **label)
+display_image (const char *format,
+               const char *resource,
+               GtkWidget  *label)
 {
   GtkWidget *sw, *image;
 
@@ -280,13 +279,17 @@ display_image (const char  *format,
   sw = gtk_scrolled_window_new ();
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), image);
 
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (image),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
+                                  -1);
+
   return sw;
 }
 
 static GtkWidget *
-display_images (const char  *format,
-                const char  *resource_dir,
-                char       **label)
+display_images (const char *format,
+                const char *resource_dir,
+                GtkWidget  *label)
 {
   char **resources;
   GtkWidget *grid;
@@ -325,15 +328,19 @@ display_images (const char  *format,
 
   g_strfreev (resources);
 
-  *label = g_strdup ("Images");
+  gtk_label_set_label (GTK_LABEL (label), "Images");
+
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (grid),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
+                                  -1);
 
   return sw;
 }
 
 static GtkWidget *
-display_text (const char  *format,
-              const char  *resource,
-              char       **label)
+display_text (const char *format,
+              const char *resource,
+              GtkWidget  *label)
 {
   GtkTextBuffer *buffer;
   GtkWidget *textview, *sw;
@@ -368,6 +375,10 @@ display_text (const char  *format,
 
   gtk_text_view_set_buffer (GTK_TEXT_VIEW (textview), buffer);
 
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (textview),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
+                                  -1);
+
   sw = gtk_scrolled_window_new ();
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                   GTK_POLICY_AUTOMATIC,
@@ -378,15 +389,19 @@ display_text (const char  *format,
 }
 
 static GtkWidget *
-display_video (const char  *format,
-               const char  *resource,
-               char       **label)
+display_video (const char *format,
+               const char *resource,
+               GtkWidget  *label)
 {
   GtkWidget *video;
 
   video = gtk_video_new_for_resource (resource);
   gtk_video_set_loop (GTK_VIDEO (video), TRUE);
 
+  gtk_accessible_update_relation (GTK_ACCESSIBLE (video),
+                                  GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
+                                  -1);
+
   return video;
 }
 
@@ -408,9 +423,9 @@ display_nothing (const char *resource)
 static struct {
   const char *extension;
   const char *format;
-  GtkWidget * (* display_func) (const char  *format,
-                                const char  *resource,
-                                char       **label);
+  GtkWidget * (* display_func) (const char *format,
+                                const char *resource,
+                                GtkWidget  *label);
 } display_funcs[] = {
   { ".gif", NULL, display_image },
   { ".jpg", NULL, display_image },
@@ -433,7 +448,6 @@ add_data_tab (const char *demoname)
   char **resources;
   GtkWidget *widget, *label;
   guint i, j;
-  char *label_string;
 
   resource_dir = g_strconcat ("/", demoname, NULL);
   resources = g_resources_enumerate_children (resource_dir, 0, NULL);
@@ -453,23 +467,21 @@ add_data_tab (const char *demoname)
             break;
         }
 
-      label_string = NULL;
+      label = gtk_label_new (resources[i]);
 
       if (j < G_N_ELEMENTS (display_funcs))
         widget = display_funcs[j].display_func (display_funcs[j].format,
                                                 resource_name,
-                                                &label_string);
+                                                label);
       else
         widget = display_nothing (resource_name);
 
-      label = gtk_label_new (label_string ? label_string : resources[i]);
       gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
       g_object_set (gtk_notebook_get_page (GTK_NOTEBOOK (notebook), widget),
                     "tab-expand", FALSE,
                     NULL);
 
       g_free (resource_name);
-      g_free (label_string);
     }
 
   g_strfreev (resources);
index 64e9577975af72056db897252e7fb7476e948b0e..e162ca1118b615927424609b945e2ffaea951e73 100644 (file)
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkSearchBar" id="searchbar">
+                <accessibility>
+                  <relation name="labelled-by">search-entry</relation>
+                </accessibility>
                 <property name="key-capture-widget">window</property>
                 <child>
                   <object class="GtkSearchEntry" id="search-entry">
                     <accessibility>
+                      <property name="label" translatable="yes">Search</property>
                       <relation name="controls">listview</relation>
                     </accessibility>
                   </object>
index c463dde68409b259989e08bd825fe5c6d44f5d1d..b42225a2be9281c5eccdacc2c8707c003c3e64a2 100644 (file)
@@ -68,6 +68,9 @@ do_password_entry (GtkWidget *do_widget)
                     "placeholder-text", "Password",
                     "activates-default", TRUE,
                     NULL);
+      gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
+                                      GTK_ACCESSIBLE_PROPERTY_LABEL, "Password",
+                                      -1);
       g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
       gtk_box_append (GTK_BOX (box), entry);
 
@@ -77,6 +80,9 @@ do_password_entry (GtkWidget *do_widget)
                     "placeholder-text", "Confirm",
                     "activates-default", TRUE,
                     NULL);
+      gtk_accessible_update_property (GTK_ACCESSIBLE (entry2),
+                                      GTK_ACCESSIBLE_PROPERTY_LABEL, "Confirm",
+                                      -1);
       g_signal_connect (entry2, "notify::text", G_CALLBACK (update_button), NULL);
       gtk_box_append (GTK_BOX (box), entry2);
 
index edf6ecbfa6f863d054465b872b8d94212aa7c523..309362cc9dd524eaca9612a44033c8e67cc7d412 100644 (file)
@@ -189,6 +189,7 @@ do_pickers (GtkWidget *do_widget)
     gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
 
     picker = gtk_color_dialog_button_new (gtk_color_dialog_new ());
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), picker);
     gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
 
     label = gtk_label_new ("Font:");
@@ -198,6 +199,7 @@ do_pickers (GtkWidget *do_widget)
     gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
 
     picker = gtk_font_dialog_button_new (gtk_font_dialog_new ());
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), picker);
     gtk_grid_attach (GTK_GRID (table), picker, 1, 1, 1, 1);
 
     label = gtk_label_new ("File:");
@@ -208,6 +210,9 @@ do_pickers (GtkWidget *do_widget)
 
     picker = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
     button = gtk_button_new_from_icon_name ("document-open-symbolic");
+    gtk_accessible_update_property (GTK_ACCESSIBLE (button),
+                                    GTK_ACCESSIBLE_PROPERTY_LABEL, "Select File",
+                                    -1);
 
     label = gtk_label_new ("None");
 
@@ -223,6 +228,9 @@ do_pickers (GtkWidget *do_widget)
     gtk_box_append (GTK_BOX (picker), button);
     app_picker = gtk_button_new_from_icon_name ("emblem-system-symbolic");
     gtk_widget_set_halign (app_picker, GTK_ALIGN_END);
+    gtk_accessible_update_property (GTK_ACCESSIBLE (app_picker),
+                                    GTK_ACCESSIBLE_PROPERTY_LABEL, "Open File",
+                                    -1);
     gtk_widget_set_sensitive (app_picker, FALSE);
     g_signal_connect (app_picker, "clicked", G_CALLBACK (open_app), NULL);
     gtk_box_append (GTK_BOX (picker), app_picker);