Refactor surrounding text warning

This commit is contained in:
Takao Fujiwara 2023-01-12 10:12:12 +09:00
parent ab005a1bb0
commit f064aefc08
2 changed files with 175 additions and 1 deletions

View File

@ -7759,3 +7759,174 @@ index 0c0bda10..340168c8 100644
--
2.38.1
From b6664195a2bc9c7666f18b5586c538fb671bf1a9 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Tue, 11 Oct 2022 20:12:35 +0900
Subject: [PATCH] client/gtk2: Refactor surrounding text warning
It would be better to check the function return value at the
first calling than the static variable.
Fixes: https://github.com/ibus/ibus/commit/39b6907
Fixes: https://github.com/ibus/ibus/commit/7bbcce6
---
client/gtk2/ibusimcontext.c | 72 +++++++++++++++++++------------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
index 6e338157..e4c4ff36 100644
--- a/client/gtk2/ibusimcontext.c
+++ b/client/gtk2/ibusimcontext.c
@@ -70,7 +70,6 @@ struct _IBusIMContext {
#endif
IBusInputContext *ibuscontext;
- IBusInputContext *ibuscontext_needs_surrounding;
/* preedit status */
gchar *preedit_string;
@@ -214,7 +213,7 @@ static gboolean _slave_delete_surrounding_cb
gint offset_from_cursor,
guint nchars,
IBusIMContext *context);
-static void _request_surrounding_text (IBusIMContext *context);
+static gboolean _request_surrounding_text (IBusIMContext *context);
static void _create_fake_input_context (void);
static gboolean _set_content_type (IBusIMContext *context);
@@ -565,34 +564,19 @@ _process_key_event (IBusInputContext *context,
* context->caps has IBUS_CAP_SURROUNDING_TEXT and the current IBus
* engine needs surrounding-text.
*/
-static void
+static gboolean
_request_surrounding_text (IBusIMContext *context)
{
- static gboolean warned = FALSE;
+ gboolean return_value = TRUE;
if (context &&
(context->caps & IBUS_CAP_SURROUNDING_TEXT) != 0 &&
context->ibuscontext != NULL &&
ibus_input_context_needs_surrounding_text (context->ibuscontext)) {
- gboolean return_value;
IDEBUG ("requesting surrounding text");
g_signal_emit (context, _signal_retrieve_surrounding_id, 0,
&return_value);
- if (!return_value) {
- /* Engines can disable the surrounding text feature with
- * the updated capabilities.
- */
- if (context->caps & IBUS_CAP_SURROUNDING_TEXT) {
- context->caps &= ~IBUS_CAP_SURROUNDING_TEXT;
- ibus_input_context_set_capabilities (context->ibuscontext,
- context->caps);
- }
- if (!warned) {
- g_warning ("%s has no capability of surrounding-text feature",
- g_get_prgname ());
- warned = TRUE;
- }
- }
}
+ return return_value;
}
static gboolean
@@ -986,7 +970,6 @@ ibus_im_context_init (GObject *obj)
ibusimcontext->cursor_area.height = 0;
ibusimcontext->ibuscontext = NULL;
- ibusimcontext->ibuscontext_needs_surrounding = NULL;
ibusimcontext->has_focus = FALSE;
ibusimcontext->time = GDK_CURRENT_TIME;
#ifdef ENABLE_SURROUNDING
@@ -2185,16 +2168,33 @@ _ibus_context_hide_preedit_text_cb (IBusInputContext *ibuscontext,
g_signal_emit (ibusimcontext, _signal_preedit_end_id, 0);
}
+static void
+_ibus_warn_no_support_surrounding_text (IBusIMContext *context)
+{
+ /* Engines can disable the surrounding text feature with
+ * the updated capabilities.
+ */
+ if (context->caps & IBUS_CAP_SURROUNDING_TEXT) {
+ context->caps &= ~IBUS_CAP_SURROUNDING_TEXT;
+ ibus_input_context_set_capabilities (context->ibuscontext,
+ context->caps);
+ }
+ g_warning ("%s has no capability of surrounding-text feature",
+ g_get_prgname ());
+}
+
static void
_ibus_context_require_surrounding_text_cb (IBusInputContext *ibuscontext,
IBusIMContext *ibusimcontext)
{
IDEBUG ("%s", __FUNCTION__);
g_assert (ibusimcontext->ibuscontext == ibuscontext);
- if (ibusimcontext->ibuscontext_needs_surrounding == ibuscontext) {
- _request_surrounding_text (ibusimcontext);
- ibusimcontext->ibuscontext_needs_surrounding = NULL;
- }
+ if (!_request_surrounding_text (ibusimcontext))
+ _ibus_warn_no_support_surrounding_text (ibusimcontext);
+ g_signal_handlers_disconnect_by_func (
+ ibusimcontext->ibuscontext,
+ G_CALLBACK (_ibus_context_require_surrounding_text_cb),
+ ibusimcontext);
}
static void
@@ -2236,6 +2236,7 @@ _create_input_context_done (IBusBus *bus,
g_error_free (error);
}
else {
+ gboolean requested_surrounding_text = FALSE;
ibus_input_context_set_client_commit_preedit (context, TRUE);
ibusimcontext->ibuscontext = context;
@@ -2263,16 +2264,12 @@ _create_input_context_done (IBusBus *bus,
"hide-preedit-text",
G_CALLBACK (_ibus_context_hide_preedit_text_cb),
ibusimcontext);
- g_signal_connect (
- ibusimcontext->ibuscontext,
- "require-surrounding-text",
- G_CALLBACK (_ibus_context_require_surrounding_text_cb),
- ibusimcontext);
g_signal_connect (ibusimcontext->ibuscontext, "destroy",
G_CALLBACK (_ibus_context_destroy_cb),
ibusimcontext);
- ibus_input_context_set_capabilities (ibusimcontext->ibuscontext, ibusimcontext->caps);
+ ibus_input_context_set_capabilities (ibusimcontext->ibuscontext,
+ ibusimcontext->caps);
if (ibusimcontext->has_focus) {
/* The time order is _create_input_context() ->
@@ -2286,11 +2283,18 @@ _create_input_context_done (IBusBus *bus,
_set_cursor_location_internal (ibusimcontext);
if (ibus_input_context_needs_surrounding_text (
ibusimcontext->ibuscontext)) {
- _request_surrounding_text (ibusimcontext);
- } else {
- ibusimcontext->ibuscontext_needs_surrounding = ibusimcontext->ibuscontext;
+ if (!_request_surrounding_text (ibusimcontext))
+ _ibus_warn_no_support_surrounding_text (ibusimcontext);
+ requested_surrounding_text = TRUE;
}
}
+ if (!requested_surrounding_text) {
+ g_signal_connect (
+ ibusimcontext->ibuscontext,
+ "require-surrounding-text",
+ G_CALLBACK (_ibus_context_require_surrounding_text_cb),
+ ibusimcontext);
+ }
if (!g_queue_is_empty (ibusimcontext->events_queue)) {
#if GTK_CHECK_VERSION (3, 98, 4)
--
2.37.3

View File

@ -50,7 +50,7 @@
Name: ibus
Version: 1.5.27
Release: 10%{?dist}
Release: 11%{?dist}
Summary: Intelligent Input Bus for Linux OS
License: LGPL-2.0-or-later
URL: https://github.com/ibus/%name/wiki
@ -554,6 +554,9 @@ dconf update || :
%{_datadir}/installed-tests/ibus
%changelog
* Thu Jan 12 2023 Takao Fujiwara <tfujiwar@redhat.com> - 1.5.27-11
- Refactor surrounding text warning
* Fri Jan 06 2023 Tomas Popela <tpopela@redhat.com> - 1.5.27-10
- Don't build GTK 2 content for RHEL 10 as GTK 2 won't be there