Bug 677856

Summary: When using x input method in gtk3 application, hangul input is broken.
Product: [Fedora] Fedora Reporter: sangu <sangu.fedora>
Component: gtk3Assignee: Matthias Clasen <mclasen>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: i18n-bugs, mclasen, shawn.p.huang, tfujiwar
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ibus-1.3.99.20110206-4.fc15 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-09-14 03:36:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description sangu 2011-02-16 04:55:50 UTC
Description of problem:
When x input method in gtk3 application, hangul input is broken.

$ gedit
[...]
** (gedit:3457): WARNING **: Invalid change to preedit string, first=0 length=1 (orig length == 0)

** (gedit:3457): WARNING **: Invalid change to preedit string, first=0 length=1 (orig length == 0)

** (gedit:3457): WARNING **: Invalid change to preedit string, first=0 length=3 (orig length == 0)

** (gedit:3457): WARNING **: Invalid change to preedit string, first=0 length=1 (orig length == 0)

Version-Release number of selected component (if applicable):
1.3.99.20110127-4.fc15.x86_64

How reproducible:
always

Steps to Reproduce:
1. launch gedit
2. change to x input method in gedit 
3. input hangul 
  
Actual results:
rkrkrkrkrkrkrk가가가가가

Expected results:
가가가가가가가가가가가

Additional info:

gtk3-3.0.0-1.fc15.x86_64
ibus-hangul-1.3.0.20100329-5.fc15.x86_64

Comment 1 fujiwara 2011-02-17 04:32:59 UTC
Interested. Thanks for filing the bug.
I might notice the issue but I forgot it.

We need to remove the snooper when we switch the input methods.

Comment 4 Fedora Update System 2011-02-17 08:05:10 UTC
ibus-1.3.99.20110206-2.fc15 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/ibus-1.3.99.20110206-2.fc15

Comment 5 Fedora Update System 2011-03-03 03:01:30 UTC
ibus-1.3.99.20110206-4.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 6 sangu 2011-03-07 04:57:39 UTC
Not Fixed in ibus-1.3.99.20110206-4.fc15.x86_64.

gtk3-3.0.1-2.fc15.x86_64
ibus-hangul-1.3.1-1.fc15.x86_64

Comment 7 fujiwara 2011-03-09 06:41:11 UTC
There are two problems.
One is that snooper was not removed when the im client is switched from ibus to xim and it was fixed in ibus-1.3.99.20110206-4.fc15.

Another is that ibus-x11 doesn't receive KeyPress events because KeyRelease events are buffered in X11.
If the im client is gtk-xim, the gtk_im_context_xim_filter_keypress() calls XFilterEvent() and XFilterEvent() calls XSendEvent() internally.
ibus-x11 receives the key event from XFilterEvent() -> WaitXIMProtocol() -> xim_forward_event().

ibus_hangul_engine_process_key_event returns FALSE in KeyRelease.
If the process_key_events returns FALSE, xim_forward_event() sends the same event again with XIM_FORWARD_EVENT.
It seems gdk does not pick up the forwarded KeyRelease events with XFilterEvent() in _gdk_x11_display_queue_events().
So if you type the next chars, the events are not KeyPress but the buffered KeyRelease. 
XFilterEvent() always returns FALSE for the buffered events in _XimProtoKeypressFilter().
So gtk-xim outputs the ASCII chars but not the chars from ibus-hangul.
XIM_FORWARD_EVENT has the option of sync_bit but it seems it's not handled correctly at present.

The possible solution is to ignore the KeyRelease event for gtk-xim.
--- ibus/client/x11/main.c
+++ ibus/client/x11/main.c
@@ -654,7 +654,7 @@ xim_get_ic_values (XIMS xims, IMChangeIC
     for (i = 0; i < (int) call_data->ic_attr_num; ++i, ++ic_attr) {
         if (g_strcmp0 (XNFilterEvents, ic_attr->name) == 0) {
             ic_attr->value = (void *) malloc (sizeof (CARD32));
-            *(CARD32 *) ic_attr->value = KeyPressMask | KeyReleaseMask;
+            *(CARD32 *) ic_attr->value = KeyPressMask;
             ic_attr->value_length = sizeof (CARD32);
         }
     }

I'll talk with the maintainer.

Comment 8 fujiwara 2011-03-11 03:34:56 UTC
If we apply this fix, we need to make sure there is no regressions in qt3, qt4, X and Java.
I'll be back this problem after beta maybe because now I focus on gnome-shell.
I guess this problem is not so critical since you can use ibus client but not gtk-xim.

Comment 9 fujiwara 2011-04-05 06:20:34 UTC
I'd suggest this is a gtk3 bug:
https://bugzilla.gnome.org/show_bug.cgi?id=645993