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 376750 - bug in gedit_window_key_press_event
bug in gedit_window_key_press_event
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.16.x
Other Linux
: Normal normal
: ---
Assigned To: Gedit maintainers
Gedit maintainers
Depends on:
Blocks:
 
 
Reported: 2006-11-18 19:16 UTC by ek.kato
Modified: 2006-12-03 22:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to fix key press event in geditview (722 bytes, patch)
2006-11-18 19:18 UTC, ek.kato
none Details | Review
revised patch (623 bytes, patch)
2006-11-20 09:26 UTC, ek.kato
none Details | Review
Patch to use gtk_window_activate_key() (343 bytes, patch)
2006-11-20 18:47 UTC, ek.kato
none Details | Review
better patch (467 bytes, patch)
2006-11-20 18:59 UTC, ek.kato
none Details | Review
proposed patch (614 bytes, patch)
2006-11-26 13:59 UTC, Paolo Borelli
none Details | Review
patch (2.31 KB, patch)
2006-11-26 15:34 UTC, Paolo Borelli
committed Details | Review

Description ek.kato 2006-11-18 19:16:53 UTC
As described in the comment for gedit_window_key_press_event(), current implementation causes problem if focused_widget is GeditView.

For example, if focus is in a text widget and a Shift key is pressed, it will cause same key_press event in GtkTextView twice with following sequence.

1. gtk_widget_event (focused_widget, (GdkEvent*) event) in gedit_window_key_press_event() is called and return FALSE

   In the event, gtk_source_view_key_press_event() is called and return FALSE
   (with gtk_text_view_key_press_event() return FALSE)


2. Since 1. returns FALSE, GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event) call gtk_source_view_key_press_event().


If XIM is uses for input method for gtktextview, this causes infinite loop since XFilterEvent is called twice with the same event.  So GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event) should not be called if the focused widget is GeditView.

Please apply attached patch.
Comment 1 ek.kato 2006-11-18 19:18:25 UTC
Created attachment 76813 [details] [review]
Patch to fix key press event in geditview
Comment 2 Bruno Boaventura 2006-11-20 03:36:13 UTC
Patch looks good.
Comment 3 ek.kato 2006-11-20 08:52:19 UTC
Sorry, my patch broke keyboard shortcut for the menu (like Control-F).
I'll reconsider how to solve...
Comment 4 ek.kato 2006-11-20 09:04:36 UTC
And I'm not sure why gedit_window_key_press_event() calls gtk_widget_event() for the focused_widget.  Just return GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event) seems fine for me.

What does it mean "an entry on a panel" in its comment?

   ...
   This is unfortunate and means that pressing ctrl+V
   in an entry on a panel ends up pasting text in the TextView.
   ...
Comment 5 Paolo Maggi 2006-11-20 09:08:07 UTC
See also bug #331369, it looks related to me
Comment 6 Paolo Maggi 2006-11-20 09:09:30 UTC
"an entry on a panel" is a GtkEntry put in a side or bottom panel.
Comment 7 ek.kato 2006-11-20 09:26:34 UTC
Created attachment 76905 [details] [review]
revised patch

> "an entry on a panel" is a GtkEntry put in a side or bottom panel.

OK. But how can I create GtkEntry in side panel?  I've checked "Statusbar" and "SidePane".

Anyway, I've revised the patch.  It only calls gtk_widget_event for the focused_widget when it is not a textview.  Can you review it?
Comment 8 ek.kato 2006-11-20 10:05:14 UTC
Aha, now understand using Python Console from "BottomPane".  As you said, just call GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event (widget, event) causes the problem with Control-V in the BottomPane.

I've tested my revised patch and it solves "double keypress event with a shift key" problem in GeditView, but same problem still exists in the BottomPane.

I think the "double keypress event" which is occurred when gtk_im_context_filter_keypress() returns FALSE cannot be solved with current implementation of gedit_window_key_press_event().

