[gtk/input-tweaks: 4/7] imcontext: Tweak Compose sequence handling




commit 76d67b586c5dc2b19ee4072284fa4fb7f74b01f3
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 29 08:24:14 2021 -0400

    imcontext: Tweak Compose sequence handling
    
    When we don't have any matches for a Compose sequence
    anymore, beep, and keep the preedit as it was for the
    last match.
    
    Fixes: #4127

 gtk/gtkimcontextsimple.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index f193eb48e3..71f9094aee 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -622,7 +622,7 @@ no_sequence_matches (GtkIMContextSimple *context_simple,
   guint keyval;
 
   context = GTK_IM_CONTEXT (context_simple);
-  
+
   priv->in_compose_sequence = FALSE;
 
   /* No compose sequences found, check first if we have a partial
@@ -1071,6 +1071,7 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
   else /* Then, check for compose sequences */
     {
       gboolean success = FALSE;
+      int prefix = 0;
       GString *output;
 
       output = g_string_new ("");
@@ -1109,6 +1110,16 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
               success = TRUE;
               break;
             }
+          else
+            {
+              int table_prefix;
+
+              gtk_compose_table_get_prefix ((GtkComposeTable *)tmp_list->data,
+                                            priv->compose_buffer, n_compose,
+                                            &table_prefix);
+
+              prefix = MAX (prefix, table_prefix);
+            }
 
           tmp_list = tmp_list->next;
         }
@@ -1135,6 +1146,21 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
 
           return TRUE;
         }
+
+      /* If we get here, no Compose sequence matched.
+       * Only beep if we were in a sequence before.
+       */
+      if (prefix > 0)
+        {
+          for (i = prefix; i < n_compose; i++)
+            priv->compose_buffer[i] = 0;
+
+          beep_surface (gdk_event_get_surface (event));
+
+          g_signal_emit_by_name (context_simple, "preedit-changed");
+
+          return TRUE;
+        }
     }
 
   /* The current compose_buffer doesn't match anything */


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