Blob Blame History Raw
From 571e3b6e4f386abf12d3db70b9468e092c8d72bd Mon Sep 17 00:00:00 2001
From: Alynx Zhou <alynx.zhou@gmail.com>
Date: Tue, 24 Aug 2021 10:12:52 +0800
Subject: [PATCH] client/gtk2/ibusimcontext: Fix wrong cursor location in gtk3
 apps

If you apply this patch in your tarball, please also apply this to
client/gtk3/ibusimcontext.c besides client/gtk2/ibusimcontext.c .

BUG=https://github.com/ibus/ibus/issues/2337
---
 client/gtk2/ibusimcontext.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index da9a402f..b1ccede9 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -1497,7 +1497,10 @@ _set_cursor_location_internal (IBusIMContext *ibusimcontext)
 
 #if GTK_CHECK_VERSION (3, 98, 4)
 #elif GTK_CHECK_VERSION (2, 91, 0)
-    area.y += gdk_window_get_height (ibusimcontext->client_window);
+    if (area.x == -1 && area.y == -1 && area.width == 0 && area.height == 0) {
+        area.x = 0;
+        area.y += gdk_window_get_height (ibusimcontext->client_window);
+    }
 #else
     if (area.x == -1 && area.y == -1 && area.width == 0 && area.height == 0) {
         gint w, h;
-- 
2.31.1

From 5487a6baa4b22605ba8197ca1a0fa43c91d57786 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Mon, 6 Sep 2021 20:23:59 +0900
Subject: [PATCH] client/gtk2/ibusimcontext: Implement clear preedit for GTK4

IBus IM module uses synchornized key processes for GTK4 and the timing
of the GTK reset siginal may work with focus-in/out between windows.
(I don't test GTK4 firefox and terminal yet and the verification is not
completed.)
So ibus_im_context_clear_preedit_text() is now called with the GTK4 reset
siginal.
ibus_im_context_clear_preedit_text() works with ibus-setup-anthy ->
"Conversion" tab -> "Behavior on Focus Out" pull down menu.

BUG=https://github.com/ibus/ibus/issues/2334
---
 client/gtk2/ibusimcontext.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index b1ccede9..e12be45d 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -1270,6 +1270,8 @@ ibus_im_context_reset (GtkIMContext *context)
          * IBus uses button-press-event instead until GTK is fixed.
          * https://gitlab.gnome.org/GNOME/gtk/issues/1534
          */
+        if (_use_sync_mode)
+            ibus_im_context_clear_preedit_text (ibusimcontext);
         ibus_input_context_reset (ibusimcontext->ibuscontext);
     }
     gtk_im_context_reset (ibusimcontext->slave);