How about connecting "key_press_event" to the focused widget when its focus is changed to the text widget of bottom/side pane?
Comment 9 ek.kato 2006-11-20 18:47:31 UTC
Created attachment 76929 [details] [review]
Patch to use gtk_window_activate_key()

3rd try to fix the problem.

It uses gtk_window_activate_key() instead of GTK_WIDGET_CLASS (gedit_window_parent_class)->key_press_event () so that avoid calling gtk_im_context_filter_keypress twice.

I've tested this code with XIM, and text input in the main textview and the python console in the bottom pane works fine for me.
Comment 10 ek.kato 2006-11-20 18:59:19 UTC
Created attachment 76932 [details] [review]
better patch

Added check for focused_widget if !handled.
Comment 11 Paolo Borelli 2006-11-26 13:59:38 UTC
Created attachment 77165 [details] [review]
proposed patch

What about this patch? Can you test if it works? If it does, I think that it's the proper way to fix it.
Comment 12 ek.kato 2006-11-26 14:31:34 UTC
(In reply to comment #11)
> Created an attachment (id=77165) [edit]
> proposed patch
> 
> What about this patch? Can you test if it works? If it does, I think that it's
> the proper way to fix it.

Does it compile?  I got following error.

gedit-window.c: In function 'gedit_window_key_press_event':
gedit-window.c:282: error: 'GtkWindowClass' has no member named 'key_press_event'

Comment 13 Paolo Borelli 2006-11-26 15:00:31 UTC
No, you are right. My patch was totally bogus and untested, sorry, I got confused.


However I don't think that your patch is totally right:

GTK_WINDOW_CLASS (gedit_window_parent_class)->key_press_event (widget, event) makes sure that the parent handler is called, that is gtk_window_key_press_event(). Let's take a look at that function:


static gint
gtk_window_key_press_event (GtkWidget   *widget,
			    GdkEventKey *event)
{
  GtkWindow *window = GTK_WINDOW (widget);
  gboolean handled = FALSE;

  /* handle mnemonics and accelerators */
  if (!handled)
    handled = gtk_window_activate_key (window, event);

  /* handle focus widget key events */
  if (!handled)
    handled = gtk_window_propagate_key_event (window, event);

  /* Chain up, invokes binding set */
  if (!handled)
    handled = GTK_WIDGET_CLASS (gtk_window_parent_class)->key_press_event (widget, event);

  return handled;
}


So your patch correctly avoids to call gtk_window_propagate_key_event twice, but in the case that gtk_window_activate_key doesn't return true, it doesn't call into the "grand parent handler", so it ignores the binding set.


I think we should change gedit_window_key_press_event to look like gtk_window_key_press_event, only with gtk_window_propagate_key_event done before gtk_window_activate_key, and then make sure to chain up to the grand parent handler, skipping GtkWindow's key-press-event handler
Comment 14 Paolo Borelli 2006-11-26 15:34:43 UTC
Created attachment 77167 [details] [review]
patch

can you test this one? Thanks in advance
Comment 15 ek.kato 2006-11-26 16:21:36 UTC
(In reply to comment #14)

I've tested the patch and works fine.  Thanks!
What is the grand_parent_class in this case? Just curious.
Comment 16 Paolo Borelli 2006-11-26 16:42:47 UTC
> What is the grand_parent_class in this case? Just curious.

It's GtkWidgetClass
Comment 17 ek.kato 2006-11-26 16:46:36 UTC
(In reply to comment #16)
> > What is the grand_parent_class in this case? Just curious.
> 
> It's GtkWidgetClass

I see.  So it calls gtk_bindings_activate_event().
Now I think the problem is resolved.  Thanks again.
Comment 18 Paolo Borelli 2006-12-02 16:24:37 UTC
ops, forgot to commit :-)

Now it's in cvs.
Comment 19 Paolo Maggi 2006-12-03 18:02:43 UTC
Have you committed to gnome-216 branch too?
Comment 20 Paolo Borelli 2006-12-03 22:42:11 UTC
> Have you committed to gnome-216 branch too?

Now yes.