Mnemonics for GtkLabels in GtkPopovers interfere with other accelerators
Submitted by Casey Jao
Link to original bug (#785236)
Description
Created attachment 356123 Check if label belongs to popover before adding mnemonic.
This bug report stems from an issue I noticed recent versions of Evince, where certain keyboard shortcuts don’t work. Further investigation revealed that the problem is rooted in how GtkLabel sets up mnemonics.
In Evince, the accelerators “<alt>
P” and “<alt>
N” are supposed to jump to the previous and next item, respectively, in the navigation history (https://github.com/GNOME/evince/blob/master/shell/ev-application.c#L1051). Such shortcuts are handy if for example one jumped to a reference in an article by clicking a link and wanted to go back. Some time ago I filed a bug report about this against Evince (https://bugzilla.gnome.org/show_bug.cgi?id=782451).
To make a long story short, Evince changed its menus to use GtkPopover instead of GtkMenu (https://bugzilla.gnome.org/show_bug.cgi?id=760527), and mnemonics for labels inside GtkPopover interfere with other keyboard accelerators. Indeed the problem goes away if I undo this change. The mechanism for this conflict appears to be as follows:
*Mnemonics take precedence over accelerators in gtk_window_activate_key(). *GtkLabels buried inside popovers assign their mnemonics to the top level window in gtk_label_setup_mnemonic() (https://github.com/GNOME/gtk/blob/master/gtk/gtklabel.c#L1756).
I am attaching a simple patch based on the GTK 3.22 branch which appears to fix the problem; namely, just check if the label lives inside a GtkPopover, and if so, don’t add its mnemonic to the top level window. The existing code does something similar in case the label lives inside a GtkMenu.
Any comments would be appreciated.
Patch 356123, "Check if label belongs to popover before adding mnemonic.":
0001-Check-if-GtkLabel-belongs-to-a-popover-before-adding.patch
Version: 3.22.x