From c58d9446f40b36136f25baf66dfb6116fb16888c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 21 May 2020 18:05:43 -0400 Subject: [PATCH] Differentiate keypad keysyms in accelerators When displaying accelerators, differentiate keypad symbols with a 'KP' prefix. Fixing a 17 year old bug. Update expected output in accelerator tests. Fixes: #227 --- gtk/gtkaccelgroup.c | 85 +++++++++++++++++++++++-------------------- testsuite/gtk/accel.c | 4 +- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/gtk/gtkaccelgroup.c b/gtk/gtkaccelgroup.c index b749581629..cb7b2660b7 100644 --- a/gtk/gtkaccelgroup.c +++ b/gtk/gtkaccelgroup.c @@ -220,14 +220,14 @@ static inline gboolean is_primary (const gchar *string) { return ((string[0] == '<') && - (string[1] == 'p' || string[1] == 'P') && - (string[2] == 'r' || string[2] == 'R') && - (string[3] == 'i' || string[3] == 'I') && - (string[4] == 'm' || string[4] == 'M') && - (string[5] == 'a' || string[5] == 'A') && - (string[6] == 'r' || string[6] == 'R') && - (string[7] == 'y' || string[7] == 'Y') && - (string[8] == '>')); + (string[1] == 'p' || string[1] == 'P') && + (string[2] == 'r' || string[2] == 'R') && + (string[3] == 'i' || string[3] == 'I') && + (string[4] == 'm' || string[4] == 'M') && + (string[5] == 'a' || string[5] == 'A') && + (string[6] == 'r' || string[6] == 'R') && + (string[7] == 'y' || string[7] == 'Y') && + (string[8] == '>')); } static inline gboolean @@ -411,15 +411,15 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator, goto out; } } - else - { - keyval = gdk_keyval_from_name (accelerator); - if (keyval == GDK_KEY_VoidSymbol) - { - error = TRUE; - goto out; - } - } + else + { + keyval = gdk_keyval_from_name (accelerator); + if (keyval == GDK_KEY_VoidSymbol) + { + error = TRUE; + goto out; + } + } if (keyval && accelerator_codes != NULL) { @@ -937,18 +937,25 @@ gtk_accelerator_print_label (GString *gstring, if (seen_mod) append_separator (gstring); + if (accelerator_key >= GDK_KEY_KP_Space && + accelerator_key <= GDK_KEY_KP_Equal) + { + g_string_append (gstring, C_("keyboard label", "KP")); + g_string_append (gstring, " "); + } + switch (ch) - { - case ' ': - g_string_append (gstring, C_("keyboard label", "Space")); - break; - case '\\': - g_string_append (gstring, C_("keyboard label", "Backslash")); - break; - default: - g_string_append_unichar (gstring, g_unichar_toupper (ch)); - break; - } + { + case ' ': + g_string_append (gstring, C_("keyboard label", "Space")); + break; + case '\\': + g_string_append (gstring, C_("keyboard label", "Backslash")); + break; + default: + g_string_append_unichar (gstring, g_unichar_toupper (ch)); + break; + } } else if (!append_keyval_symbol (accelerator_key, gstring)) { @@ -956,22 +963,22 @@ gtk_accelerator_print_label (GString *gstring, tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key)); if (tmp != NULL) - { + { if (seen_mod) append_separator (gstring); - if (tmp[0] != 0 && tmp[1] == 0) - g_string_append_c (gstring, g_ascii_toupper (tmp[0])); - else - { - const char *str; + if (tmp[0] != 0 && tmp[1] == 0) + g_string_append_c (gstring, g_ascii_toupper (tmp[0])); + else + { + const char *str; str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp); - if (str == tmp) + if (str == tmp) append_without_underscores (gstring, tmp); - else - g_string_append (gstring, str); - } - } + else + g_string_append (gstring, str); + } + } } } diff --git a/testsuite/gtk/accel.c b/testsuite/gtk/accel.c index 4c06b28ca0..559635160e 100644 --- a/testsuite/gtk/accel.c +++ b/testsuite/gtk/accel.c @@ -87,13 +87,13 @@ accel2 (void) static void accel3 (void) { - test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "7", TRUE); + test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "KP 7", TRUE); } static void accel4 (void) { - test_one_accel ("KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+7", TRUE); + test_one_accel ("KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+KP 7", TRUE); } static void