[gtk/gtk-4-6] imwayland: Do not defer commit() after set_surrounding_text()



commit 812c8926ecf1722ab8a1570a26588263c80c6a4b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Apr 6 13:08:00 2022 +0200

    imwayland: Do not defer commit() after set_surrounding_text()
    
    For reasons that only apply to the old serial handling, asking for
    the surrounding after IM changes resulted in lazy handling of
    commit() afterwards.
    
    With the recent interpretation of serials, this problem became more
    apparent, since it is in fact very likely that the last interaction
    step after an IM change is notifying of the changed surrounding
    text after the IM change was applied.
    
    Make handling of surrounding text similar to caret position changes,
    always commit() after the state change, but skip through non-changes.
    
    This makes the compositor state fully up-to-date after an IM change.

 gtk/gtkimcontextwayland.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkimcontextwayland.c b/gtk/gtkimcontextwayland.c
index 7e8d0e721c..ea9ed00cfc 100644
--- a/gtk/gtkimcontextwayland.c
+++ b/gtk/gtkimcontextwayland.c
@@ -910,17 +910,20 @@ gtk_im_context_wayland_set_surrounding (GtkIMContext *context,
 
   context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
 
+  if (context_wayland->surrounding.text && text &&
+      (len < 0 || len == strlen (context_wayland->surrounding.text)) &&
+      strncmp (context_wayland->surrounding.text, text, len) == 0 &&
+      context_wayland->surrounding.cursor_idx == cursor_index &&
+      context_wayland->surrounding.anchor_idx == selection_bound)
+    return;
+
   g_free (context_wayland->surrounding.text);
   context_wayland->surrounding.text = g_strndup (text, len);
   context_wayland->surrounding.cursor_idx = cursor_index;
   context_wayland->surrounding.anchor_idx = selection_bound;
 
   notify_surrounding_text (context_wayland);
-  /* State changes coming from reset don't have any other opportunity to get
-   * committed. */
-  if (context_wayland->surrounding_change !=
-      ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD)
-    commit_state (context_wayland);
+  commit_state (context_wayland);
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]