From 3b65a6a42ed2d4d2ecdcec94163ce0b748e707fc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 25 Oct 2015 14:09:03 -0400 Subject: [PATCH] Translate GDK_KEY_KP_Decimal according to locale It makes sense that you should be able to type numbers that are correctly formatted and parsable according to the current locale, using just the keypad. This patch makes it so by translating GDK_KEY_KP_Decimal to the decimal separator for the current locale, instead of hardcoding a '.'. https://bugzilla.gnome.org/show_bug.cgi?id=756751 --- gdk/gdkkeyuni.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gdk/gdkkeyuni.c b/gdk/gdkkeyuni.c index 4282597da..8da12d670 100644 --- a/gdk/gdkkeyuni.c +++ b/gdk/gdkkeyuni.c @@ -28,6 +28,8 @@ #include "gdk.h" #include "gdkalias.h" +#include + /* Thanks to Markus G. Kuhn for the ksysym<->Unicode * mapping functions, from the xterm sources. */ @@ -1654,6 +1656,23 @@ static const struct { { 0x0ef7, 0x318e }, /* Hangul_AraeAE ㆎ HANGUL LETTER ARAEAE */ }; +static gunichar +get_decimal_point (void) +{ + struct lconv *locale_data; + const gchar *decimal_point; + gunichar ret; + + locale_data = localeconv (); + decimal_point = locale_data->decimal_point; + + ret = g_utf8_get_char_validated (decimal_point, -1); + if (ret != (gunichar)-2 && ret != (gunichar)-1) + return ret; + + return (gunichar) '.'; +} + /** * gdk_unicode_to_keyval: * @wc: a ISO10646 encoded character @@ -1676,6 +1695,9 @@ gdk_unicode_to_keyval (guint32 wc) (wc >= 0x00a0 && wc <= 0x00ff)) return wc; + if (wc == 0xffae) + return (guint32) get_decimal_point (); + /* Binary search in table */ while (max >= min) { mid = (min + max) / 2;