Screen reader reads out underscores
Steps to reproduce
- Run:
#include <gtk/gtk.h>
void on_activate(GApplication *app) {
GtkWidget *win = gtk_application_window_new(GTK_APPLICATION(app));
GtkWidget *btn = gtk_button_new_with_mnemonic("_Hello World");
gtk_window_set_child(GTK_WINDOW(win), btn);
gtk_window_present(GTK_WINDOW(win));
}
int main(void) {
GtkApplication *app = gtk_application_new("org.gtk.Example", 0);
g_object_connect(app, "signal::activate", on_activate, NULL);
return g_application_run(G_APPLICATION(app), 0, NULL);
}
- Turn on Orca
- Observe Orca saying "Line Hello World Pushbutton"
- Open GTK inspector
- Select the label inside of the button
- Go to the accessibility tab, and observe that the accessiblity label is set to "_Hello World"
Current behavior
Orca reads out the underscore that defines the mnemonic (i.e. a button w/ the mnemonic "_Next" will actually be read out as "Line Next Pushbutton" instead of "Next Pushbutton"). This is because GTK reports to the a11y bus the raw contents of the label, underscore and all, even though what's visible on screen doesn't match that.
GTK actually does the same with markup too. So if I have a label with the contents "Foobar" and use-markup
set to true, Orca would read out "less than, b, greater than, foobar, less than, slash, b, greater than" instead of just "foobar"
If I try the same experiment in GTK 3, it would filter out both the underscore in the mnemonic if user-underline is on and markup formatting if use-markup is on. So this is a regression
Expected outcome
The GtkLabel detects that use-underline (or use-markup) is on and strips out the underscore (or markup formatting)
Version information
4.14.2, on Fedora 40
I can also reproduce it in my app, built against GTK 4.15.1 (runtime/org.gnome.Sdk/x86_64/master/8f584f3f5f489d1cdbd5f6f7f1efa4e1f004ba8274f690dceb0ca1bc3076146f)