[gtk/im-context-event-leak-3] imcontext: Eat key events during preedit




commit a926f217d77ac33017e5c6d90dc5beb746449650
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 15 17:46:19 2021 -0400

    imcontext: Eat key events during preedit
    
    Avoid passing through random key press or release
    events while we are showing preedit. That prevents
    'accidents' like typing Ctrl-. bringing up the
    Emoji chooser during preedit, or hitting Ctrl-a
    after the Compose key moving the 'dot' around in
    vim in terminals.

 gtk/gtkimcontextsimple.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 7ab3e4382b..89221ce80e 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -731,13 +731,21 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
            }
        }
 
+      if (priv->in_hex_sequence || priv->in_compose_sequence)
+        return TRUE; /* Don't leak random key events during preedit */
+
       return FALSE;
     }
 
   /* Ignore modifier key presses */
   for (i = 0; i < G_N_ELEMENTS (gtk_compose_ignore); i++)
     if (event->keyval == gtk_compose_ignore[i])
-      return FALSE;
+      {
+        if (priv->in_hex_sequence || priv->in_compose_sequence)
+          return TRUE; /* Don't leak random key events during preedit */
+
+        return FALSE;
+      }
 
   hex_mod_mask = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
                                                GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
@@ -776,16 +784,23 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
         gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
                                       GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
 
-      if (event->state & no_text_input_mask ||
-         (priv->in_hex_sequence && priv->modifiers_dropped &&
-          (event->keyval == GDK_KEY_Return ||
-           event->keyval == GDK_KEY_ISO_Enter ||
-           event->keyval == GDK_KEY_KP_Enter)))
+      if (priv->in_hex_sequence && priv->modifiers_dropped &&
+         (event->keyval == GDK_KEY_Return ||
+          event->keyval == GDK_KEY_ISO_Enter ||
+          event->keyval == GDK_KEY_KP_Enter))
        {
          return FALSE;
        }
+
+      if (event->state & no_text_input_mask)
+        {
+          if (priv->in_hex_sequence || priv->in_compose_sequence)
+            return TRUE; /* Don't leak random key events during preedit */
+
+          return FALSE;
+        }
     }
-  
+
   /* Handle backspace */
   if (priv->in_hex_sequence && have_hex_mods && is_backspace)
     {


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