After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 331369 - Menu short cuts do not work
Menu short cuts do not work
Status: RESOLVED DUPLICATE of bug 335796
Product: gtk+
Classification: Platform
Component: Input Methods
2.10.x
Other All
: High critical
: ---
Assigned To: Hidetoshi Tajima
gtk-bugs
AP1
: 350230 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-02-16 05:11 UTC by younker
Modified: 2007-03-09 23:43 UTC
See Also:
GNOME target: ---
GNOME version: 2.13/2.14



Description younker 2006-02-16 05:11:52 UTC
Please describe the problem:
locale zh_CN.UTF-8
Gentoo 2.3.6
Gnome 2.13.91.

Steps to reproduce:
1. Start gedit
2. Press Alt-F
3. The File menu does not active


Actual results:
the char f is entered in the text area

Expected results:
The File menu should be poped up.

Does this happen every time?
yes. 

Other information:
emerged with BMG overlay
Comment 1 Paolo Maggi 2006-02-22 14:01:31 UTC
Do accellerators work for you in other GNOME programs?
Are you sure it is not a translation problem?
Comment 2 younker 2006-02-22 23:36:34 UTC
Yes, works for other applications, only gedit does not work.
Comment 3 Paolo Maggi 2006-02-27 09:08:32 UTC
I cannot reproduce it.
Which is your locale?
Comment 4 Paolo Borelli 2006-02-27 09:12:18 UTC
also, do you use an input method? My blind guess is that the input method steals alt+F before the menu.
Comment 5 younker 2006-02-27 11:04:22 UTC
My locale is zh_CN.UTF-8, and I use fcitx as my IME, 
but I can use the menu short cut for other gnome application.
Comment 6 Paolo Maggi 2006-02-27 14:10:04 UTC
Are shortcuts for the other applications working also when a text widget is focused? Are you sure it is not a translation problem?
Comment 7 younker 2006-02-27 14:52:42 UTC
yes, I tried this in gnumeric, sylpheed and some others applications, I don't think it is an translation problem because it works on gedit 2.12.x
Comment 8 younker 2006-03-01 13:22:12 UTC
I removed the Chinese mo file, then start gedit, it shows its UI with English, but the short cut key for menu still doesn't work.

Another information is I can't activate my IME which is fcitx, I can activate fcitx in the file open/save dialog in gedit but can not activate it in gedit. 

Comment 9 bill.haneman 2006-03-23 11:41:01 UTC
Looks like all menu keynav may bve broken in gedit: 

From a Sun-internal bug report, regarding loss of menu keyboard navigation in gedit:

-------8<---------

Found the root reason in gedit-window.c:218
/*
 * GtkWindow catches keybindings for the menu items _before_ passing them to
 * the focused widget. This is unfortunate and means that pressing ctrl+V
 * in an entry on a panel ends up pasting text in the TextView.
 * Here we force events to be first  passed to the focused widget and then
 * we chain up the default handler... this is the opposite of Gtk default
 * behavior so we need to keep an eye open to see if anything breaks.
 */
static gboolean
gedit_window_key_press_event (GtkWidget   *widget,
                              GdkEventKey *event)
{       GtkWidget *focused_widget;
        gboolean handled = FALSE;

        focused_widget = gtk_window_get_focus (GTK_WINDOW (widget));

        if (focused_widget)
        {
                handled = gtk_widget_event (focused_widget,
                                            (GdkEvent*) event);
        }

        if (handled)
                return TRUE;
        else
                return GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event);
}

focused_widget will catch the key event first, successfully handle it and return handle=true, then menu widget never can't catch the event again. From the comment, it seems in previous realization, it's different here.

Comment 10 bill.haneman 2006-03-23 11:41:28 UTC
Looks like all menu keynav may bve broken in gedit: 

From a Sun-internal bug report, regarding loss of menu keyboard navigation in gedit:

-------8<---------

Found the root reason in gedit-window.c:218
/*
 * GtkWindow catches keybindings for the menu items _before_ passing them to
 * the focused widget. This is unfortunate and means that pressing ctrl+V
 * in an entry on a panel ends up pasting text in the TextView.
 * Here we force events to be first  passed to the focused widget and then
 * we chain up the default handler... this is the opposite of Gtk default
 * behavior so we need to keep an eye open to see if anything breaks.
 */
static gboolean
gedit_window_key_press_event (GtkWidget   *widget,
                              GdkEventKey *event)
{       GtkWidget *focused_widget;
        gboolean handled = FALSE;

        focused_widget = gtk_window_get_focus (GTK_WINDOW (widget));

        if (focused_widget)
        {
                handled = gtk_widget_event (focused_widget,
                                            (GdkEvent*) event);
        }

        if (handled)
                return TRUE;
        else
                return GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event);
}

