Add category to each entry in keysym-labels tables.

This commit is contained in:
Daiki Ueno
2010-06-08 09:31:18 +09:00
parent bb7462e786
commit 5f6604cf92
6 changed files with 2216 additions and 2153 deletions

View File

@ -25,6 +25,7 @@
struct eek_keysym_label {
guint keysym;
const gchar *label;
EekKeysymCategory category;
};
#include "eek-special-keysym-labels.h"
@ -53,6 +54,81 @@ keysym_label_compare (const void *key0, const void *key1)
return (gint)entry0->keysym - (gint)entry1->keysym;
}
static gboolean
find_keysym (guint keysym,
const gchar **label,
EekKeysymCategory *category)
{
EekKeysymCategory bsearch_key, *bsearch_val;
/* First, search special keysyms. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
special_keysym_labels,
G_N_ELEMENTS(special_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val) {
if (label)
*label = g_strdup (bsearch_val->label);
if (category)
*category = bsearch_val->category;
return TRUE;
}
/* Check for Latin-1 characters (1:1 mapping) */
if ((keysym >= 0x0020 && keysym <= 0x007e) ||
(keysym >= 0x00a0 && keysym <= 0x00ff)) {
if (label)
*label = unichar_to_utf8 (keysym);
if (category)
*category = EEK_KEYSYM_CATEGORY_LETTER;
return TRUE;
}
/* Also check for directly encoded 24-bit UCS characters:
*/
if ((keysym & 0xff000000) == 0x01000000) {
if (label)
*label = unichar_to_utf8 (keysym & 0x00ffffff);
if (category)
*category = EEK_KEYSYM_CATEGORY_LETTER;
return TRUE;
}
/* Search known unicode keysyms. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
unicode_keysym_labels,
G_N_ELEMENTS(unicode_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val) {
if (label)
*label = g_strdup (bsearch_val->label);
if (category)
*category = bsearch_val->category;
return TRUE;
}
/* Finally, search keynames. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
keyname_keysym_labels,
G_N_ELEMENTS(keyname_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val) {
if (label)
*label = g_strdup (bsearch_val->label);
if (category)
*category = bsearch_val->category;
return TRUE;
}
return FALSE;
}
/**
* eek_keysym_to_string:
* @keysym: keysym ID
@ -62,47 +138,25 @@ keysym_label_compare (const void *key0, const void *key1)
G_CONST_RETURN gchar *
eek_keysym_to_string (guint keysym)
{
struct eek_keysym_label bsearch_key, *bsearch_val;
/* First, search special keysyms. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
special_keysym_labels,
G_N_ELEMENTS(special_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val)
return g_strdup (bsearch_val->label);
/* Check for Latin-1 characters (1:1 mapping) */
if ((keysym >= 0x0020 && keysym <= 0x007e) ||
(keysym >= 0x00a0 && keysym <= 0x00ff))
return unichar_to_utf8 (keysym);
/* Also check for directly encoded 24-bit UCS characters:
*/
if ((keysym & 0xff000000) == 0x01000000)
return unichar_to_utf8 (keysym & 0x00ffffff);
/* Search known unicode keysyms. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
unicode_keysym_labels,
G_N_ELEMENTS(unicode_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val)
return g_strdup (bsearch_val->label);
/* Finally, search keynames. */
bsearch_key.keysym = keysym;
bsearch_val = bsearch (&bsearch_key,
keyname_keysym_labels,
G_N_ELEMENTS(keyname_keysym_labels),
sizeof (struct eek_keysym_label),
keysym_label_compare);
if (bsearch_val)
return g_strdup (bsearch_val->label);
const gchar *label;
if (find_keysym (keysym, &label, NULL))
return label;
return g_strdup ("");
}
/**
* eek_keysym_get_category:
* @keysym: keysym ID
*
* Return a string representation of @keysym.
*/
EekKeysymCategory
eek_keysym_get_category (guint keysym)
{
EekKeysymCategory category;
if (find_keysym (keysym, NULL, &category))
return category;
return EEK_KEYSYM_CATEGORY_UNKNOWN;
}

View File

@ -23,6 +23,14 @@
#define EEK_INVALID_KEYSYM ((guint)(-1))
#define EEK_INVALID_KEYCODE ((guint)(-1))
typedef enum {
EEK_KEYSYM_CATEGORY_LETTER,
EEK_KEYSYM_CATEGORY_FUNCTION,
EEK_KEYSYM_CATEGORY_KEYNAME,
EEK_KEYSYM_CATEGORY_UNKNOWN
} EekKeysymCategory;
G_CONST_RETURN gchar *eek_keysym_to_string (guint keysym);
EekKeysymCategory eek_keysym_get_category (guint keysym);
#endif /* EEK_KEYSYMS_H */

