GNOME Bugzilla – Bug 300730
Mnemonic activation of panel menu items no longer works
Last modified: 2015-03-24 13:00:56 UTC
From Fedora: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=152259 With the Gnome in FC3, I could focus on certain parts of the menu by pressing letter keys. For example, Alt-F1 would start the menu and after pressing the down arrow once, I could move to "System Settings" by pressing "s" several times. This capability is no longer available. Only the arrow keys work. I think this is probably down to a change made in gtk+ 2.6 where GtkMenuShell maintains its own mnemonic hash. See bug #101309. I haven't confirmed that in great detail, though. very time-consuming when you are trying to reach the middle line of the menu.
(uggh, don't mind the copy and paste error :-) Matthias: any thoughts on this? This is what the panel is doing: static void setup_mnemonic (GtkWidget *menuitem, GtkWidget *old_toplevel, gpointer keyval_as_pointer) { GtkWidget *toplevel; guint keyval; keyval = GPOINTER_TO_UINT (keyval_as_pointer); if (old_toplevel != NULL) gtk_window_remove_mnemonic (GTK_WINDOW (old_toplevel), keyval, GTK_WIDGET (menuitem)); toplevel = gtk_widget_get_toplevel (menuitem); if (GTK_WIDGET_TOPLEVEL (toplevel)) gtk_window_add_mnemonic (GTK_WINDOW (toplevel), keyval, GTK_WIDGET (menuitem)); } static void setup_invisible_mnemonic (GtkWidget *menuitem, char unicode_char) { guint accel_key; accel_key = gdk_keyval_to_lower (gdk_unicode_to_keyval (unicode_char)); g_signal_connect (menuitem, "hierarchy_changed", G_CALLBACK (setup_mnemonic), GUINT_TO_POINTER (accel_key)); setup_mnemonic (menuitem, NULL, GUINT_TO_POINTER (accel_key)); } { ... if (invisible_mnemonic && title) setup_invisible_mnemonic (menuitem, title [0]); ... }
*** Bug 303358 has been marked as a duplicate of this bug. ***
*** Bug 304813 has been marked as a duplicate of this bug. ***
Is there any activity on this bug? Navigating the menu using the keyboard seems impossible without using the cursor keys (which I don't use, normally). I (and I bet I'm not the only one) really love to see this major usability regression fixed.
Is there anyone going to fix this bug? Or may be someone could explain current situation with GTK+ and GNOME Panel related to this bug - a background. Why this bug is not fixed yet and where is the real problem?
I've tried stepping through the code in a debugger, and when the following code snippet inside |setup_mnemonic()| is hit: toplevel = gtk_widget_get_toplevel (menuitem); if (GTK_WIDGET_TOPLEVEL (toplevel)) gtk_window_add_mnemonic (GTK_WINDOW (toplevel), keyval, GTK_WIDGET (menuitem)); ...|GTK_WIDGET_TOPLEVEL(toplevel)| evaluates to 0, and thus mnemonic-adding code is never called. The problem seems to be that |menuitem| has no parent, so the call simply returns |menuitem|, but |menuitem|'s not a top-level widget. At first I thought this might be that the passed-in menuitem (because it's only an initialized menuitem) isn't contained inside some other widget. However, I tested this by rearranging the calls so that |gtk_shell_append()| for the menuitems happens before |setup_menuitem()|, but it didn't seem to work. I'm not at all familiar with GTK+ or its C-based "object-orientedness" (ugh), so I can't knowledgeably say much beyond this. I might try poking at this more in the next month or so, but realistically I probably have more useful things to do with my time, even if this bug slows me down and forces me to change the way I use the main menus maybe ten or twenty times a day.
Adding to 2.14.x milestone.
Vincent, I just learned that GtkMenu can already do the invisible mnemonic thing you want here, no hacks with gtk_window_add_accelerator() necessary. Here is how it works: gtk_menu_item_new_with_mnemonic ("_Foo"); gtk_label_set_pattern (GTK_LABEL (GTK_BIN (menuitem)->child), ""); This makes a menuitem with no underlined characters, and 'F' as the mnemonic.
Created attachment 58235 [details] [review] mnemonic patch
The patch has only been superficially tested, but seems to work.
Comment on attachment 58235 [details] [review] mnemonic patch > void > setup_menuitem (GtkWidget *menuitem, > GtkIconSize icon_size, >@@ -1199,19 +1162,21 @@ > > { > GtkWidget *label; >- >+ gchar *_title; >+ >+ label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL); >+ _title = g_strconcat ("_", title, NULL); >+ gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _title); >+ g_free (_title); > if (invisible_mnemonic) >- label = gtk_label_new (title); >- else >- label = gtk_label_new_with_mnemonic (title); >+ gtk_label_set_pattern (GTK_LABEL (label), ""); I could just be reading this wrong, but doesn't this always make the first character a mnemonic, even if the string already contains a mnemonic (e.g., if title were "The _GIMP")? Or is it safe to assume that any menu item created here won't have any built-in mnemonics? API docs don't explicitly specify what happens for a string with multiple underscores (all of them get hooked up?), so I have no idea what the expected behavior's supposed to be.
Well, if you look two lines further down in the patch - if (invisible_mnemonic && title) - setup_invisible_mnemonic (menuitem, title [0]); you see that that is exactly the same behaviour that the code was trying to implement before. And no, there will not be any underscores in the titles. The I do believe the docs mention that only the first _ is interpreted as mnemonic.
I committed a modified part of the patch. Jeff is right: we don't want to make the first character a mnemonic if invisible_mnemonic is FALSE. In fact, this code is a mess since this function is used for other stuff than the main menu... Thanks Matthias.