focused_widget will catch the key event first, successfully handle it and return handle=true, then menu widget never can't catch the event again. From the comment, it seems in previous realization, it's different here.
Comment 11 Paolo Borelli 2006-03-23 11:50:28 UTC
Well, while removing that function would 'fix' the problem, it would break other things: what we need to find out is *who* is handling that keypress.

Let's say for instance that the culprit is an input method: removing that function would fix the menus, but break the input method itself since the keypress would not be passed to it.

To me it makes perfect sense that the first to handle the keypress is the focused widget and in particular the textview and only if the keypress is not handled by it then we look in the menu. For instance this fixed a long standing bug with emacs-keybindings gtk preference, where shortucts like ctrl+A where handled by the menu instead of triggering the corresponding emacs command despite the preference being set.
Comment 12 Paolo Borelli 2006-03-23 11:53:20 UTC
(btw sorry, we already knew that that function was involved, we should have had noted it here with the above explanation in order to save you some debugging)
Comment 13 Calum Benson 2006-04-26 16:54:55 UTC
Apologies for spam-- marking AP1 to reflect accessibility impact.
Comment 14 Calum Benson 2006-04-26 17:08:04 UTC
Apologies for spam... ensuring Sun a11y folks are cc'ed on all current accessibility bugs.
Comment 15 younker 2006-07-28 05:11:35 UTC
Hi, This bug still exists in the latest version of gedit, I think this is a very serious problem for guys who use zh_CN.UTF-8 locale to work. 

I don't find this issue in any other application what ever they written by gtk+ or gnome. 

So can someone tell me what is the progress about this issue?

Thanks all.
Comment 16 Paolo Borelli 2006-08-10 20:23:57 UTC
*** Bug 350230 has been marked as a duplicate of this bug. ***
Comment 17 Paolo Maggi 2006-08-25 15:21:06 UTC
We have no clue on how to solve this problem in a sane way.
May be we should ask help to the gtk+ guys.

Any volunteer to find a sane solution for this bug?

Comment 18 Paolo Maggi 2006-08-25 16:14:03 UTC
Could you please try to disable the input method and tell us if it works?
May be your input method is stealing Alt+F (and the other key press event) before the menu.

-----------------------

<paolo> mclasen: hi, any clue on how to fix bug #331369?
<mclasen> paolo: you get what you ask for, imo
<mclasen> if you take the key event and let it be handled by some widget, then it cannot be used to activate the menu...
<paolo> well, what I cannot understand is why we have the problem only on some locale
<paolo> it the text view does not handle the event, then the menu should be activate
<paolo> and this is what we have in most locales
<paolo> if you see, user is trying to activate the menu with "Alt+F" and AFAIK GtkTextView does not handle Alt+F
* paolo is wondering if the input method is stealing ALT+F before the menu
<mclasen> I guess if you feed the event to the text view, it asks the input method 
<mclasen> and if the input method considers it appropriate to handle Alt-f or just does not care to check the modifiers
<mclasen> ...
<pbor> yes, as noted in the bug I think that's the cause
<paolo> well, if the input method is eating events it does not really manage, I'd consider it a IM bug
<pbor> and making the menu take precedence on the textview is not really a fix since it would break the IM in case it was really using one of those key combination

-----------------------

Comment 19 younker 2006-08-25 23:46:54 UTC
This is not a XIM problem, since I can do this well at any other gnome program. 

Before 2.15 of gedit, it works. 

My locale setting is zh_CN.UTF-8, seems this problem is related to the locale setting, when I switched to en_US, it works again, but that is not what I wanted. 
Comment 20 Paolo Borelli 2006-08-26 16:54:53 UTC
> This is not a XIM problem, since I can do this well at any other gnome program. 

Actually that doesn't prove anything: as explained above gedit makes sure that key are first processed by the textview. This is not the default and other gnome programs do not do that, but it makes sense and fixes other separate issues. If the IM is handling key combinations it should not handle, then it is a IM bug.
Comment 21 Paolo Maggi 2006-09-02 15:07:07 UTC
hmmm... you said that when you switched to en_US gedit is working. Are you using XIM with en_US?

Could you please explain me how to install/configure/use XIM with gedit so that I can investigate the problem?

Note that I know very little about Input Methods and how to use them so please explain me also the obvious things. 

If some developer looking at this bug and that knows XIM want to help me it will be very cool.

Comment 22 padraig.obriain 2006-09-27 16:43:04 UTC
I am seeing this on Solaris without using an interesting locale

How about adding the following code before call to gtk_widget_event()
                handled = gtk_window_activate_key (GTK_WINDOW(widget), event);
                if (handled)
                        return TRUE;
