[gtk/input-tweaks: 2/2] imcontext: Code cleanup




commit c4dbb8f01ebab1b94adbbcd771642ce4013c22ec
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 29 19:59:08 2021 -0400

    imcontext: Code cleanup

 gtk/gtkimcontextsimple.c | 50 +++++++++++++++---------------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 1803b8e70d..cdba288c0b 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -544,18 +544,22 @@ is_dead_key (guint keysym)
   return GDK_KEY_dead_grave <= keysym && keysym <= GDK_KEY_dead_greek;
 }
 
-static gunichar
-dead_key_to_unicode (guint     keysym,
-                     gboolean *need_space)
+static void
+append_dead_key (GString *string,
+                 guint    keysym)
 {
   /* Sadly, not all the dead keysyms have spacing mark equivalents
-   * in Unicode. For those that don't, we use space + the non-spacing
-   * mark as an approximation
+   * in Unicode. For those that don't, we use NBSP + the non-spacing
+   * mark as an approximation.
    */
   switch (keysym)
     {
-#define CASE(keysym, unicode, sp) \
-    case GDK_KEY_dead_##keysym: *need_space = sp; return unicode;
+#define CASE(keysym, unicode, sp)                \
+    case GDK_KEY_dead_##keysym:                  \
+      if (sp)                                    \
+        g_string_append_unichar (string, 0xA0);  \
+      g_string_append_unichar (string, unicode); \
+      break;
 
     CASE (grave, 0x60, 0);
     CASE (acute, 0xb4, 0);
@@ -606,8 +610,7 @@ dead_key_to_unicode (guint     keysym,
     CASE (capital_schwa, 0x1dea, 1);
 #undef CASE
     default:
-      *need_space = FALSE;
-      return gdk_keyval_to_unicode (keysym);
+      g_string_append_unichar (string, gdk_keyval_to_unicode (keysym));
     }
 }
 
@@ -675,7 +678,6 @@ no_sequence_matches (GtkIMContextSimple *context_simple,
 
       if (n_compose > 1 && i >= n_compose - 1)
         {
-          gboolean need_space;
           GString *s;
 
           s = g_string_new ("");
@@ -684,15 +686,7 @@ no_sequence_matches (GtkIMContextSimple *context_simple,
             {
               /* dead keys are never *really* dead */
               for (int j = 0; j < i; j++)
-                {
-                  ch = dead_key_to_unicode (priv->compose_buffer[j], &need_space);
-                  if (ch)
-                    {
-                      if (need_space)
-                        g_string_append_c (s, ' ');
-                      g_string_append_unichar (s, ch);
-                    }
-                }
+                append_dead_key (s, priv->compose_buffer[j]);
 
               ch = gdk_keyval_to_unicode (priv->compose_buffer[i]);
               if (ch != 0 && ch != ' ' && !g_unichar_iscntrl (ch))
@@ -702,14 +696,7 @@ no_sequence_matches (GtkIMContextSimple *context_simple,
             }
           else
             {
-              ch = dead_key_to_unicode (priv->compose_buffer[0], &need_space);
-              if (ch)
-                {
-                  if (need_space)
-                    g_string_append_c (s, ' ');
-                  g_string_append_unichar (s, ch);
-                }
-
+              append_dead_key (s, priv->compose_buffer[0]);
               gtk_im_context_simple_commit_string (context_simple, s->str);
 
               for (i = 1; i < n_compose; i++)
@@ -1244,17 +1231,10 @@ gtk_im_context_simple_get_preedit_string (GtkIMContext   *context,
               else
                 {
                   gunichar ch;
-                  gboolean need_space;
 
                   if (is_dead_key (priv->compose_buffer[i]))
                     {
-                      ch = dead_key_to_unicode (priv->compose_buffer[i], &need_space);
-                      if (ch)
-                        {
-                          if (need_space)
-                            g_string_append_c (s, ' ');
-                          g_string_append_unichar (s, ch);
-                        }
+                      append_dead_key (s, priv->compose_buffer[i]);
                     }
                   else
                     {


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