diff --git a/clutter/Makefile.am b/clutter/Makefile.am index 8c89acdc4..b8b432964 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -189,6 +189,7 @@ source_c = \ $(srcdir)/clutter-group.c \ $(srcdir)/clutter-input-device.c \ $(srcdir)/clutter-interval.c \ + $(srcdir)/clutter-keysyms-table.c \ $(srcdir)/clutter-layout-manager.c \ $(srcdir)/clutter-layout-meta.c \ $(srcdir)/clutter-list-model.c \ @@ -236,7 +237,6 @@ source_h_priv = \ $(srcdir)/clutter-event-translator.h \ $(srcdir)/clutter-event-private.h \ $(srcdir)/clutter-id-pool.h \ - $(srcdir)/clutter-keysyms-table.h \ $(srcdir)/clutter-master-clock.h \ $(srcdir)/clutter-model-private.h \ $(srcdir)/clutter-offscreen-effect-private.h \ diff --git a/clutter/clutter-event.c b/clutter/clutter-event.c index e1b297be9..9f3c1d1d9 100644 --- a/clutter/clutter-event.c +++ b/clutter/clutter-event.c @@ -31,7 +31,6 @@ #include "clutter-debug.h" #include "clutter-event-private.h" #include "clutter-keysyms.h" -#include "clutter-keysyms-table.h" #include "clutter-private.h" /** @@ -744,53 +743,6 @@ clutter_event_set_key_unicode (ClutterEvent *event, event->key.unicode_value = key_unicode; } -/** - * clutter_keysym_to_unicode: - * @keyval: a key symbol - * - * Convert from a Clutter key symbol to the corresponding ISO10646 (Unicode) - * character. - * - * Return value: a Unicode character, or 0 if there is no corresponding - * character. - */ -guint32 -clutter_keysym_to_unicode (guint keyval) -{ - int min = 0; - int max = G_N_ELEMENTS (clutter_keysym_to_unicode_tab) - 1; - int mid; - - /* First check for Latin-1 characters (1:1 mapping) */ - if ((keyval >= 0x0020 && keyval <= 0x007e) || - (keyval >= 0x00a0 && keyval <= 0x00ff)) - return keyval; - - /* Also check for directly encoded 24-bit UCS characters: - */ - if ((keyval & 0xff000000) == 0x01000000) - return keyval & 0x00ffffff; - - /* binary search in table */ - while (max >= min) - { - mid = (min + max) / 2; - - if (clutter_keysym_to_unicode_tab[mid].keysym < keyval) - min = mid + 1; - else if (clutter_keysym_to_unicode_tab[mid].keysym > keyval) - max = mid - 1; - else - { - /* found it */ - return clutter_keysym_to_unicode_tab[mid].ucs; - } - } - - /* No matching Unicode value found */ - return 0; -} - /** * clutter_event_get_device_id: * @event: a clutter event diff --git a/clutter/clutter-keysyms-table.h b/clutter/clutter-keysyms-table.c similarity index 97% rename from clutter/clutter-keysyms-table.h rename to clutter/clutter-keysyms-table.c index 113f55453..9dcb2fb42 100644 --- a/clutter/clutter-keysyms-table.h +++ b/clutter/clutter-keysyms-table.c @@ -1,12 +1,11 @@ -#ifndef __CLUTTER_KEYSYMS_TABLE_H__ -#define __CLUTTER_KEYSYMS_TABLE_H__ +#include -/* Code below from GDK, which contains following comment; +/* Code below from GDK, which contains following comment: * * Thanks to Markus G. Kuhn for the ksysym<->Unicode * mapping functions, from the xterm sources. */ -struct { +static const struct { unsigned short keysym; unsigned short ucs; } clutter_keysym_to_unicode_tab[] = { @@ -801,7 +800,7 @@ struct { /* Following items added to GTK, not in the xterm table */ /* Numeric keypad */ - + { 0xFF80 /* Space */, ' ' }, { 0xFFAA /* Multiply */, '*' }, { 0xFFAB /* Add */, '+' }, @@ -819,9 +818,56 @@ struct { { 0xFFB7 /* 7 */, '7' }, { 0xFFB8 /* 8 */, '8' }, { 0xFFB9 /* 9 */, '9' }, - { 0xFFBD /* Equal */, '=' }, + { 0xFFBD /* Equal */, '=' }, /* End numeric keypad */ }; -#endif /* __CLUTTER_KEYSYMS_TABLE_H__ */ +static const int clutter_keysym_to_unicode_tab_size = + G_N_ELEMENTS (clutter_keysym_to_unicode_tab); + +/** + * clutter_keysym_to_unicode: + * @keyval: a key symbol + * + * Converts @keyval from a Clutter key symbol to the corresponding + * ISO10646 (Unicode) character. + * + * Return value: a Unicode character, or 0 if there is no corresponding + * character. + */ +guint32 +clutter_keysym_to_unicode (guint keyval) +{ + int min = 0; + int max = clutter_keysym_to_unicode_tab_size - 1; + int mid; + + /* First check for Latin-1 characters (1:1 mapping) */ + if ((keyval >= 0x0020 && keyval <= 0x007e) || + (keyval >= 0x00a0 && keyval <= 0x00ff)) + return keyval; + + /* Also check for directly encoded 24-bit UCS characters: */ + if ((keyval & 0xff000000) == 0x01000000) + return keyval & 0x00ffffff; + + /* binary search in table */ + while (max >= min) + { + mid = (min + max) / 2; + + if (clutter_keysym_to_unicode_tab[mid].keysym < keyval) + min = mid + 1; + else if (clutter_keysym_to_unicode_tab[mid].keysym > keyval) + max = mid - 1; + else + { + /* found it */ + return clutter_keysym_to_unicode_tab[mid].ucs; + } + } + + /* No matching Unicode value found */ + return 0; +}