Comment 23 Dan Winship 2006-10-12 20:32:25 UTC
This happens in openSUSE 10.2 with *all* locales. gedit 2.16.1, gtk+ 2.10.3
https://bugzilla.novell.com/show_bug.cgi?id=208679
Comment 24 Paolo Borelli 2006-10-13 07:27:43 UTC
Dan, I don't think is an issue with the locale, however can you check if any input method is active?
As said in the above discussion with mclasen our guess is that is the input method that intercepts the short cuts.

If that's not the case, some investigations of where the key press gets eaten would be very appreciated.
Comment 25 younker 2006-10-13 10:48:54 UTC
I can ensure that this problem is not XIM related, with the same locale setting, XIM works fine in leafpad, but not work in gedit and gvim, so I think there are some problems with these applications, in some cases they catch the key press event. 

anyway, in en_US settings without XIM, the short cut works. 
Comment 26 Dan Winship 2006-10-13 12:40:36 UTC
(In reply to comment #24)
> Dan, I don't think is an issue with the locale, however can you check if any
> input method is active?

Huh... ok, apparently we are patching the default input method to "X Input
Method" rather than "Default". (Although there is no actual X Input Method
running.) Full story at
https://bugzilla.novell.com/show_bug.cgi?id=131498. It looks like that patch
can be reverted now though (although of course, people actually using XIM
would still lose).
Comment 27 Paolo Borelli 2006-10-13 13:01:54 UTC
Younker: as explained above, gedit makes sure that the event is passed to the Text  widget *before* the GtkWindow. This is not the deafult in gtk (that's why you don't see the issue in leafpad), but it is *intentional*. This is required so that combination like ctrl+V in a sidepane entry do not paste in the main textview. In fact if we didn't do that, a key combo which is a *real* input method combination, but also a menu shortcut would trigger the menu, which is IMHO a problem.

To sum it up this is a bug in XIM: it should *not* eat key combos it doesn't need. The fact that the gtk default behavior hides this, just made the bug less noticeable.
Comment 28 Dan Winship 2006-10-18 03:25:04 UTC
So, yeah, gtk_im_context_xim_filter_keypress() is claiming the event, because
XmbLookupString() succeeds even when Alt is down. It seems like either
XmbLookupString is broken, or else GtkIMContextXIM is supposed to know to not
call it if Ctrl/Alt are pressed?

(In reply to comment #21)
> Could you please explain me how to install/configure/use XIM with gedit so that
> I can investigate the problem?

All you have to do is right-click on the main textview, and choose Input
Methods -> X Input Method. You don't need to configure anything else.
Comment 29 ek.kato 2006-11-20 22:56:00 UTC
> So, yeah, gtk_im_context_xim_filter_keypress() is claiming the event, because
> XmbLookupString() succeeds even when Alt is down. It seems like either
> XmbLookupString is broken, or else GtkIMContextXIM is supposed to know to not
> call it if Ctrl/Alt are pressed?

I've confirmed that XmbLookupString() with "Alt-f" does return 1 for num_bytes and "f" for the character buffer.  This makes return value of gtk_im_context_xim_filter_keypress() TRUE.

In contrast,  XmbLookupString() with "Ctrl-f" return 1 and the character 0x6, which result in return FALSE in gtk_im_context_xim_filter_keypress(), and gedit properly shows Find dialog.

Thus the bug is not in XIM server itself, but in gtkimcontextxim.c.  I think gtk_im_context_xim_filter_keypress() must check accelerator mod_mask except for Control and Shift mask.  Here is the workaround, and I'll file a bug in GTK+ later.

--- gtkimcontextxim.c.orig      2005-07-01 03:42:44.000000000 +0900
+++ gtkimcontextxim.c   2006-11-21 07:50:16.000000000 +0900
@@ -705,6 +705,7 @@
   Status status;
   gboolean result = FALSE;
   GdkWindow *root_window = gdk_screen_get_root_window (gdk_drawable_get_screen (event->window));
+  guint accel_mod_mask;

   XKeyPressedEvent xevent;

@@ -728,6 +729,10 @@
   if (XFilterEvent ((XEvent *)&xevent, GDK_DRAWABLE_XID (context_xim->client_window)))
     return TRUE;

+  accel_mod_mask = gtk_accelerator_get_default_mod_mask() & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK);
+  if (event->state & accel_mod_mask)
+    return FALSE;
+
  again:
   if (ic)
     num_bytes = XmbLookupString (ic, &xevent, buffer, buffer_size, &keysym, &status);

Comment 30 ek.kato 2006-11-20 23:04:41 UTC
It found this is already filed in GTK+ bug #335796.
Comment 31 Matthias Clasen 2007-03-09 23:43:25 UTC

*** This bug has been marked as a duplicate of 335796 ***