View File

@ -28,16 +28,17 @@ if len(sys.argv) != 2:
table = dict()
for line in sys.stdin:
line = line.decode('UTF-8')
match = re.match(r'\s*(0x[0-9A-F]+)\s+(\S*)', line, re.I)
match = re.match(r'\s*(0x[0-9A-F]+)\s+(\S*)\s+(\S*)', line, re.I)
if match:
table[int(match.group(1), 16)] = match.group(2)
table[int(match.group(1), 16)] = (match.group(2), match.group(3))
sys.stdout.write("static const struct eek_keysym_label %s[] = {\n" %
sys.argv[1])
for index, (keysym, label) in enumerate([(keysym, table[keysym])
for keysym in sorted(table.keys())]):
sys.stdout.write(" { 0x%X, %s }" % (keysym, label.encode('UTF-8')))
for index, (keysym, (l, c)) in enumerate([(keysym, table[keysym])
for keysym in sorted(table.keys())]):
sys.stdout.write(" { 0x%X, %s, %s }" %
(keysym, l.encode('UTF-8'), c.encode('UTF-8')))
if index < len(table) - 1:
sys.stdout.write(",")
sys.stdout.write("\n")

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +1,31 @@
0x20 ""
0x8A3 "horiz\nconn"
0xFE50 "ˋ"
0xFE51 "ˊ"
0xFE52 "ˆ"
0xFE53 "~"
0xFE54 "ˉ"
0xFE55 "˘"
0xFE56 "˙"
0xFE57 "¨"
0xFE58 "˚"
0xFE59 "˝"
0xFE5A "ˇ"
0xFE5B "¸"
0xFE5C "˛"
0xFF14 "Scroll\nLock"
0xFF20 "Compose"
0xFF55 "Page\nUp"
0xFF56 "Page\nDown"
0xFF7E "AltGr"
0xFF7F "Num\nLock"
0xFF8D "Enter"
0xFF95 "Home"
0xFF96 "Left"
0xFF97 "Up"
0xFF98 "Right"
0xFF99 "Down"
0xFF9C "End"
0xFF9D "Begin"
0xFF9E "Ins"
0xFF9F "Del"
0x20 "" EEK_KEYSYM_LETTER
0x8A3 "horiz\nconn" EEK_KEYSYM_LETTER
0xFE50 "ˋ" EEK_KEYSYM_LETTER
0xFE51 "ˊ" EEK_KEYSYM_LETTER
0xFE52 "ˆ" EEK_KEYSYM_LETTER
0xFE53 "~" EEK_KEYSYM_LETTER
0xFE54 "ˉ" EEK_KEYSYM_LETTER
0xFE55 "˘" EEK_KEYSYM_LETTER
0xFE56 "˙" EEK_KEYSYM_LETTER
0xFE57 "¨" EEK_KEYSYM_LETTER
0xFE58 "˚" EEK_KEYSYM_LETTER
0xFE59 "˝" EEK_KEYSYM_LETTER
0xFE5A "ˇ" EEK_KEYSYM_LETTER
0xFE5B "¸" EEK_KEYSYM_LETTER
0xFE5C "˛" EEK_KEYSYM_LETTER
0xFF14 "Scroll\nLock" EEK_KEYSYM_FUNCTION
0xFF20 "Compose" EEK_KEYSYM_FUNCTION
0xFF55 "Page\nUp" EEK_KEYSYM_FUNCTION
0xFF56 "Page\nDown" EEK_KEYSYM_FUNCTION
0xFF7E "AltGr" EEK_KEYSYM_MODIFIER
0xFF7F "Num\nLock" EEK_KEYSYM_MODIFIER
0xFF8D "Enter" EEK_KEYSYM_FUNCTION
0xFF95 "Home" EEK_KEYSYM_FUNCTION
0xFF96 "Left" EEK_KEYSYM_FUNCTION
0xFF97 "Up" EEK_KEYSYM_FUNCTION
0xFF98 "Right" EEK_KEYSYM_FUNCTION
0xFF99 "Down" EEK_KEYSYM_FUNCTION
0xFF9C "End" EEK_KEYSYM_FUNCTION
0xFF9D "Begin" EEK_KEYSYM_FUNCTION
0xFF9E "Ins" EEK_KEYSYM_FUNCTION
0xFF9F "Del" EEK_KEYSYM_FUNCTION

File diff suppressed because it is too large Load Diff