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

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