From 07c6d0a5df5a94560e3e6d6d1f499c68ea28c8d4 Mon Sep 17 00:00:00 2001 From: Takao Fujiwara Date: Mon, 9 Aug 2021 13:27:50 +0900 Subject: [PATCH] Enable sync process in GTK4 --- ibus-HEAD.patch | 218 ++++++++++++++++++++++++++++++++++++++++++++++++ ibus.spec | 5 +- 2 files changed, 222 insertions(+), 1 deletion(-) diff --git a/ibus-HEAD.patch b/ibus-HEAD.patch index 362ebb1..0b56af7 100644 --- a/ibus-HEAD.patch +++ b/ibus-HEAD.patch @@ -6037,3 +6037,221 @@ index 0ef72c03..c1016703 100755 -- 2.28.0 +From a823161768c8f6916dbdebe73842a9fc04521369 Mon Sep 17 00:00:00 2001 +From: fujiwarat +Date: Mon, 9 Aug 2021 12:36:40 +0900 +Subject: [PATCH] client/gtk2/ibusimcontext: Enable sync process in GTK4 + +gtk_im_context_filter_key() does not forward control keys likes +BackSpace, Return and change the process mode to the synchronization. + +BUG=https://gitlab.gnome.org/GNOME/gtk/-/issues/3465 +--- + client/gtk2/ibusimcontext.c | 65 +++++++++++++++++++++++-------------- + 1 file changed, 41 insertions(+), 24 deletions(-) + +diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c +index e7ce5363..da9a402f 100644 +--- a/client/gtk2/ibusimcontext.c ++++ b/client/gtk2/ibusimcontext.c +@@ -110,13 +110,15 @@ static guint _signal_preedit_end_id = 0; + static guint _signal_delete_surrounding_id = 0; + static guint _signal_retrieve_surrounding_id = 0; + +-#if !GTK_CHECK_VERSION (3, 98, 4) ++#if GTK_CHECK_VERSION (3, 98, 4) ++static gboolean _use_sync_mode = TRUE; ++#else + static const gchar *_no_snooper_apps = NO_SNOOPER_APPS; + static gboolean _use_key_snooper = ENABLE_SNOOPER; + static guint _key_snooper_id = 0; +-#endif + + static gboolean _use_sync_mode = FALSE; ++#endif + + static const gchar *_discard_password_apps = ""; + static gboolean _use_discard_password = FALSE; +@@ -767,11 +769,13 @@ ibus_im_context_class_init (IBusIMContextClass *class) + g_signal_lookup ("retrieve-surrounding", G_TYPE_FROM_CLASS (class)); + g_assert (_signal_retrieve_surrounding_id != 0); + +-#if !GTK_CHECK_VERSION (3, 98, 4) ++#if GTK_CHECK_VERSION (3, 98, 4) ++ _use_sync_mode = _get_boolean_env ("IBUS_ENABLE_SYNC_MODE", TRUE); ++#else + _use_key_snooper = !_get_boolean_env ("IBUS_DISABLE_SNOOPER", + !(ENABLE_SNOOPER)); +-#endif + _use_sync_mode = _get_boolean_env ("IBUS_ENABLE_SYNC_MODE", FALSE); ++#endif + _use_discard_password = _get_boolean_env ("IBUS_DISCARD_PASSWORD", FALSE); + + #define CHECK_APP_IN_CSV_ENV_VARIABLES(retval, \ +@@ -1434,6 +1438,9 @@ static gboolean + _set_cursor_location_internal (IBusIMContext *ibusimcontext) + { + GdkRectangle area; ++#if GTK_CHECK_VERSION (3, 98, 4) ++ GtkWidget *root; ++#endif + + if(ibusimcontext->client_window == NULL || + ibusimcontext->ibuscontext == NULL) { +@@ -1442,8 +1449,27 @@ _set_cursor_location_internal (IBusIMContext *ibusimcontext) + + area = ibusimcontext->cursor_area; + +-#if !GTK_CHECK_VERSION (3, 98, 4) + #ifdef GDK_WINDOWING_WAYLAND ++#if GTK_CHECK_VERSION (3, 98, 4) ++ root = GTK_WIDGET (gtk_widget_get_root (ibusimcontext->client_window)); ++ /* FIXME: GTK_STYLE_CLASS_TITLEBAR is available in GTK3 but not GTK4. ++ * gtk_css_boxes_get_content_rect() is available in GTK4 but it's an ++ * internal API and calculate the window edge 32 in GTK3. ++ */ ++ area.y += 32; ++ area.width = 50; /* FIXME: Why 50 meets the cursor position? */ ++ area.height = gtk_widget_get_height (root); ++ area.height += 32; ++ if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) { ++ ibus_input_context_set_cursor_location_relative ( ++ ibusimcontext->ibuscontext, ++ area.x, ++ area.y, ++ area.width, ++ area.height); ++ return FALSE; ++ } ++#else + if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) { + gdouble px, py; + GdkWindow *parent; +@@ -1469,23 +1495,20 @@ _set_cursor_location_internal (IBusIMContext *ibusimcontext) + #endif + #endif + +- if (area.x == -1 && area.y == -1 && area.width == 0 && area.height == 0) { + #if GTK_CHECK_VERSION (3, 98, 4) +- area.x = 0; +- area.y += gtk_widget_get_height (ibusimcontext->client_window); + #elif GTK_CHECK_VERSION (2, 91, 0) +- area.x = 0; +- area.y += gdk_window_get_height (ibusimcontext->client_window); ++ 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; + gdk_drawable_get_size (ibusimcontext->client_window, &w, &h); + area.y += h; + area.x = 0; +-#endif + } ++#endif + + #if GTK_CHECK_VERSION (3, 98, 4) +-#ifdef GDK_WINDOWING_X11 ++#if defined(GDK_WINDOWING_X11) + GdkDisplay *display = gtk_widget_get_display (ibusimcontext->client_window); + if (GDK_IS_X11_DISPLAY (display)) { + Display *xdisplay = gdk_x11_display_get_xdisplay (display); +@@ -1505,21 +1528,10 @@ _set_cursor_location_internal (IBusIMContext *ibusimcontext) + XGetWindowAttributes (xdisplay, window, &xwa); + area.x = x - xwa.x + area.x; + area.y = y - xwa.y + area.y; +- area.width = xwa.width; ++ area.width = 50; /* FIXME: Why 50 meets the cursor position? */ + area.height = xwa.height; + } + #endif +-#elif GTK_CHECK_VERSION (3, 93, 0) +- { +- GtkNative *native = gtk_widget_get_native ( +- ibusimcontext->client_window); +- GdkSurface *surface = gtk_native_get_surface (native); +- int root_x = 0; +- int root_y = 0; +- gdk_surface_get_position (surface, &root_x, &root_y); +- area.x += root_x; +- area.y += root_y; +- } + #else + gdk_window_get_root_coords (ibusimcontext->client_window, + area.x, area.y, +@@ -1541,12 +1553,17 @@ ibus_im_context_set_cursor_location (GtkIMContext *context, GdkRectangle *area) + + IBusIMContext *ibusimcontext = IBUS_IM_CONTEXT (context); + ++#if !GTK_CHECK_VERSION (3, 93, 0) ++ /* The area is the relative coordinates and this has to get the absolute ++ * ones in _set_cursor_location_internal() since GTK 4.0. ++ */ + if (ibusimcontext->cursor_area.x == area->x && + ibusimcontext->cursor_area.y == area->y && + ibusimcontext->cursor_area.width == area->width && + ibusimcontext->cursor_area.height == area->height) { + return; + } ++#endif + ibusimcontext->cursor_area = *area; + _set_cursor_location_internal (ibusimcontext); + gtk_im_context_set_cursor_location (ibusimcontext->slave, area); +-- +2.28.0 + +From 943d37444d9cc0881cb5fff87bdd4b9efd5abdb4 Mon Sep 17 00:00:00 2001 +From: fujiwarat +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 + diff --git a/ibus.spec b/ibus.spec index 4ba4a52..6c5b2fc 100644 --- a/ibus.spec +++ b/ibus.spec @@ -38,7 +38,7 @@ Name: ibus Version: 1.5.24 -Release: 12%{?dist} +Release: 13%{?dist} Summary: Intelligent Input Bus for Linux OS License: LGPLv2+ URL: https://github.com/ibus/%name/wiki @@ -510,6 +510,9 @@ dconf update || : %{_datadir}/installed-tests/ibus %changelog +* Mon Aug 09 2021 Takao Fujiwara - 1.5.24-13 +- Enable sync process in GTK4 + * Mon Jul 26 2021 Takao Fujiwara - 1.5.24-12 - Search language name in engine list in ibus-setup - Set Multi_key to 0xB7 in compose preedit