[gtk/input-tweaks: 1/2] composetable: Change an API
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/input-tweaks: 1/2] composetable: Change an API
- Date: Thu, 29 Jul 2021 21:29:31 +0000 (UTC)
commit 539391ce6c5d2271b591c2849c629828af8be154
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jul 29 15:47:04 2021 -0400
composetable: Change an API
Make gtk_check_algorithmically take a GString
for the result. This is in preparation for allowing
multi-character results here, in the future.
Update all callers.
gtk/gtkcomposetable.c | 20 +++++++++----------
gtk/gtkcomposetable.h | 2 +-
gtk/gtkimcontextsimple.c | 18 ++++++++++-------
testsuite/gtk/composetable.c | 46 ++++++++++++++++++++++++--------------------
4 files changed, 47 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkcomposetable.c b/gtk/gtkcomposetable.c
index 0d9488c214..ef8d01266a 100644
--- a/gtk/gtkcomposetable.c
+++ b/gtk/gtkcomposetable.c
@@ -486,6 +486,9 @@ parser_remove_duplicates (GtkComposeParser *parser)
GHashTableIter iter;
gunichar *sequence;
char *value;
+ GString *output;
+
+ output = g_string_new ("");
g_hash_table_iter_init (&iter, parser->sequences);
while (g_hash_table_iter_next (&iter, (gpointer *)&sequence, (gpointer *)&value))
@@ -493,8 +496,6 @@ parser_remove_duplicates (GtkComposeParser *parser)
static guint16 keysyms[MAX_COMPOSE_LEN + 1];
int i;
int n_compose = 0;
- gunichar output_char;
- char buf[8] = { 0, };
gboolean remove_sequence = FALSE;
if (value[0] == '\0')
@@ -529,10 +530,9 @@ parser_remove_duplicates (GtkComposeParser *parser)
n_compose++;
}
- if (gtk_check_algorithmically (keysyms, n_compose, &output_char))
+ if (gtk_check_algorithmically (keysyms, n_compose, output))
{
- g_unichar_to_utf8 (output_char, buf);
- if (strcmp (value, buf) == 0)
+ if (strcmp (value, output->str) == 0)
remove_sequence = TRUE;
}
@@ -540,6 +540,8 @@ next:
if (remove_sequence)
g_hash_table_iter_remove (&iter);
}
+
+ g_string_free (output, TRUE);
}
static void
@@ -1534,7 +1536,7 @@ check_normalize_nfc (gunichar *combination_buffer,
gboolean
gtk_check_algorithmically (const guint16 *compose_buffer,
int n_compose,
- gunichar *output_char)
+ GString *output)
{
int i;
@@ -1543,8 +1545,7 @@ gtk_check_algorithmically (const guint16 *compose_buffer,
combination_buffer = alloca (sizeof (gunichar) * (n_compose + 1));
- if (output_char)
- *output_char = 0;
+ g_string_set_size (output, 0);
for (i = 0; i < n_compose && IS_DEAD_KEY (compose_buffer[i]); i++)
;
@@ -1631,8 +1632,7 @@ gtk_check_algorithmically (const guint16 *compose_buffer,
combination_utf8 = g_ucs4_to_utf8 (combination_buffer, -1, NULL, NULL, NULL);
nfc = g_utf8_normalize (combination_utf8, -1, G_NORMALIZE_NFC);
- if (output_char)
- *output_char = g_utf8_get_char (nfc);
+ g_string_assign (output, nfc);
g_free (combination_utf8);
g_free (nfc);
diff --git a/gtk/gtkcomposetable.h b/gtk/gtkcomposetable.h
index e9adc50150..584849f747 100644
--- a/gtk/gtkcomposetable.h
+++ b/gtk/gtkcomposetable.h
@@ -87,7 +87,7 @@ void gtk_compose_table_get_prefix (const GtkComposeTable *table,
gboolean gtk_check_algorithmically (const guint16 *compose_buffer,
int n_compose,
- gunichar *output);
+ GString *output);
guint32 gtk_compose_table_data_hash (const guint16 *data,
int max_seq_len,
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 8289aad7bc..1803b8e70d 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -821,7 +821,6 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
int i;
gboolean compose_finish;
gboolean compose_match;
- gunichar output_char;
guint keyval, state;
while (priv->compose_buffer[n_compose] != 0 && n_compose < priv->compose_buffer_len)
@@ -1132,12 +1131,13 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
G_UNLOCK (global_tables);
- g_string_free (output, TRUE);
-
if (success)
- return TRUE;
+ {
+ g_string_free (output, TRUE);
+ return TRUE;
+ }
- if (gtk_check_algorithmically (priv->compose_buffer, n_compose, &output_char))
+ if (gtk_check_algorithmically (priv->compose_buffer, n_compose, output))
{
if (!priv->in_compose_sequence)
{
@@ -1145,14 +1145,18 @@ gtk_im_context_simple_filter_keypress (GtkIMContext *context,
g_signal_emit_by_name (context_simple, "preedit-start");
}
- if (output_char)
- gtk_im_context_simple_commit_char (context_simple, output_char);
+ if (output->len > 0)
+ gtk_im_context_simple_commit_string (context_simple, output->str);
else
g_signal_emit_by_name (context_simple, "preedit-changed");
+ g_string_free (output, TRUE);
+
return TRUE;
}
+ g_string_free (output, TRUE);
+
/* If we get here, no Compose sequence matched.
* Only beep if we were in a sequence before.
*/
diff --git a/testsuite/gtk/composetable.c b/testsuite/gtk/composetable.c
index 1a77e5bc93..5adb9caca4 100644
--- a/testsuite/gtk/composetable.c
+++ b/testsuite/gtk/composetable.c
@@ -310,81 +310,85 @@ match_algorithmic (void)
{
guint16 buffer[8] = { 0, };
gboolean ret;
- gunichar ch;
+ GString *output;
+
+ output = g_string_new ("");
buffer[0] = GDK_KEY_a;
buffer[1] = GDK_KEY_b;
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_false (ret);
- g_assert_true (ch == 0);
+ g_assert_cmpstr (output->str, ==, "");
buffer[0] = GDK_KEY_dead_abovering;
buffer[1] = GDK_KEY_A;
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_true (ret);
- g_assert_true (ch == 0xc5);
+ g_assert_cmpstr (output->str, ==, "Å");
buffer[0] = GDK_KEY_A;
buffer[1] = GDK_KEY_dead_abovering;
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_false (ret);
- g_assert_true (ch == 0);
+ g_assert_cmpstr (output->str, ==, "");
buffer[0] = GDK_KEY_dead_dasia;
buffer[1] = GDK_KEY_dead_perispomeni;
buffer[2] = GDK_KEY_Greek_alpha;
- ret = gtk_check_algorithmically (buffer, 3, &ch);
+ ret = gtk_check_algorithmically (buffer, 3, output);
g_assert_true (ret);
- g_assert_true (ch == 0x1f07);
+ g_assert_cmpstr (output->str, ==, "ἇ");
buffer[0] = GDK_KEY_dead_perispomeni;
buffer[1] = GDK_KEY_dead_dasia;
buffer[2] = GDK_KEY_Greek_alpha;
- ret = gtk_check_algorithmically (buffer, 3, &ch);
+ ret = gtk_check_algorithmically (buffer, 3, output);
g_assert_true (ret);
- g_assert_true (ch == 0x1f07);
+ g_assert_cmpstr (output->str, ==, "ἇ");
buffer[0] = GDK_KEY_dead_acute;
buffer[1] = GDK_KEY_dead_cedilla;
buffer[2] = GDK_KEY_c;
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_true (ret);
- g_assert_cmphex (ch, ==, 0);
+ g_assert_cmpstr (output->str, ==, "");
- ret = gtk_check_algorithmically (buffer, 3, &ch);
+ ret = gtk_check_algorithmically (buffer, 3, output);
g_assert_true (ret);
- g_assert_cmphex (ch, ==, 0x1e09);
+ g_assert_cmpstr (output->str, ==, "ḉ");
buffer[0] = GDK_KEY_dead_cedilla;
buffer[1] = GDK_KEY_dead_acute;
buffer[2] = GDK_KEY_c;
- ret = gtk_check_algorithmically (buffer, 3, &ch);
+ ret = gtk_check_algorithmically (buffer, 3, output);
g_assert_true (ret);
- g_assert_cmphex (ch, ==, 0x1e09);
+ g_assert_cmpstr (output->str, ==, "ḉ");
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_true (ret);
buffer[0] = GDK_KEY_dead_acute;
buffer[1] = GDK_KEY_dead_cedilla;
buffer[2] = GDK_KEY_dead_grave;
- ret = gtk_check_algorithmically (buffer, 3, &ch);
+ ret = gtk_check_algorithmically (buffer, 3, output);
g_assert_false (ret);
buffer[0] = GDK_KEY_dead_diaeresis;
buffer[1] = GDK_KEY_a;
- ret = gtk_check_algorithmically (buffer, 2, &ch);
+ ret = gtk_check_algorithmically (buffer, 2, output);
g_assert_true (ret);
- g_assert_cmphex (ch, ==, 0xe4);
+ g_assert_cmpstr (output->str, ==, "ä");
+
+ g_string_free (output, TRUE);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]