Blame SOURCES/ibus-1713606-hangul-with-mouse.patch

e4fcff
From a40631e166137c9042a68c2d76844e7afc53d388 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Fri, 9 Nov 2018 14:49:44 +0900
e4fcff
Subject: [PATCH] Detect mouse click to commit Hangul preedit
e4fcff
e4fcff
If preedit text is not committed with the mouse click, preedit text
e4fcff
is moved to the new cursor position in Hangul typing.
e4fcff
Since set_cursor_location() is received before the reset() signal is
e4fcff
sent to ibus-daemon and commit_text() signal is received from
e4fcff
ibus-daemon, UpdatePreeditTextWithMode D-Bus method is newly added
e4fcff
and now ibus clients commit the preedit.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 bus/ibusimpl.c              |  11 ++++
e4fcff
 bus/inputcontext.c          | 108 ++++++++++++++++++++++++-------
e4fcff
 bus/inputcontext.h          |  19 +++++-
e4fcff
 client/gtk2/ibusimcontext.c |  95 +++++++++++++++++++++++++---
e4fcff
 src/ibusinputcontext.c      | 122 ++++++++++++++++++++++++++++++++----
e4fcff
 src/ibusinputcontext.h      |  27 +++++++-
e4fcff
 6 files changed, 338 insertions(+), 44 deletions(-)
