[gtk/wip/compose-parser: 9/9] imcontext: Replace the builtin sequences




commit c97f660b6682140f0c25acc702284bf9506ee697
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 7 17:03:11 2021 -0400

    imcontext: Replace the builtin sequences
    
    When we find a Compose file, replace the builtin
    sequences with the table we found. This matches the
    semantics described in Compose(5), and makes it possible
    to drop unwanted sequences from the builtin table.
    
    It is slight change of behavior for users with existing
    Compose files. To match the previous behavior, you have
    to add
    
    include "%L"
    
    to your Compose file, to keep the builtin sequences in
    addition to your own.

 gtk/gtkimcontextsimple.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 4e160ab048..078ed6f612 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -40,15 +40,15 @@
  *
  * `GtkIMContextSimple` is an input method supporting table-based input methods.
  *
- * `GtkIMContextSimple` has a built-in table of compose sequences that is
- * derived from the X11 Compose files.
- *
- * `GtkIMContextSimple` reads additional compose sequences from the first of the
+ * `GtkIMContextSimple` reads compose sequences from the first of the
  * following files that is found: ~/.config/gtk-4.0/Compose, ~/.XCompose,
  * /usr/share/X11/locale/$locale/Compose (for locales that have a nontrivial
  * Compose file). The syntax of these files is described in the Compose(5)
  * manual page.
  *
+ * If none of these files is found, `GtkIMContextSimple` uses a built-in table
+ * of compose sequences that is derived from the X11 Compose files.
+ *
  * ## Unicode characters
  *
  * `GtkIMContextSimple` also supports numeric entry of Unicode characters
@@ -88,6 +88,7 @@ const GtkComposeTableCompact gtk_compose_table_compact = {
 
 G_LOCK_DEFINE_STATIC (global_tables);
 static GSList *global_tables;
+static gboolean omit_builtin_sequences;
 
 static const guint16 gtk_compose_ignore[] = {
   0, /* Yes, XKB will send us key press events with NoSymbol :( */
@@ -173,7 +174,8 @@ gtk_compose_table_find (gconstpointer data1,
 }
 
 static void
-add_compose_table_from_file (const char *compose_file)
+add_compose_table_from_file (const char *compose_file,
+                             gboolean    replace_builtin)
 {
   guint hash;
 
@@ -187,7 +189,11 @@ add_compose_table_from_file (const char *compose_file)
       table = gtk_compose_table_new_with_file (compose_file);
 
       if (table)
-        global_tables = g_slist_prepend (global_tables, table);
+        {
+          global_tables = g_slist_prepend (global_tables, table);
+          if (replace_builtin)
+            omit_builtin_sequences = TRUE;
+        }
     }
 
   G_UNLOCK (global_tables);
@@ -231,7 +237,7 @@ gtk_im_context_simple_init_compose_table (void)
   path = g_build_filename (g_get_user_config_dir (), "gtk-4.0", "Compose", NULL);
   if (g_file_test (path, G_FILE_TEST_EXISTS))
     {
-      add_compose_table_from_file (path);
+      add_compose_table_from_file (path, TRUE);
       g_free (path);
       return;
     }
@@ -244,7 +250,7 @@ gtk_im_context_simple_init_compose_table (void)
   path = g_build_filename (home, ".XCompose", NULL);
   if (g_file_test (path, G_FILE_TEST_EXISTS))
     {
-      add_compose_table_from_file (path);
+      add_compose_table_from_file (path, TRUE);
       g_free (path);
       return;
     }
@@ -288,7 +294,9 @@ gtk_im_context_simple_init_compose_table (void)
   g_strfreev (langs);
 
   if (path != NULL)
-    add_compose_table_from_file (path);
+    {
+      add_compose_table_from_file (path, TRUE);
+    }
 
   g_free (path);
 }
@@ -1066,7 +1074,10 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
       if (success)
         return TRUE;
 
-      if (gtk_compose_table_compact_check (&gtk_compose_table_compact,
+      G_LOCK (global_tables);
+
+      if (!omit_builtin_sequences &&
+          gtk_compose_table_compact_check (&gtk_compose_table_compact,
                                            priv->compose_buffer, n_compose,
                                            &compose_finish, &compose_match,
                                            &output_char))
@@ -1096,6 +1107,8 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
           return TRUE;
         }
 
+      G_UNLOCK (global_tables);
+
       if (gtk_check_algorithmically (priv->compose_buffer, n_compose, &output_char))
         {
           if (!priv->in_compose_sequence)
@@ -1255,8 +1268,6 @@ gtk_im_context_simple_add_table (GtkIMContextSimple *context_simple,
                                 int                 max_seq_len,
                                 int                 n_seqs)
 {
-  GtkComposeTable *table;
-
   g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (context_simple));
 
   add_compose_table_from_data (data, max_seq_len, n_seqs);
@@ -1275,5 +1286,5 @@ gtk_im_context_simple_add_compose_file (GtkIMContextSimple *context_simple,
 {
   g_return_if_fail (GTK_IS_IM_CONTEXT_SIMPLE (context_simple));
 
-  add_compose_table_from_file (compose_file);
+  add_compose_table_from_file (compose_file, FALSE);
 }


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