@@ -1383,7 +1385,7 @@ ibus_im_context_set_client_window (GtkIMContext *context,
 
     if (ibusimcontext->client_window) {
 #if !GTK_CHECK_VERSION (3, 98, 4)
-        if (ibusimcontext->use_button_press_event)
+        if (ibusimcontext->use_button_press_event && !_use_sync_mode)
             _connect_button_press_event (ibusimcontext, FALSE);
 #endif
         g_object_unref (ibusimcontext->client_window);
@@ -1393,7 +1395,7 @@ ibus_im_context_set_client_window (GtkIMContext *context,
     if (client != NULL) {
         ibusimcontext->client_window = g_object_ref (client);
 #if !GTK_CHECK_VERSION (3, 98, 4)
-        if (!ibusimcontext->use_button_press_event)
+        if (!ibusimcontext->use_button_press_event && !_use_sync_mode)
             _connect_button_press_event (ibusimcontext, TRUE);
 #endif
     }
@@ -1994,7 +1996,8 @@ _ibus_context_update_preedit_text_cb (IBusInputContext  *ibuscontext,
 
 #if !GTK_CHECK_VERSION (3, 98, 4)
     if (!ibusimcontext->use_button_press_event &&
-        mode == IBUS_ENGINE_PREEDIT_COMMIT) {
+        mode == IBUS_ENGINE_PREEDIT_COMMIT &&
+        !_use_sync_mode) {
         if (ibusimcontext->client_window) {
             _connect_button_press_event (ibusimcontext, TRUE);
         }
-- 
2.28.0

From 4957d1468db4fc5ed30c3ae1f2afac9e51b329d6 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Mon, 6 Sep 2021 20:25:52 +0900
Subject: [PATCH] client/gtk2/ibusimcontext: Calculate keycode from keysym in
 GTK3 forward-key-event

IBus GTK3 mode also calculates keycode from keysym if keycode == 0
with forward-key-event signal to follow GTK4.
---
 client/gtk2/ibusimcontext.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index e12be45d..b1424e87 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -1939,13 +1939,16 @@ _ibus_context_forward_key_event_cb (IBusInputContext  *ibuscontext,
     int group = 0;
     g_return_if_fail (GTK_IS_IM_CONTEXT (ibusimcontext));
     if (keycode == 0 && ibusimcontext->client_window) {
-        GdkDisplay *display = gtk_widget_get_display (ibusimcontext->client_window);
+        GdkDisplay *display =
+                gtk_widget_get_display (ibusimcontext->client_window);
         GdkKeymapKey *keys = NULL;
         gint n_keys = 0;
-        if (!gdk_display_map_keyval (display, keyval, &keys, &n_keys))
+        if (gdk_display_map_keyval (display, keyval, &keys, &n_keys)) {
+            keycode = keys->keycode;
+            group = keys->group;
+        } else {
             g_warning ("Failed to parse keycode from keyval %x", keyval);
-       keycode = keys->keycode;
-       group = keys->group;
+        }
     }
     gtk_im_context_filter_key (
         GTK_IM_CONTEXT (ibusimcontext),
@@ -1957,6 +1960,17 @@ _ibus_context_forward_key_event_cb (IBusInputContext  *ibuscontext,
         (GdkModifierType)state,
         group);
 #else
+    if (keycode == 0 && ibusimcontext->client_window) {
+        GdkDisplay *display =
+                gdk_window_get_display (ibusimcontext->client_window);
+        GdkKeymap *keymap = gdk_keymap_get_for_display (display);
+        GdkKeymapKey *keys = NULL;
+        gint n_keys = 0;
+        if (gdk_keymap_get_entries_for_keyval (keymap, keyval, &keys, &n_keys))
+            keycode = keys->keycode;
+        else
+            g_warning ("Failed to parse keycode from keyval %x", keyval);
+    }
     GdkEventKey *event = _create_gdk_event (ibusimcontext, keyval, keycode, state);
     gdk_event_put ((GdkEvent *)event);
     gdk_event_free ((GdkEvent *)event);
-- 
2.28.0

From fbea5441fc53ae1d5533bed1ee53009141cf905a Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Fri, 10 Sep 2021 00:09:26 +0900
Subject: [PATCH] Fix build errors in Ubuntu focal

- Ubuntu focal uses glib 2.64.6 which does not include errno.h
  so config.h includes errno.h as the workaround.
- make autogen.sh not to delete dist files in Travis
- Call $(PYTHON) for gensimple.py for Ubuntu python3
- Add a code review in src/ibuscomposetable.c

BUG=https://github.com/ibus/ibus/pull/2348
---
 autogen.sh             | 2 +-
 configure.ac           | 9 +++++++++
 engine/Makefile.am     | 2 +-
 src/ibuscomposetable.c | 4 ++++
 src/ibusregistry.c     | 4 ++++
 src/ibusshare.c        | 3 +++
 6 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index 693a2740..ea633e06 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -53,4 +53,4 @@ ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.11 CFLAGS="$CFL
         echo "rm $f"
         rm $f
     done
-}
+} || :
diff --git a/configure.ac b/configure.ac
index 29f8b3db..ce096ad3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,6 +162,15 @@ PKG_CHECK_MODULES(GIO2, [
 PKG_CHECK_MODULES(GTHREAD2, [
     gthread-2.0 >= glib_required_version
 ])
+PKG_CHECK_EXISTS(
+    [glib-2.0 >= 2.65.0],
+    [AC_DEFINE(GLIB2_EMBED_ERRNO_H, TRUE, [glib2 include errno.h])]
+)
+AH_BOTTOM([
+#ifndef GLIB2_EMBED_ERRNO_H
+#  include <errno.h>
+#endif
+])
 
 # --disable-tests option.
 AC_ARG_ENABLE(tests,
diff --git a/engine/Makefile.am b/engine/Makefile.am
index 84bc7f6c..03867f52 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -99,7 +99,7 @@ simple.xml: simple.xml.in
 	    mv $@.tmp $@
 
 simple.xml.in:
-	$(srcdir)/gensimple.py \
+	$(PYTHON) $(srcdir)/gensimple.py \
 	    --input=$(XKBCONFIG_BASE)/rules/evdev.xml \
 	    --output=$@ \
 	    --version=$(VERSION).`date '+%Y%m%d'` \
diff --git a/src/ibuscomposetable.c b/src/ibuscomposetable.c
index d4184d30..b76464bc 100644
--- a/src/ibuscomposetable.c
+++ b/src/ibuscomposetable.c
@@ -18,6 +18,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
  * USA
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -1606,6 +1609,7 @@ ibus_compose_table_compact_check (const IBusComposeTableCompactEx
             row_stride = i + 1;
 
             if (seq_index[i + 1] - seq_index[i] > 0) {
+                g_assert (row_stride);
                 seq = bsearch (compose_buffer + 1,
                                table->data + seq_index[i],
                                (seq_index[i + 1] - seq_index[i]) / row_stride,
diff --git a/src/ibusregistry.c b/src/ibusregistry.c
index 23c5ca1b..962afb20 100644
--- a/src/ibusregistry.c
+++ b/src/ibusregistry.c
@@ -20,6 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
  * USA
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <gio/gio.h>
 #include <glib/gstdio.h>
 #include <string.h>
diff --git a/src/ibusshare.c b/src/ibusshare.c
index 8974511a..0c0bda10 100644
--- a/src/ibusshare.c
+++ b/src/ibusshare.c
@@ -20,6 +20,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
  * USA
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "ibusshare.h"
 #include <glib.h>
-- 
2.33.1

From 943d37444d9cc0881cb5fff87bdd4b9efd5abdb4 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Mon, 9 Aug 2021 12:49:15 +0900
Subject: [PATCH] client/gtk2/ibusimcontext: Fix a key event loop with
 forwarding keys.

_ibus_context_forward_key_event_cb() caused a key event loop in
_key_snooper_cb() with key release events.
---
 client/gtk2/ibusimcontext.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index da9a402f..e66125df 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -366,6 +366,10 @@ ibus_im_context_commit_event (IBusIMContext *ibusimcontext,
         g_signal_emit (ibusimcontext, _signal_commit_id, 0, text->text);
         g_object_unref (text);
         _request_surrounding_text (ibusimcontext);
+#if !GTK_CHECK_VERSION (3, 98, 4)
+        /* Avoid a loop with _ibus_context_forward_key_event_cb() */
+        event->state |= IBUS_HANDLED_MASK;
+#endif
         return TRUE;
     }
    return FALSE;
@@ -643,12 +647,15 @@ _key_snooper_cb (GtkWidget   *widget,
 
     } while (0);
 
-    if (ibusimcontext != NULL) {
+    if (ibusimcontext != NULL && event->type == GDK_KEY_PRESS) {
         /* "retrieve-surrounding" signal sometimes calls unref by
          * gtk_im_multicontext_get_slave() because priv->context_id is not
          * the latest than global_context_id in GtkIMMulticontext.
          * Since _focus_im_context is gotten by the focus_in event,
          * it would be good to call ref here.
+         *
+         * Most release key events would be redundant from
+         * _ibus_context_forward_key_event_cb ().
          */
         g_object_ref (ibusimcontext);
         _request_surrounding_text (ibusimcontext);
@@ -657,7 +664,7 @@ _key_snooper_cb (GtkWidget   *widget,
 
     retval = _process_key_event (ibuscontext, event, ibusimcontext);
 
-    if (ibusimcontext != NULL) {
+    if (ibusimcontext != NULL && event->type == GDK_KEY_PRESS) {
         /* unref ibusimcontext could call ibus_im_context_finalize here
          * because "retrieve-surrounding" signal could call unref.
          */
-- 
2.28.0

From 179ebddf4dbde1cef1cea2df4e659cf4940d1a30 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Fri, 27 Aug 2021 20:05:02 +0900
Subject: [PATCH] src/tests: Add --screendump option in
 ibus-desktop-testing-runner

The screendump is useful in CI to if check gnome-shell-extension-no-overview
works.
Also add ibus-desktop-testing-autostart to get the debug info in CI.
You can copy ibus-desktop-testing.desktop to $HOME/.config/autostart
if CI fails.
---
 src/tests/Makefile.am                     | 11 +++++
 src/tests/ibus-desktop-testing-autostart  | 55 +++++++++++++++++++++++
 src/tests/ibus-desktop-testing-runner.in  | 20 +++++++--
 src/tests/ibus-desktop-testing.desktop.in | 11 +++++
 4 files changed, 93 insertions(+), 4 deletions(-)
 create mode 100755 src/tests/ibus-desktop-testing-autostart
 create mode 100644 src/tests/ibus-desktop-testing.desktop.in

diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 13c06eb4..7d00f236 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -96,6 +96,7 @@ test_sourcesdir = $(datadir)/installed-tests/ibus
 CLEANFILES += \
     $(test_metas) \
     ibus-desktop-testing-runner \
+    org.freedesktop.IBus.Desktop.Testing.desktop \
     $(NULL)
 
 test_execs_PROGRAMS = $(TESTS)
@@ -106,6 +107,14 @@ CLEANFILES += \
     $(NULL)
 endif
 test_execsdir = $(libexecdir)/installed-tests/ibus
+libexec_SCRIPTS = ibus-desktop-testing-autostart
+
+test_frame_DATA = org.freedesktop.IBus.Desktop.Testing.desktop
+test_framedir = $(pkgdatadir)/tests
+org.freedesktop.IBus.Desktop.Testing.desktop: ibus-desktop-testing.desktop.in
+	$(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|g" \
+	$< > $@.tmp && \
+	mv $@.tmp $@
 endif
 
 $(test_metas): $(test_metas_in) $(test_programs)
@@ -133,6 +142,8 @@ EXTRA_DIST = \
     ibus-compose.emoji \
     ibus-compose.env \
     ibus-compose-locales.in \
+    ibus-desktop-testing.desktop.in \
+    ibus-desktop-testing-autostart \
     ibus-desktop-testing-runner.in \
     $(NULL)
 
diff --git a/src/tests/ibus-desktop-testing-autostart b/src/tests/ibus-desktop-testing-autostart
new file mode 100755
index 00000000..da22b64e
--- /dev/null
+++ b/src/tests/ibus-desktop-testing-autostart
@@ -0,0 +1,55 @@
+#!/bin/sh
+# -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2021 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+TEST_LOG=
+COMMANDS='
+id
+echo $DISPLAY
+pwd
+pstree -asp $$
+gsettings list-recursively org.gnome.shell
+rpm -q gnome-shell-extension-no-overview gnome-shell gnome-session
+'
+
+if [ $# -gt 0 ] ; then
+    TEST_LOG=$1
+fi
+
+run_test()
+{
+while read cmd ; do
+    if [ x"$cmd" = x ] ; then
+        continue
+    fi
+    echo "# $cmd"
+    eval "$cmd"
+done << EOF_COMMANDS
+`echo "$COMMANDS"`
+EOF_COMMANDS
+}
+
+if [ x"$TEST_LOG" = x ] ; then
+    run_test
+else
+    run_test 2>>$TEST_LOG 1>>$TEST_LOG
+fi
diff --git a/src/tests/ibus-desktop-testing-runner.in b/src/tests/ibus-desktop-testing-runner.in
index c1016703..48528326 100755
--- a/src/tests/ibus-desktop-testing-runner.in
+++ b/src/tests/ibus-desktop-testing-runner.in
@@ -36,13 +36,14 @@
 
 
 PROGNAME=`basename $0`
-VERSION=0.2
+VERSION=0.3
 DISPLAY=:99.0
 BUILDDIR="."
 SRCDIR="."
 TEST_LOG="test-suite.log"
 TEST_LOG_STDOUT=0
 RESULT_LOG=""
+SCREEN_LOG=""
 HAVE_GRAPHICS=1
 DESKTOP_COMMAND="dbus-launch --exit-with-session gnome-session"
 PID_XORG=0
@@ -90,14 +91,15 @@ usage()
 "-T, --timeout=TIMEOUT            Set timeout (default TIMEOUT is 300 sec).\n" \
 "-o, --output=OUTPUT_FILE         OUtput the log to OUTPUT_FILE\n"             \
 "-O, --result=RESULT_FILE         OUtput the result to RESULT_FILE\n"          \
+"-S, --screendump=DUMP_FILE       OUtput the screen to DUMP_FILE ('STDOUT' can be stdout)\n" \
 ""
 }
 
 parse_args()
 {
     # This is GNU getopt. "sudo port getopt" in BSD?
-    ARGS=`getopt -o hvb:s:cd:t:r:T:o:O: --long \
-          help,version,builddir:,srcdir:,no-graphics,desktop:,tests:,runner:,timeout:,output:,result:\
+    ARGS=`getopt -o hvb:s:cd:t:r:T:o:O:S: --long \
+          help,version,builddir:,srcdir:,no-graphics,desktop:,tests:,runner:,timeout:,output:,result:,screendump:\
         -- "$@"`;
     eval set -- "$ARGS"
     while [ 1 ] ; do
@@ -113,6 +115,7 @@ parse_args()
         -T | --timeout )     TIMEOUT="$2"; shift 2;;
         -o | --output )      TEST_LOG="$2"; shift 2;;
         -O | --result )      RESULT_LOG="$2"; shift 2;;
+        -S | --screendump )  SCREEN_LOG="$2"; shift 2;;
         -- )                 shift; break;;
         * )                  usage; exit 1;;
         esac
@@ -259,6 +262,7 @@ run_desktop()
 {
     echo "$DESKTOP_COMMAND" | grep gnome-session > /dev/null
     HAS_GNOME=$?
+    export DISPLAY=$DISPLAY
     if test $HAVE_GRAPHICS -eq 1 ; then
         /usr/libexec/Xorg.wrap -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./xorg.log -config ./xorg.conf -configdir . $DISPLAY &
     else
@@ -266,7 +270,6 @@ run_desktop()
     fi
     PID_XORG=$!
     sleep 1
-    export DISPLAY=$DISPLAY
     # init_gnome need to be called with $DISPLAY before gnome-session is called
     if [  $HAS_GNOME -eq 0 ] ; then
         init_gnome
@@ -454,6 +457,15 @@ main()
     init_desktop
     run_dbus_daemon 2>>$TEST_LOG 1>>$TEST_LOG
     run_desktop 2>>$TEST_LOG 1>>$TEST_LOG
+    if [ x"$SCREEN_LOG" != x ] ; then
+        SCREEN_PNG="`date '+%Y%m%d%H%M%S'`.png"
+        gnome-screenshot --file=$SCREEN_PNG
+        if [ x"$SCREEN_LOG" = xSTDOUT ] ; then
+            base64 $SCREEN_PNG
+        else
+            base64 $SCREEN_PNG > $SCREEN_LOG
+        fi
+    fi
     run_test_suite
     finit
 }
diff --git a/src/tests/ibus-desktop-testing.desktop.in b/src/tests/ibus-desktop-testing.desktop.in
new file mode 100644
index 00000000..fa0c9b40
--- /dev/null
+++ b/src/tests/ibus-desktop-testing.desktop.in
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Name=IBus Desktop Testing Runner
+GenericName=Input Method Desktop Testing Runner
+Comment=Test plugin for IBus Desktop Testing
+Exec=@ibexecdir@/ibus-desktop-testing-autostart /var/tmp/ibus-ci-autostart.log
+Terminal=false
+Type=Application
+Encoding=UTF-8
+Icon=ibus
+Categories=System
+Keywords=im;
-- 
2.28.0

From acc5570511698c7b5cc037eb81be2c4be52a824f Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Fri, 29 Oct 2021 12:56:49 +0900
Subject: [PATCH] ui/gtk3: Erase Emojier preedit/lookup popup between
 applications

It would be better to erase Emojier popup window when users change
the input focus between applications. But it hasn't been implemented
because the focus-out/in events also happen when the Emojier popup window
is launching or rebuilding to the category list in GNOME Wayland.
The focus-out/in events do not happen in Xorg desktops with the rebuilding
GUI because GTK popup window causes focus-in/out evnets in Wayland.

Now I'm convinced with several issues and added a little complicated logic
to erase Emojier popup window with the focus changes between input contexts
to handle focus-in/out events in Wayland.

BUG=rhbz#1942970
---
 ui/gtk3/emojier.vala      | 69 ++++++++++++++++++++++++++++++++++++---
 ui/gtk3/emojierapp.vala   | 12 +++++--
 ui/gtk3/panelbinding.vala | 21 ++++++++++--
 3 files changed, 94 insertions(+), 8 deletions(-)

diff --git a/ui/gtk3/emojier.vala b/ui/gtk3/emojier.vala
index 9e6e9263..69fb8abe 100644
--- a/ui/gtk3/emojier.vala
+++ b/ui/gtk3/emojier.vala
@@ -2,7 +2,7 @@
  *
  * ibus - The Input Bus
  *
- * Copyright (c) 2017-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (c) 2017-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -227,6 +227,8 @@ public class IBusEmojier : Gtk.ApplicationWindow {
         BACKWARD,
     }
 
+    public bool is_wayland { get; set; }
+
     public const uint BUTTON_CLOSE_BUTTON = 1000;
 
     private const uint EMOJI_GRID_PAGE = 10;
@@ -317,15 +319,18 @@ public class IBusEmojier : Gtk.ApplicationWindow {
     private Gdk.Rectangle m_cursor_location;
     private bool m_is_up_side_down = false;
     private uint m_redraw_window_id;
+    private bool m_rebuilding_gui = false;
+    private uint m_rebuilding_gui_timeout_id;
 
     public signal void candidate_clicked(uint index, uint button, uint state);
     public signal void commit_text(string text);
     public signal void cancel();
 
-    public IBusEmojier() {
+    public IBusEmojier(bool is_wayland) {
         GLib.Object(
             type : Gtk.WindowType.POPUP
         );
+        this.is_wayland = is_wayland;
 
         // GLib.ActionEntry accepts const variables only.
         var action = new GLib.SimpleAction.stateful(
@@ -1002,6 +1007,7 @@ public class IBusEmojier : Gtk.ApplicationWindow {
         button.button_press_event.connect((w, e) => {
             m_category_active_index = -1;
             m_show_unicode = false;
+            start_rebuild_gui(false);
             hide_candidate_panel();
             show_all();
             return true;
@@ -1458,6 +1464,7 @@ public class IBusEmojier : Gtk.ApplicationWindow {
                     show_emoji_for_category(m_backward);
                     show_candidate_panel();
                 } else {
+                    start_rebuild_gui(false);
                     hide_candidate_panel();
                     show_all();
                 }
@@ -1778,6 +1785,34 @@ public class IBusEmojier : Gtk.ApplicationWindow {
     }
 
 
+    private void start_rebuild_gui(bool initial_launching) {
+        if (!this.is_wayland)
+            return;
+        if (!initial_launching && !base.get_visible())
+            return;
+        if (initial_launching && base.get_visible())
+            return;
+        if (m_rebuilding_gui_timeout_id != 0) {
+            GLib.Source.remove(m_rebuilding_gui_timeout_id);
+            m_rebuilding_gui_timeout_id = 0;
+        }
+
+        m_rebuilding_gui = true;
+        m_rebuilding_gui_timeout_id =
+                GLib.Timeout.add_seconds(10, () => {
+                    if (!m_rebuilding_gui) {
+                        m_rebuilding_gui_timeout_id = 0;
+                        return false;
+                    }
+                    warning("Rebuilding GUI is time out.");
+                    m_rebuilding_gui = false;
+                    m_rebuilding_gui_timeout_id = 0;
+                    return false;
+                },
+                GLib.Priority.DEFAULT_IDLE);
+    }
+
+
     public bool has_variants(uint index,
                              bool need_commit_signal) {
         if (index >= m_lookup_table.get_number_of_candidates())
@@ -1880,12 +1915,17 @@ public class IBusEmojier : Gtk.ApplicationWindow {
                 m_show_unicode = false;
                 m_category_active_index = -1;
             }
+            start_rebuild_gui(false);
             hide_candidate_panel();
             return true;
         } else if (m_backward_index >= 0 && m_backward != null) {
+            // Escape on Emoji variants window does not call focus-out events
+            // because hide() is not called here so start_rebuild_gui()
+            // is not called.
             show_emoji_for_category(m_backward);
             return true;
         } else if (m_candidate_panel_is_visible && m_backward != null) {
+            start_rebuild_gui(false);
             hide_candidate_panel();
             return true;
         }
@@ -2218,7 +2258,7 @@ public class IBusEmojier : Gtk.ApplicationWindow {
 
         /* Some window managers, e.g. MATE, GNOME, Plasma desktops,
          * does not give the keyboard focus when Emojier is lauched
-         * twice with Ctrl-Shift-e via XIEvent, if present_with_time()
+         * twice with Ctrl-period via XIEvent, if present_with_time()
          * is not applied.
          * But XFCE4 desktop does not effect this bug.
          * Seems this is caused by the window manager's focus stealing
@@ -2265,8 +2305,10 @@ public class IBusEmojier : Gtk.ApplicationWindow {
 #endif
 
 
-    /* override virtual functions */
+    // override virtual functions
     public override void show_all() {
+        // Ctrl-period, space keys causes focus-out/in events in GNOME Wayland.
+        start_rebuild_gui(true);
         base.show_all();
         if (m_candidate_panel_mode)
             show_candidate_panel();
@@ -2416,6 +2458,17 @@ public class IBusEmojier : Gtk.ApplicationWindow {
     }
 
 
+    public override bool focus_in_event(Gdk.EventFocus event) {
+        m_rebuilding_gui = false;
+        return base.focus_in_event(event);
+    }
+
+
+    public override bool focus_out_event(Gdk.EventFocus event) {
+        return base.focus_out_event(event);
+    }
+
+
     public bool is_running() {
         return m_is_running;
     }
@@ -2511,6 +2564,14 @@ public class IBusEmojier : Gtk.ApplicationWindow {
     }
 
 
+    public bool is_rebuilding_gui() {
+        /* The candidate window and preedit text should not be closed
+         * when the GUI is rebuilding.
+         */
+        return m_rebuilding_gui;
+    }
+
+
     public static bool has_loaded_emoji_dict() {
         if (m_emoji_to_data_dict == null)
             return false;
diff --git a/ui/gtk3/emojierapp.vala b/ui/gtk3/emojierapp.vala
index 783c611c..812356f0 100644
--- a/ui/gtk3/emojierapp.vala
+++ b/ui/gtk3/emojierapp.vala
@@ -3,7 +3,7 @@
  * ibus - The Input Bus
  *
  * Copyright (c) 2017 Peng Wu <alexepico@gmail.com>
- * Copyright (c) 2017-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (c) 2017-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -208,7 +208,15 @@ public class EmojiApplication : Gtk.Application {
         IBusEmojier.load_unicode_dict();
 
         if (m_emojier == null) {
-            m_emojier = new IBusEmojier();
+            bool is_wayland = false;
+#if USE_GDK_WAYLAND
+            Type instance_type = Gdk.Display.get_default().get_type();
+            Type wayland_type = typeof(GdkWayland.Display);
+            is_wayland = instance_type.is_a(wayland_type);
+#else
+            warning("Checking Wayland is disabled");
+#endif
+            m_emojier = new IBusEmojier(is_wayland);
             // For title handling in gnome-shell
             add_window(m_emojier);
             m_emojier.candidate_clicked.connect((i, b, s) => {
diff --git a/ui/gtk3/panelbinding.vala b/ui/gtk3/panelbinding.vala
index 861255b1..e63d93f2 100644
--- a/ui/gtk3/panelbinding.vala
+++ b/ui/gtk3/panelbinding.vala
@@ -3,7 +3,7 @@
  * ibus - The Input Bus
  *
  * Copyright(c) 2018 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright(c) 2018-2020 Takao Fujwiara <takao.fujiwara1@gmail.com>
+ * Copyright(c) 2018-2021 Takao Fujwiara <takao.fujiwara1@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -799,6 +799,23 @@ class PanelBinding : IBus.PanelService {
 
     public override void focus_out(string input_context_path) {
         m_current_context_path = "";
+        /* Close emoji typing when the focus out happens but it's not a
+         * rebuilding GUI.
+         * Emojier rebuilding GUI happens when Escape key is pressed on
+         * Emojier candidate list and the rebuilding also causes focus-out/in
+         * events in GNOME Wayland but not Xorg desktops.
+         * The rebuilding GUI can be checked with m_emojier.is_rebuilding_gui()
+         * in Wayland.
+         * m_emojier.is_rebuilding_gui() always returns false in Xorg desktops
+         * since focus-out/in events does not happen.
+         */
+        if (m_emojier != null && !m_emojier.is_rebuilding_gui()) {
+            m_preedit.reset();
+            m_emojier.set_annotation("");
+            if (m_wayland_lookup_table_is_visible)
+                hide_wayland_lookup_table();
+            key_press_escape();
+        }
     }
 
 
@@ -822,7 +839,7 @@ class PanelBinding : IBus.PanelService {
             m_loaded_unicode = true;
         }
         if (m_emojier == null) {
-            m_emojier = new IBusEmojier();
+            m_emojier = new IBusEmojier(m_is_wayland);
             // For title handling in gnome-shell
             m_application.add_window(m_emojier);
             m_emojier.candidate_clicked.connect((i, b, s) => {
-- 
2.28.0

From 28acfd433b3df1673b7c7177915c027ce48c061e Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Fri, 5 Nov 2021 07:22:34 +0900
Subject: [PATCH] ui/gtk2: Deprecate gettext.bind_textdomain_codeset()
 since Python 3.8

setup/i18n.py is a symlink of ui/gtk2/i18n.py
env PYTHONWARNINGS='d' ibus-setup

BUG=https://github.com/ibus/ibus/issues/2276
---
 setup/i18n.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/setup/i18n.py b/setup/i18n.py
index 976d1aee..af14efc6 100644
--- a/setup/i18n.py
+++ b/setup/i18n.py
@@ -3,7 +3,9 @@
 # ibus - The Input Bus
 #
 # Copyright(c) 2007-2015 Peng Huang <shawn.p.huang@gmail.com>
+# Copyright(c) 2012-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright(c) 2007-2015 Google, Inc.
+# Copyright(c) 2012-2021 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -23,12 +25,14 @@
 import locale
 import gettext
 import os
+import sys
 
 DOMAINNAME = "ibus10"
 
 _ = lambda a: gettext.dgettext(DOMAINNAME, a)
 N_ = lambda a: a
 
+PY3K = sys.version_info >= (3, 0)
 LOCALEDIR = os.getenv("IBUS_LOCALEDIR")
 
 def init_textdomain(domainname):
@@ -42,7 +46,9 @@ def init_textdomain(domainname):
     except AttributeError:
         pass
     gettext.bindtextdomain(domainname, LOCALEDIR)
-    gettext.bind_textdomain_codeset(domainname, 'UTF-8')
+    # https://docs.python.org/3/library/gettext.html#gettext.lgettext
+    if not PY3K:
+        gettext.bind_textdomain_codeset(domainname, 'UTF-8')
 
 def gettext_engine_longname(engine):
     name = engine.get_name()
-- 
2.33.1

From cfcc6f194cfc95ab0cf1b3b719d77321c249a83b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Na=C3=AFm=20Favier?= <n@monade.li>
Date: Tue, 16 Nov 2021 00:33:37 +0100
Subject: [PATCH] src/ibuscomposetable: invalidate cache based on symlink
 mtime too

When the compose file is a symbolic link, take the link itself's
modification time into account (in addition to its target's) in
determining whether to invalidate the compose cache.

This is useful e.g. on NixOS systems where the compose file might point
to a store path with an irrelevant modification time, and we want the
cache to expire when the symlink itself changes.

BUG=https://github.com/ibus/ibus/pull/2362
---
 src/ibuscomposetable.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/ibuscomposetable.c b/src/ibuscomposetable.c
index b76464bc..250e0139 100644
--- a/src/ibuscomposetable.c
+++ b/src/ibuscomposetable.c
@@ -1040,10 +1040,14 @@ ibus_compose_table_load_cache (const gchar *compose_file)
         if (!g_file_test (path, G_FILE_TEST_EXISTS))
             break;
 
-        if (g_stat (compose_file, &original_buf))
-            break;
         if (g_stat (path, &cache_buf))
             break;
+        if (g_lstat (compose_file, &original_buf))
+            break;
+        if (original_buf.st_mtime > cache_buf.st_mtime)
+            break;
+        if (g_stat (compose_file, &original_buf))
+            break;
         if (original_buf.st_mtime > cache_buf.st_mtime)
             break;
         if (!g_file_get_contents (path, &contents, &length, &error)) {
-- 
2.33.1

From 2bc47f09832073c87ccdf1060bd93ff95878685a Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Thu, 2 Dec 2021 23:52:36 +0900
Subject: [PATCH] autogen: Delete gnome-autogen dependency

You may like to call ./autogen.sh --enable-gtk-doc with your custom
configure options.
Also set SAVE_DIST_FILE=1 by default
---
 autogen.sh      | 96 +++++++++++++++++++++++++++++++++----------------
 src/Makefile.am | 18 ++++++----
 3 files changed, 80 insertions(+), 41 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index ea633e06..1acbf705 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,22 +1,47 @@
 #!/bin/sh
 # Run this to generate all the initial makefiles, etc.
 
-srcdir=`dirname $0`
-test -z "$srcdir" && srcdir=.
-
-PKG_NAME="ibus"
-DIST_FILES="
-engine/simple.xml.in
-src/ibusemojigen.h
-src/ibusunicodegen.h
-"
+: ${srcdir=$(dirname $0)}
+: ${srcdir:=.}
+: ${SAVE_DIST_FILES:=0}
+
+olddir=$(pwd)
+# shellcheck disable=SC2016
+PKG_NAME=$(autoconf --trace 'AC_INIT:$1' configure.ac)
+WANT_GTK_DOC=0
+GCC_VERSION=$(gcc --version | head -1 | awk '{print $3}')
+GCC_MAJOR_VERSION=$(echo "$GCC_VERSION" | awk -F. '{print $1}')
 FEDORA_PKG1='autoconf automake libtool gettext-devel'
 FEDORA_PKG2='glib2-devel gtk2-devel gtk3-devel
  wayland-devel'
 FEDORA_PKG3='cldr-emoji-annotation iso-codes-devel unicode-emoji unicode-ucd
  xkeyboard-config-devel'
 
-(test -z "$DISABLE_INSTALL_PKGS") && {
+CFLAGS=${CFLAGS-"-Wall -Wformat -Werror=format-security"}
+(test $GCC_MAJOR_VERSION -ge 10) && {
+    CFLAGS="$CFLAGS -fanalyzer -fsanitize=address -fsanitize=leak"
+    FEDORA_PKG1="$FEDORA_PKG1 libasan"
+}
+
+cd "$srcdir"
+
+(test -f configure.ac \
+  && test -f README ) || {
+    echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
+    echo " top-level $PKG_NAME directory"
+    exit 1
+}
+
+(test $(grep -q "^GTK_DOC_CHECK" configure.ac)) || {
+    WANT_GTK_DOC=1
+    FEDORA_PKG2="$FEDORA_PKG2 gtk-doc"
+}
+
+(test -f ChangeLog) || {
+    touch ChangeLog
+}
+
+(test "x$DISABLE_INSTALL_PKGS" = "x") && {
     (test -f /etc/fedora-release ) && {
         rpm -q $FEDORA_PKG1 || exit 1
         rpm -q $FEDORA_PKG2 || exit 1
@@ -27,30 +52,39 @@ FEDORA_PKG3='cldr-emoji-annotation iso-codes-devel unicode-emoji unicode-ucd
     }
 }
 
-(test -f $srcdir/configure.ac \
-  && test -f $srcdir/README ) || {
-    echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
-    echo " top-level $PKG_NAME directory"
-    exit 1
-}
-
-which gnome-autogen.sh || {
-    echo "Not found gnome-autogen.sh. You may need to install gnome-common"
-    exit 1
+CONFIGFLAGS="$@"
+(test "$#" = 0 -a "x$NOCONFIGURE" = "x" ) && {
+    echo "*** WARNING: I am going to run 'configure' with no arguments." >&2
+    echo "*** If you wish to pass any to it, please specify them on the" >&2
+    echo "*** '$0' command line." >&2
+    echo "" >&2
+    (test $WANT_GTK_DOC -eq 1) && CONFIGFLAGS="--enable-gtk-doc $@"
 }
 
-(test -f $srcdir/ChangeLog) || {
-    touch $srcdir/ChangeLog
-}
+(test $WANT_GTK_DOC -eq 1) && gtkdocize --copy
 
-CFLAGS=${CFLAGS-"-Wall -Wformat -Werror=format-security"}
+ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.11 \
+autoreconf --verbose --force --install || exit 1
 
-# need --enable-gtk-doc for gnome-autogen.sh to make dist
-ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I m4" REQUIRED_AUTOMAKE_VERSION=1.11 CFLAGS="$CFLAGS" . gnome-autogen.sh "$@"
+cd "$olddir"
+(test "x$NOCONFIGURE" = "x" ) && {
+    echo "$srcdir/configure $CONFIGFLAGS"
+    $srcdir/configure $CONFIGFLAGS || exit 1
+    (test "$1" = "--help" ) && {
+        exit 0
+    } || {
+        echo "Now type 'make' to compile $PKG_NAME" || exit 1
+    }
+} || {
+    echo "Skipping configure process."
+}
 
-(test -z "$SAVE_DIST_FILES") && {
-    for f in $DIST_FILES ; do
-        echo "rm $f"
-        rm $f
-    done
+cd "$srcdir"
+(test "x$SAVE_DIST_FILES" = "x0" ) && {
+    # rm engine/simple.xml.in src/ibusemojigen.h src/ibusunicodegen.h
+    for d in engine src; do
+        echo "make -C $d maintainer-clean-generic"
+        make -C $d maintainer-clean-generic
+   done
 } || :
+cd "$olddir"
diff --git a/src/Makefile.am b/src/Makefile.am
index 742ee7d7..578694b5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@
 # ibus - The Input Bus
 #
 # Copyright (c) 2007-2015 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2015-2020 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2015-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2017 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
@@ -296,8 +296,8 @@ dicts/emoji-%.dict: emoji-parser
 	    echo "Skip $$plus_comment $@"; \
 	fi;
 
-ibusemojigen.h: dicts/emoji-en.dict
-	$(NULL)
+ibusemojigen.h:
+	$(MAKE) $(AM_MAKEFLAGS) dicts/emoji-en.dict
 
 # We put dicts/emoji-%.dict as the make target for the parallel build
 # and the make target has to be genarated even if the file size is zero.
@@ -364,8 +364,8 @@ dicts/unicode-blocks.dict: unicode-parser
 	    echo "Generated $@"; \
 	fi;
 
-ibusunicodegen.h: dicts/unicode-blocks.dict
-	$(NULL)
+ibusunicodegen.h:
+	$(MAKE) $(AM_MAKEFLAGS) dicts/unicode-blocks.dict
 
 unicode_parser_SOURCES =        \
     unicode-parser.c            \
@@ -398,9 +398,15 @@ CLEANFILES +=                   \
     stamp-ibusenumtypes.h       \
     $(NULL)
 
-DISTCLEANFILES =                \
+MAINTAINERCLEANFILES =          \
     ibusemojigen.h              \
     ibusunicodegen.h            \
+    dicts/emoji-en.dict         \
+    dicts/unicode-blocks.dict   \
+    $(NULL)
+
+DISTCLEANFILES =                \
+    $(MAINTAINERCLEANFILES)     \
     ibusversion.h               \
     $(NULL)
 
-- 
2.33.1

From 104148bcdada1f8f22ef905c930f9944f3e99a63 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Thu, 2 Dec 2021 23:53:28 +0900
Subject: [PATCH] src: Disable emoji shortcut key with no-emoji hint

BUG=https://gitlab.gnome.org/GNOME/gtk/-/issues/4337
---
 src/ibusengine.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/ibusengine.c b/src/ibusengine.c
index 9aeafbf9..7e844838 100644
--- a/src/ibusengine.c
+++ b/src/ibusengine.c
@@ -2,8 +2,8 @@
 /* vim:set et sts=4: */
 /* ibus - The Input Bus
  * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
- * Copyright (C) 2018-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
- * Copyright (C) 2008-2019 Red Hat, Inc.
+ * Copyright (C) 2018-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (C) 2008-2021 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -954,6 +954,10 @@ ibus_engine_filter_key_event (IBusEngine *engine,
         return FALSE;
     for (n = names; n; n = n->next) {
         const gchar *name = (const gchar *)n->data;
+        if (!g_strcmp0 (name, "emoji") &&
+            (engine->priv->content_hints & IBUS_INPUT_HINT_NO_EMOJI)) {
+            continue;
+        }
         keys = g_hash_table_lookup (priv->extension_keybindings, name);
         for (; keys; keys++) {
             if (keys->keyval == 0 && keys->keycode == 0 && keys->state == 0)
-- 
2.33.1