e4fcff
e4fcff
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
e4fcff
index 80f3acfb..bbbb5770 100644
e4fcff
--- a/bus/ibusimpl.c
e4fcff
+++ b/bus/ibusimpl.c
e4fcff
@@ -815,6 +815,17 @@ bus_ibus_impl_set_focused_context (BusIBusImpl     *ibus,
e4fcff
             engine = bus_input_context_get_engine (ibus->focused_context);
e4fcff
             if (engine) {
e4fcff
                 g_object_ref (engine);
e4fcff
+                /* _ic_focus_in() can be called before _ic_focus_out() is
e4fcff
+                 * called under the async processes of two ibus clients.
e4fcff
+                 * E.g. gedit is a little slower v.s. a simple GtkTextView
e4fcff
+                 * application is the fastest when you click a Hangul
e4fcff
+                 * preedit text between the applications.
e4fcff
+                 * preedit will be committed with focus-out in the ibus client
e4fcff
+                 * likes ibus-im.so
e4fcff
+                 * so do not commit preedit here in focus-in event.
e4fcff
+                 */
e4fcff
+                bus_input_context_clear_preedit_text (ibus->focused_context,
e4fcff
+                                                      FALSE);
e4fcff
                 bus_input_context_set_engine (ibus->focused_context, NULL);
e4fcff
                 bus_input_context_set_emoji_extension (ibus->focused_context,
e4fcff
                                                        NULL);
e4fcff
diff --git a/bus/inputcontext.c b/bus/inputcontext.c
e4fcff
index 4f98b849..1b8e7adb 100644
e4fcff
--- a/bus/inputcontext.c
e4fcff
+++ b/bus/inputcontext.c
e4fcff
@@ -73,6 +73,7 @@ struct _BusInputContext {
e4fcff
     guint     preedit_cursor_pos;
e4fcff
     gboolean  preedit_visible;
e4fcff
     guint     preedit_mode;
e4fcff
+    gboolean  client_commit_preedit;
e4fcff
 
e4fcff
     /* auxiliary text */
e4fcff
     IBusText *auxiliary_text;
e4fcff
@@ -212,6 +213,9 @@ static IBusPropList    *props_empty = NULL;
e4fcff
 static const gchar introspection_xml[] =
e4fcff
     "<node>"
e4fcff
     "  <interface name='org.freedesktop.IBus.InputContext'>"
e4fcff
+    /* properties */
e4fcff
+    "    <property name='ContentType' type='(uu)' access='write' />"
e4fcff
+    "    <property name='ClientCommitPreedit' type='(b)' access='write' />\n"
e4fcff
     /* methods */
e4fcff
     "    <method name='ProcessKeyEvent'>"
e4fcff
     "      <arg direction='in'  type='u' name='keyval' />"
e4fcff
@@ -273,6 +277,12 @@ static const gchar introspection_xml[] =
e4fcff
     "      <arg type='u' name='cursor_pos' />"
e4fcff
     "      <arg type='b' name='visible' />"
e4fcff
     "    </signal>"
e4fcff
+    "    <signal name='UpdatePreeditTextWithMode'>"
e4fcff
+    "      <arg type='v' name='text' />"
e4fcff
+    "      <arg type='u' name='cursor_pos' />"
e4fcff
+    "      <arg type='b' name='visible' />"
e4fcff
+    "      <arg type='u' name='mode' />"
e4fcff
+    "    </signal>"
e4fcff
     "    <signal name='ShowPreeditText'/>"
e4fcff
     "    <signal name='HidePreeditText'/>"
e4fcff
     "    <signal name='UpdateAuxiliaryText'>"
e4fcff
@@ -297,9 +307,6 @@ static const gchar introspection_xml[] =
e4fcff
     "    <signal name='UpdateProperty'>"
e4fcff
     "      <arg type='v' name='prop' />"
e4fcff
     "    </signal>"
e4fcff
-
e4fcff
-    /* properties */
e4fcff
-    "    <property name='ContentType' type='(uu)' access='write' />"
e4fcff
     "  </interface>"
e4fcff
     "</node>";
e4fcff
 
e4fcff
@@ -1069,6 +1076,12 @@ _ic_reset (BusInputContext       *context,
e4fcff
            GDBusMethodInvocation *invocation)
e4fcff
 {
e4fcff
     if (context->engine) {
e4fcff
+        if (context->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
+            if (context->client_commit_preedit)
e4fcff
+               bus_input_context_clear_preedit_text (context, FALSE);
e4fcff
+            else
e4fcff
+               bus_input_context_clear_preedit_text (context, TRUE);
e4fcff
+        }
e4fcff
         bus_engine_proxy_reset (context->engine);
e4fcff
     }
e4fcff
     g_dbus_method_invocation_return_value (invocation, NULL);
e4fcff
@@ -1354,6 +1367,13 @@ _ic_set_content_type (BusInputContext *context,
e4fcff
     }
e4fcff
 }
e4fcff
 
e4fcff
+static void
e4fcff
+_ic_set_client_commit_preedit (BusInputContext *context,
e4fcff
+                               GVariant        *value)
e4fcff
+{
e4fcff
+    g_variant_get (value, "(b)", &context->client_commit_preedit);
e4fcff
+}
e4fcff
+
e4fcff
 static gboolean
e4fcff
 bus_input_context_service_set_property (IBusService     *service,
e4fcff
                                         GDBusConnection *connection,
e4fcff
@@ -1379,9 +1399,14 @@ bus_input_context_service_set_property (IBusService     *service,
e4fcff
     if (!bus_input_context_service_authorized_method (service, connection))
e4fcff
         return FALSE;
e4fcff
 
e4fcff
+    g_return_val_if_fail (BUS_IS_INPUT_CONTEXT (service), FALSE);
e4fcff
+
e4fcff
     if (g_strcmp0 (property_name, "ContentType") == 0) {
e4fcff
-        BusInputContext *context = (BusInputContext *) service;
e4fcff
-        _ic_set_content_type (context, value);
e4fcff
+        _ic_set_content_type (BUS_INPUT_CONTEXT (service), value);
e4fcff
+        return TRUE;
e4fcff
+    }
e4fcff
+    if (g_strcmp0 (property_name, "ClientCommitPreedit") == 0) {
e4fcff
+        _ic_set_client_commit_preedit (BUS_INPUT_CONTEXT (service), value);
e4fcff
         return TRUE;
e4fcff
     }
e4fcff
 
e4fcff
@@ -1453,22 +1478,44 @@ bus_input_context_focus_in (BusInputContext *context)
e4fcff
 
e4fcff
 /**
e4fcff
  * bus_input_context_clear_preedit_text:
e4fcff
+ * @context: A #BusInputContext
e4fcff
+ * @with_signal: %FALSE if the preedit is already updated in ibus clients
e4fcff
+ *               likes ibus-im.so. Otherwise %TRUE.
e4fcff
  *
e4fcff
- * Clear context->preedit_text. If the preedit mode is IBUS_ENGINE_PREEDIT_COMMIT, commit it before clearing.
e4fcff
+ * Clear context->preedit_text. If the preedit mode is
e4fcff
+ * IBUS_ENGINE_PREEDIT_COMMIT, commit it before clearing.
e4fcff
  */
e4fcff
-static void
e4fcff
-bus_input_context_clear_preedit_text (BusInputContext *context)
e4fcff
+void
e4fcff
+bus_input_context_clear_preedit_text (BusInputContext *context,
e4fcff
+                                      gboolean         with_signal)
e4fcff
 {
e4fcff
+    IBusText *preedit_text;
e4fcff
+    guint     preedit_mode;
e4fcff
+    gboolean  preedit_visible;
e4fcff
+
e4fcff
     g_assert (BUS_IS_INPUT_CONTEXT (context));
e4fcff
 
e4fcff
-    if (context->preedit_visible &&
e4fcff
-        context->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
-        bus_input_context_commit_text (context, context->preedit_text);
e4fcff
+    if (!with_signal) {
e4fcff
+        g_object_unref (context->preedit_text);
e4fcff
+        context->preedit_mode = IBUS_ENGINE_PREEDIT_CLEAR;
e4fcff
+        context->preedit_text = (IBusText *) g_object_ref_sink (text_empty);
e4fcff
+        context->preedit_cursor_pos = 0;
e4fcff
+        context->preedit_visible = FALSE;
e4fcff
+        return;
e4fcff
     }
e4fcff
 
e4fcff
-    /* always clear preedit text */
e4fcff
+    /* always clear preedit text to reset the cursor position in the
e4fcff
+     * client application before commit the preeit text. */
e4fcff
+    preedit_text = g_object_ref (context->preedit_text);
e4fcff
+    preedit_mode = context->preedit_mode;
e4fcff
+    preedit_visible = context->preedit_visible;
e4fcff
     bus_input_context_update_preedit_text (context,
e4fcff
         text_empty, 0, FALSE, IBUS_ENGINE_PREEDIT_CLEAR, TRUE);
e4fcff
+
e4fcff
+    if (preedit_visible && preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
+        bus_input_context_commit_text (context, preedit_text);
e4fcff
+    }
e4fcff
+    g_object_unref (preedit_text);
e4fcff
 }
e4fcff
 
e4fcff
 void
e4fcff
@@ -1479,7 +1526,10 @@ bus_input_context_focus_out (BusInputContext *context)
e4fcff
     if (!context->has_focus)
e4fcff
         return;
e4fcff
 
e4fcff
-    bus_input_context_clear_preedit_text (context);
e4fcff
+    if (context->client_commit_preedit)
e4fcff
+        bus_input_context_clear_preedit_text (context, FALSE);
e4fcff
+    else
e4fcff
+        bus_input_context_clear_preedit_text (context, TRUE);
e4fcff
     bus_input_context_update_auxiliary_text (context, text_empty, FALSE);
e4fcff
     bus_input_context_update_lookup_table (context,
e4fcff
                                            lookup_table_empty,
e4fcff
@@ -2338,7 +2388,7 @@ bus_input_context_disable (BusInputContext *context)
e4fcff
 {
e4fcff
     g_assert (BUS_IS_INPUT_CONTEXT (context));
e4fcff
 
e4fcff
-    bus_input_context_clear_preedit_text (context);
e4fcff
+    bus_input_context_clear_preedit_text (context, TRUE);
e4fcff
     bus_input_context_update_auxiliary_text (context, text_empty, FALSE);
e4fcff
     bus_input_context_update_lookup_table (context,
e4fcff
                                            lookup_table_empty,
e4fcff
@@ -2385,7 +2435,7 @@ bus_input_context_unset_engine (BusInputContext *context)
e4fcff
 {
e4fcff
     g_assert (BUS_IS_INPUT_CONTEXT (context));
e4fcff
 
e4fcff
-    bus_input_context_clear_preedit_text (context);
e4fcff
+    bus_input_context_clear_preedit_text (context, TRUE);
e4fcff
     bus_input_context_update_auxiliary_text (context, text_empty, FALSE);
e4fcff
     bus_input_context_update_lookup_table (context,
e4fcff
                                            lookup_table_empty,
e4fcff
@@ -2807,14 +2857,26 @@ bus_input_context_update_preedit_text (BusInputContext *context,
e4fcff
     } else if (PREEDIT_CONDITION) {
e4fcff
         GVariant *variant = ibus_serializable_serialize (
e4fcff
                 (IBusSerializable *)context->preedit_text);
e4fcff
-        bus_input_context_emit_signal (context,
e4fcff
-                                       "UpdatePreeditText",
e4fcff
-                                       g_variant_new (
e4fcff
-                                               "(vub)",
e4fcff
-                                               variant,
e4fcff
-                                               context->preedit_cursor_pos,
e4fcff
-                                               extension_visible),
e4fcff
-                                       NULL);
e4fcff
+        if (context->client_commit_preedit) {
e4fcff
+            bus_input_context_emit_signal (
e4fcff
+                    context,
e4fcff
+                    "UpdatePreeditTextWithMode",
e4fcff
+                    g_variant_new ("(vubu)",
e4fcff
+                                   variant,
e4fcff
+                                   context->preedit_cursor_pos,
e4fcff
+                                   extension_visible,
e4fcff
+                                   context->preedit_mode),
e4fcff
+                    NULL);
e4fcff
+        } else {
e4fcff
+            bus_input_context_emit_signal (
e4fcff
+                    context,
e4fcff
+                    "UpdatePreeditText",
e4fcff
+                    g_variant_new ("(vub)",
e4fcff
+                                   variant,
e4fcff
+                                   context->preedit_cursor_pos,
e4fcff
+                                   extension_visible),
e4fcff
+                    NULL);
e4fcff
+        }
e4fcff
     } else {
e4fcff
         g_signal_emit (context,
e4fcff
                        context_signals[UPDATE_PREEDIT_TEXT],
e4fcff
diff --git a/bus/inputcontext.h b/bus/inputcontext.h
e4fcff
index a46d5c06..7105fff8 100644
e4fcff
--- a/bus/inputcontext.h
e4fcff
+++ b/bus/inputcontext.h
e4fcff
@@ -2,8 +2,8 @@
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
  * Copyright (C) 2008-2014 Peng Huang <shawn.p.huang@gmail.com>
e4fcff
- * Copyright (C) 2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
- * Copyright (C) 2008-2014 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2017-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
+ * Copyright (C) 2008-2018 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -377,5 +377,20 @@ void                 bus_input_context_update_lookup_table
e4fcff
 void                 bus_input_context_panel_extension_received
e4fcff
                                                 (BusInputContext    *context,
e4fcff
                                                  IBusExtensionEvent *event);
e4fcff
+
e4fcff
+/**
e4fcff
+ * bus_input_context_clear_preedit_text:
e4fcff
+ *
e4fcff
+ * Clear context->preedit_text. If the preedit mode is
e4fcff
+ * IBUS_ENGINE_PREEDIT_COMMIT and with_signal is %TRUE, commit it before
e4fcff
+ * clearing.
e4fcff
+ * If with_signal is %FALSE, this just clears the preedit coditions
e4fcff
+ * and the actual preedit is handled in ibus clients.
e4fcff
+ */
e4fcff
+void                 bus_input_context_clear_preedit_text
e4fcff
+                                                (BusInputContext    *context,
e4fcff
+                                                 gboolean
e4fcff
+                                                                   with_signal);
e4fcff
+
e4fcff
 G_END_DECLS
e4fcff
 #endif
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index e4de52d9..73a0eaec 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -2,8 +2,8 @@
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
e4fcff
- * Copyright (C) 2015-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
- * Copyright (C) 2008-2017 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
+ * Copyright (C) 2008-2018 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -61,6 +61,7 @@ struct _IBusIMContext {
e4fcff
     PangoAttrList   *preedit_attrs;
e4fcff
     gint             preedit_cursor_pos;
e4fcff
     gboolean         preedit_visible;
e4fcff
+    guint            preedit_mode;
e4fcff
 
e4fcff
     GdkRectangle     cursor_area;
e4fcff
     gboolean         has_focus;
e4fcff
@@ -132,8 +133,14 @@ static void     ibus_im_context_set_surrounding
e4fcff
                                              gint           len,
e4fcff
                                              gint           cursor_index);
e4fcff
 
e4fcff
-
e4fcff
 /* static methods*/
e4fcff
+static void     _ibus_context_update_preedit_text_cb
e4fcff
+                                           (IBusInputContext   *ibuscontext,
e4fcff
+                                            IBusText           *text,
e4fcff
+                                            gint                cursor_pos,
e4fcff
+                                            gboolean            visible,
e4fcff
+                                            guint               mode,
e4fcff
+                                            IBusIMContext      *ibusimcontext);
e4fcff
 static void     _create_input_context       (IBusIMContext      *context);
e4fcff
 static gboolean _set_cursor_location_internal
e4fcff
                                             (IBusIMContext      *context);
e4fcff
@@ -744,6 +751,7 @@ ibus_im_context_init (GObject *obj)
e4fcff
     ibusimcontext->preedit_attrs = NULL;
e4fcff
     ibusimcontext->preedit_cursor_pos = 0;
e4fcff
     ibusimcontext->preedit_visible = FALSE;
e4fcff
+    ibusimcontext->preedit_mode = IBUS_ENGINE_PREEDIT_CLEAR;
e4fcff
 
e4fcff
     // Init cursor area
e4fcff
     ibusimcontext->cursor_area.x = -1;
e4fcff
@@ -854,6 +862,24 @@ ibus_im_context_finalize (GObject *obj)
e4fcff
     G_OBJECT_CLASS(parent_class)->finalize (obj);
e4fcff
 }
e4fcff
 
e4fcff
+static void
e4fcff
+ibus_im_context_clear_preedit_text (IBusIMContext *ibusimcontext)
e4fcff
+{
e4fcff
+    g_assert (ibusimcontext->ibuscontext);
e4fcff
+    if (ibusimcontext->preedit_visible &&
e4fcff
+        ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
+        gchar *preedit_string = g_strdup (ibusimcontext->preedit_string);
e4fcff
+        _ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
e4fcff
+                                              ibus_text_new_from_string (""),
e4fcff
+                                              0,
e4fcff
+                                              FALSE,
e4fcff
+                                              IBUS_ENGINE_PREEDIT_CLEAR,
e4fcff
+                                              ibusimcontext);
e4fcff
+        g_signal_emit (ibusimcontext, _signal_commit_id, 0, preedit_string);
e4fcff
+        g_free (preedit_string);
e4fcff
+    }
e4fcff
+}
e4fcff
+
e4fcff
 static gboolean
e4fcff
 ibus_im_context_filter_keypress (GtkIMContext *context,
e4fcff
                                  GdkEventKey  *event)
e4fcff
@@ -1003,6 +1029,7 @@ ibus_im_context_focus_out (GtkIMContext *context)
e4fcff
 
e4fcff
     ibusimcontext->has_focus = FALSE;
e4fcff
     if (ibusimcontext->ibuscontext) {
e4fcff
+        ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
         ibus_input_context_focus_out (ibusimcontext->ibuscontext);
e4fcff
     }
e4fcff
 
e4fcff
@@ -1022,6 +1049,12 @@ ibus_im_context_reset (GtkIMContext *context)
e4fcff
     IBusIMContext *ibusimcontext = IBUS_IM_CONTEXT (context);
e4fcff
 
e4fcff
     if (ibusimcontext->ibuscontext) {
e4fcff
+        /* Commented out ibus_im_context_clear_preedit_text().
e4fcff
+         * Hangul needs to receive the reset callback with button press
e4fcff
+         * but other IMEs should avoid to receive the reset callback
e4fcff
+         * so the signal would need to be customized with GtkSetting.
e4fcff
+         * IBus uses button-press-event instead.
e4fcff
+         */
e4fcff
         ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
     }
e4fcff
     gtk_im_context_reset (ibusimcontext->slave);
e4fcff
@@ -1068,21 +1101,67 @@ ibus_im_context_get_preedit_string (GtkIMContext   *context,
e4fcff
 }
e4fcff
 
e4fcff
 
e4fcff
+static gboolean
e4fcff
+ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
+                                       GdkEventButton *event,
e4fcff
+                                       IBusIMContext  *ibusimcontext)
e4fcff
+{
e4fcff
+    if (event->button != 1)
e4fcff
+        return FALSE;
e4fcff
+
e4fcff
+    if (ibusimcontext->preedit_visible &&
e4fcff
+        ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
+        ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
+        if (ibusimcontext->ibuscontext)
e4fcff
+            ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
+    }
e4fcff
+    return FALSE;
e4fcff
+}
e4fcff
+
e4fcff
 static void
e4fcff
 ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
e4fcff
 {
e4fcff
+    IBusIMContext *ibusimcontext;
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
+    GtkWidget *widget;
e4fcff
+#endif
e4fcff
+
e4fcff
     IDEBUG ("%s", __FUNCTION__);
e4fcff
 
e4fcff
-    IBusIMContext *ibusimcontext = IBUS_IM_CONTEXT (context);
e4fcff
+    ibusimcontext = IBUS_IM_CONTEXT (context);
e4fcff
 
e4fcff
     if (ibusimcontext->client_window) {
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
+        gdk_window_get_user_data (ibusimcontext->client_window,
e4fcff
+                                  (gpointer *)&widget);
e4fcff
+        /* firefox needs GtkWidget instead of GtkWindow */
e4fcff
+        if (GTK_IS_WIDGET (widget)) {
e4fcff
+            g_signal_handlers_disconnect_by_func (
e4fcff
+                    widget,
e4fcff
+                    (GCallback)ibus_im_context_button_press_event_cb,
e4fcff
+                    ibusimcontext);
e4fcff
+        }
e4fcff
+#endif
e4fcff
         g_object_unref (ibusimcontext->client_window);
e4fcff
         ibusimcontext->client_window = NULL;
e4fcff
     }
e4fcff
 
e4fcff
-    if (client != NULL)
e4fcff
+    if (client != NULL) {
e4fcff
         ibusimcontext->client_window = g_object_ref (client);
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
+        gdk_window_get_user_data (ibusimcontext->client_window,
e4fcff
+                                  (gpointer *)&widget);
e4fcff
 
e4fcff
+        /* firefox needs GtkWidget instead of GtkWindow */
e4fcff
+        if (GTK_IS_WIDGET (widget)) {
e4fcff
+            g_signal_connect (
e4fcff
+                    widget,
e4fcff
+                    "button-press-event",
e4fcff
+                    G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
+                    ibusimcontext);
e4fcff
+        }
e4fcff
+#endif
e4fcff
+    }
e4fcff
     if (ibusimcontext->slave)
e4fcff
         gtk_im_context_set_client_window (ibusimcontext->slave, client);
e4fcff
 }
e4fcff
@@ -1530,6 +1609,7 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
e4fcff
                                       IBusText          *text,
e4fcff
                                       gint               cursor_pos,
e4fcff
                                       gboolean           visible,
e4fcff
+                                      guint              mode,
e4fcff
                                       IBusIMContext     *ibusimcontext)
e4fcff
 {
e4fcff
     IDEBUG ("%s", __FUNCTION__);
e4fcff
@@ -1586,6 +1666,7 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
e4fcff
 
e4fcff
     flag = ibusimcontext->preedit_visible != visible;
e4fcff
     ibusimcontext->preedit_visible = visible;
e4fcff
+    ibusimcontext->preedit_mode = mode;
e4fcff
 
e4fcff
     if (ibusimcontext->preedit_visible) {
e4fcff
         if (flag) {
e4fcff
@@ -1676,7 +1757,7 @@ _create_input_context_done (IBusBus       *bus,
e4fcff
         g_error_free (error);
e4fcff
     }
e4fcff
     else {
e4fcff
-
e4fcff
+        ibus_input_context_set_client_commit_preedit (context, TRUE);
e4fcff
         ibusimcontext->ibuscontext = context;
e4fcff
 
e4fcff
         g_signal_connect (ibusimcontext->ibuscontext,
e4fcff
@@ -1692,7 +1773,7 @@ _create_input_context_done (IBusBus       *bus,
e4fcff
                           G_CALLBACK (_ibus_context_delete_surrounding_text_cb),
e4fcff
                           ibusimcontext);
e4fcff
         g_signal_connect (ibusimcontext->ibuscontext,
e4fcff
-                          "update-preedit-text",
e4fcff
+                          "update-preedit-text-with-mode",
e4fcff
                           G_CALLBACK (_ibus_context_update_preedit_text_cb),
e4fcff
                           ibusimcontext);
e4fcff
         g_signal_connect (ibusimcontext->ibuscontext,
e4fcff
diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c
e4fcff
index ae7048ad..a809ef08 100644
e4fcff
--- a/src/ibusinputcontext.c
e4fcff
+++ b/src/ibusinputcontext.c
e4fcff
@@ -2,7 +2,8 @@
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
e4fcff
- * Copyright (C) 2008-2013 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
+ * Copyright (C) 2008-2018 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -39,6 +40,7 @@ enum {
e4fcff
     FORWARD_KEY_EVENT,
e4fcff
     DELETE_SURROUNDING_TEXT,
e4fcff
     UPDATE_PREEDIT_TEXT,
e4fcff
+    UPDATE_PREEDIT_TEXT_WITH_MODE,
e4fcff
     SHOW_PREEDIT_TEXT,
e4fcff
     HIDE_PREEDIT_TEXT,
e4fcff
     UPDATE_AUXILIARY_TEXT,
e4fcff
@@ -217,6 +219,34 @@ ibus_input_context_class_init (IBusInputContextClass *class)
e4fcff
             G_TYPE_UINT,
e4fcff
             G_TYPE_BOOLEAN);
e4fcff
 
e4fcff
+    /**
e4fcff
+     * IBusInputContext::update-preedit-text-with-mode:
e4fcff
+     * @context: An IBusInputContext.
e4fcff
+     * @text: Text to be updated.
e4fcff
+     * @cursor_pos: Cursor position.
e4fcff
+     * @visible: Whether the update is visible.
e4fcff
+     * @mode: Preedit mode.
e4fcff
+     *
e4fcff
+     * Emitted to update preedit text with the mode.
e4fcff
+     *
e4fcff
+     * (Note: The text object is floating, and it will be released after the
e4fcff
+     *  signal. If signal handler wants to keep the object, the handler should
e4fcff
+     *  use g_object_ref_sink() to get the ownership of the object.)
e4fcff
+     */
e4fcff
+    context_signals[UPDATE_PREEDIT_TEXT_WITH_MODE] =
e4fcff
+        g_signal_new (I_("update-preedit-text-with-mode"),
e4fcff
+            G_TYPE_FROM_CLASS (class),
e4fcff
+            G_SIGNAL_RUN_LAST,
e4fcff
+            0,
e4fcff
+            NULL, NULL,
e4fcff
+            _ibus_marshal_VOID__OBJECT_UINT_BOOLEAN_UINT,
e4fcff
+            G_TYPE_NONE,
e4fcff
+            4,
e4fcff
+            IBUS_TYPE_TEXT,
e4fcff
+            G_TYPE_UINT,
e4fcff
+            G_TYPE_BOOLEAN,
e4fcff
+            G_TYPE_UINT);
e4fcff
+
e4fcff
     /**
e4fcff
      * IBusInputContext::show-preedit-text:
e4fcff
      * @context: An IBusInputContext.
e4fcff
@@ -542,6 +572,28 @@ ibus_input_context_g_signal (GDBusProxy  *proxy,
e4fcff
             g_object_unref (text);
e4fcff
         return;
e4fcff
     }
e4fcff
+    if (g_strcmp0 (signal_name, "UpdatePreeditTextWithMode") == 0) {
e4fcff
+        GVariant *variant = NULL;
e4fcff
+        gint32 cursor_pos;
e4fcff
+        gboolean visible;
e4fcff
+        guint mode = 0;
e4fcff
+        g_variant_get (parameters,
e4fcff
+                       "(vubu)", &variant, &cursor_pos, &visible, &mode);
e4fcff
+        IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (variant));
e4fcff
+        g_variant_unref (variant);
e4fcff
+
e4fcff
+        g_signal_emit (context,
e4fcff
+                       context_signals[UPDATE_PREEDIT_TEXT_WITH_MODE],
e4fcff
+                       0,
e4fcff
+                       text,
e4fcff
+                       cursor_pos,
e4fcff
+                       visible,
e4fcff
+                       mode);
e4fcff
+
e4fcff
+        if (g_object_is_floating (text))
e4fcff
+            g_object_unref (text);
e4fcff
+        return;
e4fcff
+    }
e4fcff
 
e4fcff
     /* lookup signal in table */
e4fcff
     gint i;
e4fcff
@@ -1043,10 +1095,11 @@ ibus_input_context_set_surrounding_text (IBusInputContext   *context,
e4fcff
                                          guint32             cursor_pos,
e4fcff
                                          guint32             anchor_pos)
e4fcff
 {
e4fcff
+    IBusInputContextPrivate *priv;
e4fcff
+
e4fcff
     g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
     g_assert (IBUS_IS_TEXT (text));
e4fcff
 
e4fcff
-    IBusInputContextPrivate *priv;
e4fcff
     priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
e4fcff
 
e4fcff
     if (cursor_pos != priv->surrounding_cursor_pos ||
e4fcff
@@ -1090,12 +1143,15 @@ ibus_input_context_set_content_type (IBusInputContext *context,
e4fcff
                                      guint             purpose,
e4fcff
                                      guint             hints)
e4fcff
 {
e4fcff
+    GVariant *cached_content_type;
e4fcff
+    GVariant *content_type;
e4fcff
+
e4fcff
     g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
 
e4fcff
-    GVariant *cached_content_type =
e4fcff
+    cached_content_type =
e4fcff
         g_dbus_proxy_get_cached_property ((GDBusProxy *) context,
e4fcff
                                           "ContentType");
e4fcff
-    GVariant *content_type = g_variant_new ("(uu)", purpose, hints);
e4fcff
+    content_type = g_variant_new ("(uu)", purpose, hints);
e4fcff
 
e4fcff
     g_variant_ref_sink (content_type);
e4fcff
     if (cached_content_type == NULL ||
e4fcff
@@ -1142,18 +1198,22 @@ ibus_input_context_get_engine_async_finish (IBusInputContext   *context,
e4fcff
                                             GAsyncResult       *res,
e4fcff
                                             GError            **error)
e4fcff
 {
e4fcff
+    GVariant *variant;
e4fcff
+    GVariant *engine_desc_variant;
e4fcff
+    IBusEngineDesc *desc;
e4fcff
+
e4fcff
     g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
     g_assert (G_IS_ASYNC_RESULT (res));
e4fcff
     g_assert (error == NULL || *error == NULL);
e4fcff
 
e4fcff
-    GVariant *variant = g_dbus_proxy_call_finish ((GDBusProxy *) context,
e4fcff
-                                                   res, error);
e4fcff
+    variant = g_dbus_proxy_call_finish ((GDBusProxy *) context, res, error);
e4fcff
     if (variant == NULL) {
e4fcff
         return NULL;
e4fcff
     }
e4fcff
 
e4fcff
-    GVariant *engine_desc_variant = g_variant_get_child_value (variant, 0);
e4fcff
-    IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engine_desc_variant));
e4fcff
+    engine_desc_variant = g_variant_get_child_value (variant, 0);
e4fcff
+    desc = IBUS_ENGINE_DESC (
e4fcff
+            ibus_serializable_deserialize (engine_desc_variant));
e4fcff
     g_variant_unref (engine_desc_variant);
e4fcff
     g_variant_unref (variant);
e4fcff
 
e4fcff
@@ -1163,9 +1223,13 @@ ibus_input_context_get_engine_async_finish (IBusInputContext   *context,
e4fcff
 IBusEngineDesc *
e4fcff
 ibus_input_context_get_engine (IBusInputContext *context)
e4fcff
 {
e4fcff
-    g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
     GVariant *result = NULL;
e4fcff
     GError *error = NULL;
e4fcff
+    GVariant *engine_desc_variant;
e4fcff
+    IBusEngineDesc *desc;
e4fcff
+
e4fcff
+    g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
+
e4fcff
     result = g_dbus_proxy_call_sync ((GDBusProxy *) context,
e4fcff
                                      "GetEngine",               /* method_name */
e4fcff
                                      NULL,                      /* parameters */
e4fcff
@@ -1189,8 +1253,9 @@ ibus_input_context_get_engine (IBusInputContext *context)
e4fcff
         return NULL;
e4fcff
     }
e4fcff
 
e4fcff
-    GVariant *engine_desc_variant = g_variant_get_child_value (result, 0);
e4fcff
-    IBusEngineDesc *desc = IBUS_ENGINE_DESC (ibus_serializable_deserialize (engine_desc_variant));
e4fcff
+    engine_desc_variant = g_variant_get_child_value (result, 0);
e4fcff
+    desc = IBUS_ENGINE_DESC (
e4fcff
+            ibus_serializable_deserialize (engine_desc_variant));
e4fcff
     g_variant_unref (engine_desc_variant);
e4fcff
     g_variant_unref (result);
e4fcff
 
e4fcff
@@ -1214,6 +1279,41 @@ ibus_input_context_set_engine (IBusInputContext *context,
e4fcff
                        );
e4fcff
 }
e4fcff
 
e4fcff
+void
e4fcff
+ibus_input_context_set_client_commit_preedit (IBusInputContext *context,
e4fcff
+                                              gboolean          client_commit)
e4fcff
+{
e4fcff
+    GVariant *cached_content_type;
e4fcff
+    GVariant *var_client_commit;
e4fcff
+
e4fcff
+    g_assert (IBUS_IS_INPUT_CONTEXT (context));
e4fcff
+
e4fcff
+    cached_content_type =
e4fcff
+        g_dbus_proxy_get_cached_property ((GDBusProxy *) context,
e4fcff
+                                          "ClientCommitPreedit");
e4fcff
+    var_client_commit = g_variant_new ("(b)", client_commit);
e4fcff
+
e4fcff
+    g_variant_ref_sink (var_client_commit);
e4fcff
+    if (cached_content_type == NULL) {
e4fcff
+        g_dbus_proxy_call ((GDBusProxy *) context,
e4fcff
+                           "org.freedesktop.DBus.Properties.Set",
e4fcff
+                           g_variant_new ("(ssv)",
e4fcff
+                                          IBUS_INTERFACE_INPUT_CONTEXT,
e4fcff
+                                          "ClientCommitPreedit",
e4fcff
+                                          var_client_commit),
e4fcff
+                           G_DBUS_CALL_FLAGS_NONE,
e4fcff
+                           -1,
e4fcff
+                           NULL, /* cancellable */
e4fcff
+                           NULL, /* callback */
e4fcff
+                           NULL  /* user_data */
e4fcff
+                           );
e4fcff
+    }
e4fcff
+
e4fcff
+    if (cached_content_type != NULL)
e4fcff
+        g_variant_unref (cached_content_type);
e4fcff
+    g_variant_unref (var_client_commit);
e4fcff
+}
e4fcff
+
e4fcff
 #define DEFINE_FUNC(name, Name)                                         \
e4fcff
     void                                                                \
e4fcff
     ibus_input_context_##name (IBusInputContext *context)               \
e4fcff
diff --git a/src/ibusinputcontext.h b/src/ibusinputcontext.h
e4fcff
index a77cf92f..09992148 100644
e4fcff
--- a/src/ibusinputcontext.h
e4fcff
+++ b/src/ibusinputcontext.h
e4fcff
@@ -2,7 +2,8 @@
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
e4fcff
- * Copyright (C) 2008-2013 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
+ * Copyright (C) 2008-2018 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -498,5 +499,29 @@ void         ibus_input_context_set_content_type
e4fcff
                                              guint               purpose,
e4fcff
                                              guint               hints);
e4fcff
 
e4fcff
+/**
e4fcff
+ * ibus_input_context_set_client_commit_preedit:
e4fcff
+ * @context: An #IBusInputContext.
e4fcff
+ * @client_commit: %TRUE if your input context commits pre-edit texts
e4fcff
+ *     with Space or Enter key events or mouse click events. %FALSE if
e4fcff
+ *     ibus-daemon commits pre-edit texts with those events.
e4fcff
+ *     The default is %FALSE. The behavior is decided with
e4fcff
+ *     ibus_engine_update_preedit_text_with_mode() to commit, clear or
e4fcff
+ *     keep the pre-edit text and this API is important in ibus-hangul.
e4fcff
+ *
e4fcff
+ * Set whether #IBusInputContext commits pre-edit texts or not.
e4fcff
+ * If %TRUE, 'update-preedit-text-with-mode' signal is emitted
e4fcff
+ * instead of 'update-preedit-text' signal.
e4fcff
+ * If your client receives the 'update-preedit-text-with-mode' signal,
e4fcff
+ * the client needs to implement commit_text() of pre-edit text when
e4fcff
+ * GtkIMContextClass.focus_out() is called in case an IME desires that
e4fcff
+ * behavior but it depends on each IME.
e4fcff
+ *
e4fcff
+ * See also ibus_engine_update_preedit_text_with_mode().
e4fcff
+ */
e4fcff
+void         ibus_input_context_set_client_commit_preedit (
e4fcff
+                                             IBusInputContext   *context,
e4fcff
+                                             gboolean            client_commit);
e4fcff
+
e4fcff
 G_END_DECLS
e4fcff
 #endif
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From 7b3b8c8b0c6a41ab524e0be9474825da9cba96ac Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Tue, 13 Nov 2018 14:27:52 +0900
e4fcff
Subject: [PATCH] client/gtk2: Do not delete IBUS_CAP_SURROUNDING_TEXT
e4fcff
e4fcff
retrieve-surrounding signal could be failed with the first typing
e4fcff
on firefox. It could be a bug in firefox but now IBusIMContext does not
e4fcff
delete IBUS_CAP_SURROUNDING_TEXT in the capabilities as a workaround
e4fcff
when retrieve-surrounding signal is failed.
e4fcff
Also added retrieve-surrounding signal after some committing text.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/2054
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 11 ++++++++---
e4fcff
 1 file changed, 8 insertions(+), 3 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index 73a0eaec..82af51a1 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -298,6 +298,7 @@ ibus_im_context_commit_event (IBusIMContext *ibusimcontext,
e4fcff
         IBusText *text = ibus_text_new_from_unichar (ch);
e4fcff
         g_signal_emit (ibusimcontext, _signal_commit_id, 0, text->text);
e4fcff
         g_object_unref (text);
e4fcff
+        _request_surrounding_text (ibusimcontext);
e4fcff
         return TRUE;
e4fcff
     }
e4fcff
    return FALSE;
e4fcff
@@ -386,9 +387,12 @@ _request_surrounding_text (IBusIMContext *context)
e4fcff
         g_signal_emit (context, _signal_retrieve_surrounding_id, 0,
e4fcff
                        &return_value);
e4fcff
         if (!return_value) {
e4fcff
-            context->caps &= ~IBUS_CAP_SURROUNDING_TEXT;
e4fcff
-            ibus_input_context_set_capabilities (context->ibuscontext,
e4fcff
-                                                 context->caps);
e4fcff
+            /* #2054 firefox::IMContextWrapper::GetCurrentParagraph() could
e4fcff
+             * fail with the first typing on firefox but it succeeds with
e4fcff
+             * the second typing.
e4fcff
+             */
e4fcff
+            g_warning ("%s has no capability of surrounding-text feature",
e4fcff
+                       g_get_prgname ());
e4fcff
         }
e4fcff
     }
e4fcff
 }
e4fcff
@@ -877,6 +881,7 @@ ibus_im_context_clear_preedit_text (IBusIMContext *ibusimcontext)
e4fcff
                                               ibusimcontext);
e4fcff
         g_signal_emit (ibusimcontext, _signal_commit_id, 0, preedit_string);
e4fcff
         g_free (preedit_string);
e4fcff
+        _request_surrounding_text (ibusimcontext);
e4fcff
     }
e4fcff
 }
e4fcff
 
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From 4c40afba9c862b4f6651b1b971553e5e89e83343 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Thu, 6 Dec 2018 16:53:57 +0900
e4fcff
Subject: [PATCH] client/gtk2: Always reset and clear preedit on mouse click
e4fcff
e4fcff
Thinking about the reset signal again, now I think it's good to emit
e4fcff
the reset signal and clear the preedit on mouse click for any engines
e4fcff
besides Hangul because the behavior could be handled by each engine
e4fcff
with the reset signal.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 26 +++++++++++++-------------
e4fcff
 1 file changed, 13 insertions(+), 13 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index 82af51a1..ed7fea6e 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -869,16 +869,19 @@ ibus_im_context_finalize (GObject *obj)
e4fcff
 static void
e4fcff
 ibus_im_context_clear_preedit_text (IBusIMContext *ibusimcontext)
e4fcff
 {
e4fcff
+    gchar *preedit_string = NULL;
e4fcff
     g_assert (ibusimcontext->ibuscontext);
e4fcff
     if (ibusimcontext->preedit_visible &&
e4fcff
         ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
-        gchar *preedit_string = g_strdup (ibusimcontext->preedit_string);
e4fcff
-        _ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
e4fcff
-                                              ibus_text_new_from_string (""),
e4fcff
-                                              0,
e4fcff
-                                              FALSE,
e4fcff
-                                              IBUS_ENGINE_PREEDIT_CLEAR,
e4fcff
-                                              ibusimcontext);
e4fcff
+        preedit_string = g_strdup (ibusimcontext->preedit_string);
e4fcff
+    }
e4fcff
+    _ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
e4fcff
+                                          ibus_text_new_from_string (""),
e4fcff
+                                          0,
e4fcff
+                                          FALSE,
e4fcff
+                                          IBUS_ENGINE_PREEDIT_CLEAR,
e4fcff
+                                          ibusimcontext);
e4fcff
+    if (preedit_string) {
e4fcff
         g_signal_emit (ibusimcontext, _signal_commit_id, 0, preedit_string);
e4fcff
         g_free (preedit_string);
e4fcff
         _request_surrounding_text (ibusimcontext);
e4fcff
@@ -1114,12 +1117,9 @@ ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
     if (event->button != 1)
e4fcff
         return FALSE;
e4fcff
 
e4fcff
-    if (ibusimcontext->preedit_visible &&
e4fcff
-        ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
-        ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
-        if (ibusimcontext->ibuscontext)
e4fcff
-            ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
-    }
e4fcff
+    ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
+    if (ibusimcontext->ibuscontext)
e4fcff
+        ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
     return FALSE;
e4fcff
 }
e4fcff
 
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From c7d8771cb9fc652cb638aa7cb8e10ea6b889509e Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Tue, 11 Dec 2018 19:16:10 +0900
e4fcff
Subject: [PATCH] client/gtk2: Fix SEGV on mouse clicks when ibus-daemon not
e4fcff
 running
e4fcff
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 5 +++--
e4fcff
 1 file changed, 3 insertions(+), 2 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index ed7fea6e..ab7ff88a 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -1117,9 +1117,10 @@ ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
     if (event->button != 1)
e4fcff
         return FALSE;
e4fcff
 
e4fcff
-    ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
-    if (ibusimcontext->ibuscontext)
e4fcff
+    if (ibusimcontext->ibuscontext) {
e4fcff
+        ibus_im_context_clear_preedit_text (ibusimcontext);
e4fcff
         ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
+    }
e4fcff
     return FALSE;
e4fcff
 }
e4fcff
 
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From 9ae2d4658fff3d1e7262fb4fb7ca9ce1af0a27ec Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Thu, 20 Dec 2018 16:40:31 +0900
e4fcff
Subject: [PATCH] client/gtk2: Use button-press-event only with
e4fcff
 IBUS_ENGINE_PREEDIT_COMMIT
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 66 ++++++++++++++++++++++++-------------
e4fcff
 1 file changed, 43 insertions(+), 23 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index ab7ff88a..f9310867 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -72,6 +72,8 @@ struct _IBusIMContext {
e4fcff
     /* cancellable */
e4fcff
     GCancellable    *cancellable;
e4fcff
     GQueue          *events_queue;
e4fcff
+
e4fcff
+    gboolean use_button_press_event;
e4fcff
 };
e4fcff
 
e4fcff
 struct _IBusIMContextClass {
e4fcff
@@ -1109,6 +1111,7 @@ ibus_im_context_get_preedit_string (GtkIMContext   *context,
e4fcff
 }
e4fcff
 
e4fcff
 
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
 static gboolean
e4fcff
 ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
                                        GdkEventButton *event,
e4fcff
@@ -1124,13 +1127,37 @@ ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
     return FALSE;
e4fcff
 }
e4fcff
 
e4fcff
+static void
e4fcff
+_connect_button_press_event (IBusIMContext *ibusimcontext,
e4fcff
+                             gboolean       do_connect)
e4fcff
+{
e4fcff
+    GtkWidget *widget = NULL;
e4fcff
+
e4fcff
+    g_assert (ibusimcontext->client_window);
e4fcff
+    gdk_window_get_user_data (ibusimcontext->client_window,
e4fcff
+                              (gpointer *)&widget);
e4fcff
+    /* firefox needs GtkWidget instead of GtkWindow */
e4fcff
+    if (GTK_IS_WIDGET (widget)) {
e4fcff
+        if (do_connect) {
e4fcff
+            g_signal_connect (
e4fcff
+                    widget,
e4fcff
+                    "button-press-event",
e4fcff
+                    G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
+                    ibusimcontext);
e4fcff
+        } else {
e4fcff
+            g_signal_handlers_disconnect_by_func (
e4fcff
+                    widget,
e4fcff
+                    G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
+                    ibusimcontext);
e4fcff
+        }
e4fcff
+    }
e4fcff
+}
e4fcff
+#endif
e4fcff
+
e4fcff
 static void
e4fcff
 ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
e4fcff
 {
e4fcff
     IBusIMContext *ibusimcontext;
e4fcff
-#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
-    GtkWidget *widget;
e4fcff
-#endif
e4fcff
 
e4fcff
     IDEBUG ("%s", __FUNCTION__);
e4fcff
 
e4fcff
@@ -1138,15 +1165,8 @@ ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
e4fcff
 
e4fcff
     if (ibusimcontext->client_window) {
e4fcff
 #if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
-        gdk_window_get_user_data (ibusimcontext->client_window,
e4fcff
-                                  (gpointer *)&widget);
e4fcff
-        /* firefox needs GtkWidget instead of GtkWindow */
e4fcff
-        if (GTK_IS_WIDGET (widget)) {
e4fcff
-            g_signal_handlers_disconnect_by_func (
e4fcff
-                    widget,
e4fcff
-                    (GCallback)ibus_im_context_button_press_event_cb,
e4fcff
-                    ibusimcontext);
e4fcff
-        }
e4fcff
+        if (ibusimcontext->use_button_press_event)
e4fcff
+            _connect_button_press_event (ibusimcontext, FALSE);
e4fcff
 #endif
e4fcff
         g_object_unref (ibusimcontext->client_window);
e4fcff
         ibusimcontext->client_window = NULL;
e4fcff
@@ -1155,17 +1175,8 @@ ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
e4fcff
     if (client != NULL) {
e4fcff
         ibusimcontext->client_window = g_object_ref (client);
e4fcff
 #if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
-        gdk_window_get_user_data (ibusimcontext->client_window,
e4fcff
-                                  (gpointer *)&widget);
e4fcff
-
e4fcff
-        /* firefox needs GtkWidget instead of GtkWindow */
e4fcff
-        if (GTK_IS_WIDGET (widget)) {
e4fcff
-            g_signal_connect (
e4fcff
-                    widget,
e4fcff
-                    "button-press-event",
e4fcff
-                    G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
-                    ibusimcontext);
e4fcff
-        }
e4fcff
+        if (ibusimcontext->use_button_press_event)
e4fcff
+            _connect_button_press_event (ibusimcontext, TRUE);
e4fcff
 #endif
e4fcff
     }
e4fcff
     if (ibusimcontext->slave)
e4fcff
@@ -1631,6 +1642,15 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
e4fcff
         ibusimcontext->preedit_attrs = NULL;
e4fcff
     }
e4fcff
 
e4fcff
+    if (!ibusimcontext->use_button_press_event &&
e4fcff
+        mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
+        if (ibusimcontext->client_window)
e4fcff
+            _connect_button_press_event (ibusimcontext, TRUE);
e4fcff
+#endif
e4fcff
+        ibusimcontext->use_button_press_event = TRUE;
e4fcff
+    }
e4fcff
+
e4fcff
     str = text->text;
e4fcff
     ibusimcontext->preedit_string = g_strdup (str);
e4fcff
     if (text->attrs) {
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From 0fd043c3b4c90855bfb4fceed4bf2f3c3635a041 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Tue, 8 Jan 2019 12:02:32 +0900
e4fcff
Subject: [PATCH] portal: Update APIs for Hangul preedit in Flatpak
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 portal/org.freedesktop.IBus.Portal.xml |  9 ++++++++-
e4fcff
 portal/portal.c                        | 18 +++++++++++++++++-
e4fcff
 2 files changed, 25 insertions(+), 2 deletions(-)
e4fcff
e4fcff
diff --git a/portal/org.freedesktop.IBus.Portal.xml b/portal/org.freedesktop.IBus.Portal.xml
e4fcff
index afce4daa..376ad424 100644
e4fcff
--- a/portal/org.freedesktop.IBus.Portal.xml
e4fcff
+++ b/portal/org.freedesktop.IBus.Portal.xml
e4fcff
@@ -1,6 +1,6 @@
e4fcff
 
e4fcff
 
e4fcff
- Copyright (C) 2017 Red Hat, Inc.
e4fcff
+ Copyright (C) 2017-2019 Red Hat, Inc.
e4fcff
 
e4fcff
  This library is free software; you can redistribute it and/or
e4fcff
  modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -97,6 +97,12 @@
e4fcff
       <arg type='u' name='cursor_pos' />
e4fcff
       <arg type='b' name='visible' />
e4fcff
     </signal>
e4fcff
+    <signal name='UpdatePreeditTextWithMode'>
e4fcff
+      <arg type='v' name='text' />
e4fcff
+      <arg type='u' name='cursor_pos' />
e4fcff
+      <arg type='b' name='visible' />
e4fcff
+      <arg type='u' name='mode' />
e4fcff
+    </signal>
e4fcff
     <signal name='ShowPreeditText'/>
e4fcff
     <signal name='HidePreeditText'/>
e4fcff
     <signal name='UpdateAuxiliaryText'>
e4fcff
@@ -123,6 +129,7 @@
e4fcff
     </signal>
e4fcff
 
e4fcff
     <property name='ContentType' type='(uu)' access='write' />
e4fcff
+    <property name='ClientCommitPreedit' type='(b)' access='write' />
e4fcff
   </interface>
e4fcff
 
e4fcff
   <interface name='org.freedesktop.IBus.Service'>
e4fcff
diff --git a/portal/portal.c b/portal/portal.c
e4fcff
index cb24d257..e78bc92f 100644
e4fcff
--- a/portal/portal.c
e4fcff
+++ b/portal/portal.c
e4fcff
@@ -1,7 +1,7 @@
e4fcff
 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
- * Copyright (C) 2017 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2017-2019 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -67,6 +67,7 @@ struct _IBusPortalClass
e4fcff
 enum
e4fcff
 {
e4fcff
     PROP_CONTENT_TYPE = 1,
e4fcff
+    PROP_CLIENT_COMMIT_PREEDIT,
e4fcff
     N_PROPERTIES
e4fcff
 };
e4fcff
 
e4fcff
@@ -315,6 +316,20 @@ ibus_portal_context_set_property (IBusPortalContext *portal_context,
e4fcff
                            NULL  /* user_data */
e4fcff
                            );
e4fcff
         break;
e4fcff
+    case PROP_CLIENT_COMMIT_PREEDIT:
e4fcff
+        g_dbus_proxy_call (G_DBUS_PROXY (portal_context->context),
e4fcff
+                           "org.freedesktop.DBus.Properties.Set",
e4fcff
+                           g_variant_new ("(ssv)",
e4fcff
+                                          IBUS_INTERFACE_INPUT_CONTEXT,
e4fcff
+                                          "ClientCommitPreedit",
e4fcff
+                                          g_value_get_variant (value)),
e4fcff
+                           G_DBUS_CALL_FLAGS_NONE,
e4fcff
+                           -1,
e4fcff
+                           NULL, /* cancellable */
e4fcff
+                           NULL, /* callback */
e4fcff
+                           NULL  /* user_data */
e4fcff
+                           );
e4fcff
+        break;
e4fcff
     default:
e4fcff
         G_OBJECT_WARN_INVALID_PROPERTY_ID (portal_context, prop_id, pspec);
e4fcff
     }
e4fcff
@@ -328,6 +343,7 @@ ibus_portal_context_get_property (IBusPortalContext *portal_context,
e4fcff
 {
e4fcff
     switch (prop_id) {
e4fcff
     case PROP_CONTENT_TYPE:
e4fcff
+    case PROP_CLIENT_COMMIT_PREEDIT:
e4fcff
         g_warning ("No support for setting content type");
e4fcff
         break;
e4fcff
     default:
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From be7fb813e530442897a9f9130b8a26380e5a12a1 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Tue, 8 Jan 2019 12:02:37 +0900
e4fcff
Subject: [PATCH] client/gtk2: Fix Atom and Slack for Flatpak
e4fcff
e4fcff
Seems Atom, slack, com.visualstudio.code does not enable
e4fcff
gtk_key_snooper_install() and this issue causes to call
e4fcff
gtk_im_context_filter_keypress instead of calling ibus APIs.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1991
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 4 ++++
e4fcff
 1 file changed, 4 insertions(+)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index f9310867..264a747a 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -565,6 +565,10 @@ daemon_name_appeared (GDBusConnection *connection,
e4fcff
                       const gchar     *owner,
e4fcff
                       gpointer         data)
e4fcff
 {
e4fcff
+    if (!g_strcmp0 (ibus_bus_get_service_name (_bus), IBUS_SERVICE_PORTAL)) {
e4fcff
+        _daemon_is_running = TRUE;
e4fcff
+        return;
e4fcff
+    }
e4fcff
     /* If ibus-daemon is running and run ssh -X localhost,
e4fcff
      * daemon_name_appeared() is called but ibus_get_address() == NULL
e4fcff
      * because the hostname and display number are different between
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From cebe7a9553de69943b955ec99285f74961c9ee4e Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Thu, 9 May 2019 15:49:21 +0900
e4fcff
Subject: [PATCH] client/gtk2: Keep preedit cursor_pos and visible in clearing
e4fcff
 preedit text
e4fcff
e4fcff
Clear the preedit_string but keep the preedit_cursor_pos and
e4fcff
preedit_visible because a time lag could happen, firefox commit
e4fcff
the preedit text before the preedit text is cleared and it cause
e4fcff
a double commits of the Hangul preedit in firefox if the preedit
e4fcff
would be located on the URL bar and click on anywhere of firefox
e4fcff
out of the URL bar.
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 12 ++++++++++--
e4fcff
 1 file changed, 10 insertions(+), 2 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index 264a747a..5e3457ba 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -881,10 +881,18 @@ ibus_im_context_clear_preedit_text (IBusIMContext *ibusimcontext)
e4fcff
         ibusimcontext->preedit_mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
         preedit_string = g_strdup (ibusimcontext->preedit_string);
e4fcff
     }
e4fcff
+
e4fcff
+    /* Clear the preedit_string but keep the preedit_cursor_pos and
e4fcff
+     * preedit_visible because a time lag could happen, firefox commit
e4fcff
+     * the preedit text before the preedit text is cleared and it cause
e4fcff
+     * a double commits of the Hangul preedit in firefox if the preedit
e4fcff
+     * would be located on the URL bar and click on anywhere of firefox
e4fcff
+     * out of the URL bar.
e4fcff
+     */
e4fcff
     _ibus_context_update_preedit_text_cb (ibusimcontext->ibuscontext,
e4fcff
                                           ibus_text_new_from_string (""),
e4fcff
-                                          0,
e4fcff
-                                          FALSE,
e4fcff
+                                          ibusimcontext->preedit_cursor_pos,
e4fcff
+                                          ibusimcontext->preedit_visible,
e4fcff
                                           IBUS_ENGINE_PREEDIT_CLEAR,
e4fcff
                                           ibusimcontext);
e4fcff
     if (preedit_string) {
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From 25d11f5cfd4c39e53be11a1348da29a61593cc4c Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Wed, 11 Dec 2019 16:28:22 +0900
e4fcff
Subject: [PATCH] client/gtk2: Fix to set use_button_press_event after signals
e4fcff
 are connected
e4fcff
e4fcff
_ibus_context_update_preedit_text_cb() can be called with reset signals
e4fcff
before ibus_im_context_set_client_window() is called. Then
e4fcff
use_button_press_event needs to be set only when the signals are connected.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 12 ++++++++----
e4fcff
 1 file changed, 8 insertions(+), 4 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index 5e3457ba..ac5de809 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -1074,8 +1074,9 @@ ibus_im_context_reset (GtkIMContext *context)
e4fcff
         /* Commented out ibus_im_context_clear_preedit_text().
e4fcff
          * Hangul needs to receive the reset callback with button press
e4fcff
          * but other IMEs should avoid to receive the reset callback
e4fcff
-         * so the signal would need to be customized with GtkSetting.
e4fcff
-         * IBus uses button-press-event instead.
e4fcff
+         * by themselves.
e4fcff
+         * IBus uses button-press-event instead until GTK is fixed.
e4fcff
+         * https://gitlab.gnome.org/GNOME/gtk/issues/1534
e4fcff
          */
e4fcff
         ibus_input_context_reset (ibusimcontext->ibuscontext);
e4fcff
     }
e4fcff
@@ -1657,10 +1658,13 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
e4fcff
     if (!ibusimcontext->use_button_press_event &&
e4fcff
         mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
 #if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
-        if (ibusimcontext->client_window)
e4fcff
+        if (ibusimcontext->client_window) {
e4fcff
             _connect_button_press_event (ibusimcontext, TRUE);
e4fcff
-#endif
e4fcff
+            ibusimcontext->use_button_press_event = TRUE;
e4fcff
+        }
e4fcff
+#else
e4fcff
         ibusimcontext->use_button_press_event = TRUE;
e4fcff
+#endif
e4fcff
     }
e4fcff
 
e4fcff
     str = text->text;
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From c662a02bf3b50914c697af12fc152ee97e2df961 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Wed, 25 Dec 2019 17:30:56 +0900
e4fcff
Subject: [PATCH] client/gtk2: Fix to connect button-press-event signal
e4fcff
e4fcff
IBus clients do not connect button-press-event in some conditions
e4fcff
and it will be fixed.
e4fcff
e4fcff
BUG=https://github.com/ibus/ibus/issues/1980
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 21 ++++++++++++---------
e4fcff
 1 file changed, 12 insertions(+), 9 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index ac5de809..30585403 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -2,8 +2,8 @@
e4fcff
 /* vim:set et sts=4: */
e4fcff
 /* ibus - The Input Bus
e4fcff
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
e4fcff
- * Copyright (C) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
- * Copyright (C) 2008-2018 Red Hat, Inc.
e4fcff
+ * Copyright (C) 2015-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
e4fcff
+ * Copyright (C) 2008-2019 Red Hat, Inc.
e4fcff
  *
e4fcff
  * This library is free software; you can redistribute it and/or
e4fcff
  * modify it under the terms of the GNU Lesser General Public
e4fcff
@@ -73,7 +73,7 @@ struct _IBusIMContext {
e4fcff
     GCancellable    *cancellable;
e4fcff
     GQueue          *events_queue;
e4fcff
 
e4fcff
-    gboolean use_button_press_event;
e4fcff
+    gboolean         use_button_press_event;
e4fcff
 };
e4fcff
 
e4fcff
 struct _IBusIMContextClass {
e4fcff
@@ -1125,6 +1125,10 @@ ibus_im_context_get_preedit_string (GtkIMContext   *context,
e4fcff
 
e4fcff
 
e4fcff
 #if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
+/* Use the button-press-event signal until GtkIMContext always emits the reset
e4fcff
+ * signal.
e4fcff
+ * https://gitlab.gnome.org/GNOME/gtk/merge_requests/460
e4fcff
+ */
e4fcff
 static gboolean
e4fcff
 ibus_im_context_button_press_event_cb (GtkWidget      *widget,
e4fcff
                                        GdkEventButton *event,
e4fcff
@@ -1157,11 +1161,13 @@ _connect_button_press_event (IBusIMContext *ibusimcontext,
e4fcff
                     "button-press-event",
e4fcff
                     G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
                     ibusimcontext);
e4fcff
+            ibusimcontext->use_button_press_event = TRUE;
e4fcff
         } else {
e4fcff
             g_signal_handlers_disconnect_by_func (
e4fcff
                     widget,
e4fcff
                     G_CALLBACK (ibus_im_context_button_press_event_cb),
e4fcff
                     ibusimcontext);
e4fcff
+            ibusimcontext->use_button_press_event = FALSE;
e4fcff
         }
e4fcff
     }
e4fcff
 }
e4fcff
@@ -1188,7 +1194,7 @@ ibus_im_context_set_client_window (GtkIMContext *context, GdkWindow *client)
e4fcff
     if (client != NULL) {
e4fcff
         ibusimcontext->client_window = g_object_ref (client);
e4fcff
 #if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
-        if (ibusimcontext->use_button_press_event)
e4fcff
+        if (!ibusimcontext->use_button_press_event)
e4fcff
             _connect_button_press_event (ibusimcontext, TRUE);
e4fcff
 #endif
e4fcff
     }
e4fcff
@@ -1655,17 +1661,14 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
e4fcff
         ibusimcontext->preedit_attrs = NULL;
e4fcff
     }
e4fcff
 
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
     if (!ibusimcontext->use_button_press_event &&
e4fcff
         mode == IBUS_ENGINE_PREEDIT_COMMIT) {
e4fcff
-#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
         if (ibusimcontext->client_window) {
e4fcff
             _connect_button_press_event (ibusimcontext, TRUE);
e4fcff
-            ibusimcontext->use_button_press_event = TRUE;
e4fcff
         }
e4fcff
-#else
e4fcff
-        ibusimcontext->use_button_press_event = TRUE;
e4fcff
-#endif
e4fcff
     }
e4fcff
+#endif
e4fcff
 
e4fcff
     str = text->text;
e4fcff
     ibusimcontext->preedit_string = g_strdup (str);
e4fcff
-- 
e4fcff
2.24.1
e4fcff
e4fcff
From ecc3465a585448486b2ce68bcefc11d6aebae755 Mon Sep 17 00:00:00 2001
e4fcff
From: fujiwarat <takao.fujiwara1@gmail.com>
e4fcff
Date: Thu, 23 Jan 2020 16:13:05 +0900
e4fcff
Subject: [PATCH] client/gtk2: Fix some format sentences
e4fcff
e4fcff
---
e4fcff
 client/gtk2/ibusimcontext.c | 23 +++++++++++------------
e4fcff
 1 file changed, 11 insertions(+), 12 deletions(-)
e4fcff
e4fcff
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
e4fcff
index 30585403..50290c55 100644
e4fcff
--- a/client/gtk2/ibusimcontext.c
e4fcff
+++ b/client/gtk2/ibusimcontext.c
e4fcff
@@ -73,7 +73,9 @@ struct _IBusIMContext {
e4fcff
     GCancellable    *cancellable;
e4fcff
     GQueue          *events_queue;
e4fcff
 
e4fcff
+#if !GTK_CHECK_VERSION (3, 93, 0)
e4fcff
     gboolean         use_button_press_event;
e4fcff
+#endif
e4fcff
 };
e4fcff
 
e4fcff
 struct _IBusIMContextClass {
e4fcff
@@ -137,12 +139,12 @@ static void     ibus_im_context_set_surrounding
e4fcff
 
e4fcff
 /* static methods*/
e4fcff
 static void     _ibus_context_update_preedit_text_cb
e4fcff
-                                           (IBusInputContext   *ibuscontext,
e4fcff
-                                            IBusText           *text,
e4fcff
-                                            gint                cursor_pos,
e4fcff
-                                            gboolean            visible,
e4fcff
-                                            guint               mode,
e4fcff
-                                            IBusIMContext      *ibusimcontext);
e4fcff
+                                            (IBusInputContext   *ibuscontext,
e4fcff
+                                             IBusText           *text,
e4fcff
+                                             gint                cursor_pos,
e4fcff
+                                             gboolean            visible,
e4fcff
+                                             guint               mode,
e4fcff
+                                             IBusIMContext      *ibusimcontext);
e4fcff
 static void     _create_input_context       (IBusIMContext      *context);
e4fcff
 static gboolean _set_cursor_location_internal
e4fcff
                                             (IBusIMContext      *context);
e4fcff
@@ -172,7 +174,6 @@ static void     _create_fake_input_context  (void);
e4fcff
 static gboolean _set_content_type           (IBusIMContext      *context);
e4fcff
 
e4fcff
 
e4fcff
-
e4fcff
 static GType                _ibus_type_im_context = 0;
e4fcff
 static GtkIMContextClass    *parent_class = NULL;
e4fcff
 
e4fcff
@@ -313,7 +314,6 @@ _process_key_event_done (GObject      *object,
e4fcff
 {
e4fcff
     IBusInputContext *context = (IBusInputContext *)object;
e4fcff
     GdkEventKey *event = (GdkEventKey *) user_data;
e4fcff
-
e4fcff
     GError *error = NULL;
e4fcff
     gboolean retval = ibus_input_context_process_key_event_async_finish (
e4fcff
             context,
e4fcff
@@ -362,12 +362,10 @@ _process_key_event (IBusInputContext *context,
e4fcff
         retval = TRUE;
e4fcff
     }
e4fcff
 
e4fcff
-    if (retval) {
e4fcff
+    if (retval)
e4fcff
         event->state |= IBUS_HANDLED_MASK;
e4fcff
-    }
e4fcff
-    else {
e4fcff
+    else
e4fcff
         event->state |= IBUS_IGNORED_MASK;
e4fcff
-    }
e4fcff
 
e4fcff
     return retval;
e4fcff
 }
e4fcff
@@ -1508,6 +1506,7 @@ _key_is_modifier (guint keyval)
e4fcff
         return FALSE;
e4fcff
     }
e4fcff
 }
e4fcff
+
e4fcff
 /* Copy from gdk */
e4fcff
 static GdkEventKey *
e4fcff
 _create_gdk_event (IBusIMContext *ibusimcontext,
e4fcff
-- 
e4fcff
2.24.1
e4fcff