diff options
author | David 'Digit' Turner <digit@android.com> | 2011-01-19 13:12:35 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-01-19 13:12:35 -0800 |
commit | 5bfd3974787f84703db2356680e314688005a17c (patch) | |
tree | dc99b32d5172a3964bedbfe6264b770faad3cbad | |
parent | 3a003a41d577050133b5dc922e8e769d9250bbd8 (diff) | |
parent | 0158ea3220978ecc0fa1738e4a0bdae83fa36175 (diff) | |
download | external_qemu-5bfd3974787f84703db2356680e314688005a17c.zip external_qemu-5bfd3974787f84703db2356680e314688005a17c.tar.gz external_qemu-5bfd3974787f84703db2356680e314688005a17c.tar.bz2 |
Merge "Make "qwerty2" the default charmap."
-rw-r--r-- | android/charmap.c | 147 | ||||
-rw-r--r-- | android/charmap.h | 33 | ||||
-rw-r--r-- | android/console.c | 4 | ||||
-rw-r--r-- | android/skin/keyboard.c | 9 | ||||
-rw-r--r-- | hw/goldfish_events_device.c | 30 |
5 files changed, 74 insertions, 149 deletions
diff --git a/android/charmap.c b/android/charmap.c index 81c866a..95dacee 100644 --- a/android/charmap.c +++ b/android/charmap.c @@ -133,73 +133,9 @@ static const AKeycodeMapEntry keycode_map[] = { /* the following is automatically generated by the 'gen-charmap.py' script * do not touch. the generation command was: - * gen-charmap.py qwerty.kcm qwerty2.kcm + * gen-charmap.py qwerty2.kcm */ -static const AKeyEntry _qwerty_keys[] = -{ - /* keycode base caps fn caps+fn number */ - - { kKeyCodeA , 'a', 'A', '#', 0x00, '#' }, - { kKeyCodeB , 'b', 'B', '<', 0x00, '<' }, - { kKeyCodeC , 'c', 'C', '9', 0x00E7, '9' }, - { kKeyCodeD , 'd', 'D', '5', 0x00, '5' }, - { kKeyCodeE , 'e', 'E', '2', 0x0301, '2' }, - { kKeyCodeF , 'f', 'F', '6', 0x00A5, '6' }, - { kKeyCodeG , 'g', 'G', '-', '_', '-' }, - { kKeyCodeH , 'h', 'H', '[', '{', '[' }, - { kKeyCodeI , 'i', 'I', '$', 0x0302, '$' }, - { kKeyCodeJ , 'j', 'J', ']', '}', ']' }, - { kKeyCodeK , 'k', 'K', '"', '~', '"' }, - { kKeyCodeL , 'l', 'L', '\'', '`', '\'' }, - { kKeyCodeM , 'm', 'M', '!', 0x00, '!' }, - { kKeyCodeN , 'n', 'N', '>', 0x0303, '>' }, - { kKeyCodeO , 'o', 'O', '(', 0x00, '(' }, - { kKeyCodeP , 'p', 'P', ')', 0x00, ')' }, - { kKeyCodeQ , 'q', 'Q', '*', 0x0300, '*' }, - { kKeyCodeR , 'r', 'R', '3', 0x20AC, '3' }, - { kKeyCodeS , 's', 'S', '4', 0x00DF, '4' }, - { kKeyCodeT , 't', 'T', '+', 0x00A3, '+' }, - { kKeyCodeU , 'u', 'U', '&', 0x0308, '&' }, - { kKeyCodeV , 'v', 'V', '=', '^', '=' }, - { kKeyCodeW , 'w', 'W', '1', 0x00, '1' }, - { kKeyCodeX , 'x', 'X', '8', 0x00, '8' }, - { kKeyCodeY , 'y', 'Y', '%', 0x00A1, '%' }, - { kKeyCodeZ , 'z', 'Z', '7', 0x00, '7' }, - { kKeyCodeComma , ',', ';', ';', '|', ',' }, - { kKeyCodePeriod , '.', ':', ':', 0x2026, '.' }, - { kKeyCodeAt , '@', '0', '0', 0x2022, '0' }, - { kKeyCodeSlash , '/', '?', '?', '\\', '/' }, - { kKeyCodeSpace , 0x20, 0x20, 0x9, 0x9, 0x20 }, - { kKeyCodeNewline , 0xa, 0xa, 0xa, 0xa, 0xa }, - { kKeyCodeTab , 0x9, 0x9, 0x9, 0x9, 0x9 }, - { kKeyCode0 , '0', ')', '0', ')', '0' }, - { kKeyCode1 , '1', '!', '1', '!', '1' }, - { kKeyCode2 , '2', '@', '2', '@', '2' }, - { kKeyCode3 , '3', '#', '3', '#', '3' }, - { kKeyCode4 , '4', '$', '4', '$', '4' }, - { kKeyCode5 , '5', '%', '5', '%', '5' }, - { kKeyCode6 , '6', '^', '6', '^', '6' }, - { kKeyCode7 , '7', '&', '7', '&', '7' }, - { kKeyCode8 , '8', '*', '8', '*', '8' }, - { kKeyCode9 , '9', '(', '9', '(', '9' }, - { kKeyCodeGrave , '`', '~', '`', '~', '`' }, - { kKeyCodeMinus , '-', '_', '-', '_', '-' }, - { kKeyCodeEquals , '=', '+', '=', '+', '=' }, - { kKeyCodeLeftBracket , '[', '{', '[', '{', '[' }, - { kKeyCodeRightBracket , ']', '}', ']', '}', ']' }, - { kKeyCodeBackslash , '\\', '|', '\\', '|', '\\' }, - { kKeyCodeSemicolon , ';', ':', ';', ':', ';' }, - { kKeyCodeApostrophe , '\'', '"', '\'', '"', '\'' }, -}; - -static const AKeyCharmap _qwerty_charmap = -{ - _qwerty_keys, - 51, - "qwerty" -}; - static const AKeyEntry _qwerty2_keys[] = { /* keycode base caps fn caps+fn number */ @@ -257,7 +193,7 @@ static const AKeyEntry _qwerty2_keys[] = { kKeyCodeApostrophe , '\'', '"', '\'', '"', '\'' }, }; -static const AKeyCharmap _qwerty2_charmap = +static const AKeyCharmap _default_charmap = { _qwerty2_keys, 51, @@ -267,8 +203,7 @@ static const AKeyCharmap _qwerty2_charmap = /* Custom character map created with -charmap option. */ static AKeyCharmap android_custom_charmap = { 0 }; -static const AKeyCharmap** android_charmaps = 0; -static int android_charmap_count = 0; +static const AKeyCharmap* android_charmap = &_default_charmap; /* Checks if a character represents an end of the line. * Returns a non-zero value if ch is an EOL character. Returns @@ -692,31 +627,17 @@ parse_kcm_file(const char* kcm_file_path, AKeyCharmap* char_map) { int android_charmap_setup(const char* kcm_file_path) { - // android_charmap_count being non-zero is used here as a flag, - // indicating that charmap has been initialized for the running - // executable. - if (android_charmap_count != 0) { + + /* Return if we already loaded a charmap */ + if (android_charmap != &_default_charmap || kcm_file_path == NULL) return 0; - } - if (NULL != kcm_file_path) { - if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) { - // Here we have two default charmaps and the custom one. - android_charmap_count = 3; - AARRAY_NEW(android_charmaps, android_charmap_count); - android_charmaps[0] = &android_custom_charmap; - android_charmaps[1] = &_qwerty_charmap; - android_charmaps[2] = &_qwerty2_charmap; - } else { - derror("Unable to parse kcm file."); - return -1; - } + if (!parse_kcm_file(kcm_file_path, &android_custom_charmap)) { + // Here we have the default charmap and the custom one. + android_charmap = &android_custom_charmap; } else { - // Here we have only two default charmaps. - android_charmap_count = 2; - AARRAY_NEW(android_charmaps, android_charmap_count); - android_charmaps[0] = &_qwerty_charmap; - android_charmaps[1] = &_qwerty2_charmap; + derror("Unable to parse kcm file."); + return -1; } return 0; @@ -724,40 +645,21 @@ android_charmap_setup(const char* kcm_file_path) { void android_charmap_done(void) { - if (NULL != android_charmaps) { - int n; - for (n = 0; n < android_charmap_count; n++) { - // Entries for qwerty and qwerty2 character maps are - // static entries defined in charmap.c - if ((_qwerty_charmap.entries != android_charmaps[n]->entries) && - (_qwerty2_charmap.entries != android_charmaps[n]->entries)) { - AFREE((void*)android_charmaps[n]->entries); - } - } - AFREE(android_charmaps); - } + if (android_charmap != &_default_charmap) + AFREE((void*)android_charmap->entries); } const AKeyCharmap* android_get_charmap_by_name(const char* name) { - int nn; - if (name != NULL) { - // Find charmap by its name in the array of available charmaps. - for (nn = 0; nn < android_charmap_count; nn++) { - if (!strcmp(android_charmaps[nn]->name, name)) { - return android_charmaps[nn]; - } - } + if (!strcmp(android_charmap->name, name)) + return android_charmap; + if (!strcmp(_default_charmap.name, name)) + return &_default_charmap; } return NULL; } -const AKeyCharmap* -android_get_charmap_by_index(unsigned int index) { - return index < android_charmap_count ? android_charmaps[index] : NULL; -} - int android_charmap_reverse_map_unicode(const AKeyCharmap* cmap, unsigned int unicode, @@ -825,14 +727,17 @@ android_charmap_reverse_map_unicode(const AKeyCharmap* cmap, return 0; } -const AKeyCharmap* -android_get_default_charmap(void) +const AKeyCharmap* android_get_default_charmap(void) +{ + return &_default_charmap; +} + +const AKeyCharmap* android_get_charmap(void) { - return android_get_charmap_by_index(0); + return android_charmap; } -const char* -android_get_default_charmap_name(void) +const char* android_get_charmap_name(void) { - return android_get_default_charmap()->name; + return android_get_charmap()->name; } diff --git a/android/charmap.h b/android/charmap.h index 6bf35c0..4c39495 100644 --- a/android/charmap.h +++ b/android/charmap.h @@ -51,7 +51,10 @@ void kcm_extract_charmap_name(const char* kcm_file_path, char* charmap_name, int max_len); -/* Initialzes key charmap array. +/* Gets a pointer to the default hard-coded charmap */ +const AKeyCharmap* android_get_default_charmap(void); + +/* Parse a charmap file and add it to our list. * Key charmap array always contains two maps: one for qwerty, and * another for qwerty2 keyboard layout. However, a custom layout can * be requested with -charmap option. In tha case kcm_file_path @@ -61,24 +64,21 @@ void kcm_extract_charmap_name(const char* kcm_file_path, * kcm_file_path is NULL and final key charmap array will contain only * two default entries. * Returns a zero value on success, or -1 on failure. -*/ + * + * Note: on success, the charmap will be returned by android_get_charmap() + */ int android_charmap_setup(const char* kcm_file_path); /* Cleanups initialization performed in android_charmap_setup routine. */ void android_charmap_done(void); /* Gets charmap descriptor by its name. - * This routine finds and returns pointer to a descriptor in the array of - * charmaps that matches given name. If no such descriptor has been found, this - * routine returns NULL. + * This routine tries to find a charmap by name. This will compare the + * name to the default charmap's name, or any charmap loaded with + * android_charmap_setup(). Returns NULL on failure. */ const AKeyCharmap* android_get_charmap_by_name(const char* name); -/* Gets charmap descriptor by its index in the array of charmaps. - * If index is greater than charmap array size, this routine returns NULL. - */ -const AKeyCharmap* android_get_charmap_by_index(unsigned int index); - /* Maps given unicode key character into a keycode and adds mapped keycode into * keycode array. This routine uses charmap passed as cmap parameter to do the * translation, and 'down' parameter to generate appropriate ('down' or 'up') @@ -90,10 +90,15 @@ android_charmap_reverse_map_unicode(const AKeyCharmap* cmap, int down, AKeycodeBuffer* keycodes); -/* Gets default charmap (index 0) */ -const AKeyCharmap* android_get_default_charmap(void); +/* Return a pointer to the active charmap. If android_charmap_setup() was + * called succesfully, this corresponds to the newly loaded charmap. + * + * Otherwise, return a pointer to the default charmap. + */ +const AKeyCharmap* android_get_charmap(void); -/* Gets name of the default charmap (index 0) */ -const char* android_get_default_charmap_name(void); +/* Return the name of the charmap to be used. Same as + * android_get_charmap()->name */ +const char* android_get_charmap_name(void); #endif /* _android_charmap_h */ diff --git a/android/console.c b/android/console.c index a44d831..96cc005 100644 --- a/android/console.c +++ b/android/console.c @@ -1968,8 +1968,8 @@ do_event_text( ControlClient client, char* args ) return -1; } - /* Get default charmap. */ - charmap = android_get_default_charmap(); + /* Get active charmap. */ + charmap = android_get_charmap(); if (charmap == NULL) { control_write( client, "KO: no character map active in current device layout/config\r\n" ); return -1; diff --git a/android/skin/keyboard.c b/android/skin/keyboard.c index 8102e33..3ee3366 100644 --- a/android/skin/keyboard.c +++ b/android/skin/keyboard.c @@ -25,6 +25,7 @@ # define D(...) ((void)0) #endif +#define DEFAULT_ANDROID_CHARMAP "qwerty2" /** LAST PRESSED KEYS ** a small buffer of last pressed keys, this is used to properly @@ -77,7 +78,7 @@ skin_keyboard_charmap_name( SkinKeyboard* keyboard ) if (keyboard && keyboard->charmap) return keyboard->charmap->name; - return "qwerty"; + return DEFAULT_ANDROID_CHARMAP; } void @@ -520,8 +521,8 @@ skin_keyboard_create_from_charmap_name(const char* charmap_name, kb->charmap = android_get_charmap_by_name(charmap_name); if (!kb->charmap) { - // Charmap name was not found. Default to the first charmap in the array. - kb->charmap = android_get_charmap_by_index(0); + // Charmap name was not found. Default to "qwerty2" */ + kb->charmap = android_get_charmap_by_name(DEFAULT_ANDROID_CHARMAP); fprintf(stderr, "### warning, skin requires unknown '%s' charmap, reverting to '%s'\n", charmap_name, kb->charmap->name ); } @@ -540,7 +541,7 @@ skin_keyboard_create_from_charmap_name(const char* charmap_name, SkinKeyboard* skin_keyboard_create_from_aconfig( AConfig* aconfig, int use_raw_keys ) { - const char* charmap_name = "qwerty"; + const char* charmap_name = DEFAULT_ANDROID_CHARMAP; AConfig* node = aconfig_find( aconfig, "keyboard" ); if (node != NULL) { charmap_name = aconfig_str(node, "charmap", charmap_name); diff --git a/hw/goldfish_events_device.c b/hw/goldfish_events_device.c index b0f95ec..549fe4b 100644 --- a/hw/goldfish_events_device.c +++ b/hw/goldfish_events_device.c @@ -153,12 +153,24 @@ static unsigned dequeue_event(events_state *s) return n; } +static const char* +get_charmap_name(events_state *s) +{ + if (s->name != NULL) + return s->name; + + s->name = android_get_charmap_name(); + return s->name; +} + + static int get_page_len(events_state *s) { int page = s->page; - if (page == PAGE_NAME) - return strlen(s->name); - if (page >= PAGE_EVBITS && page <= PAGE_EVBITS + EV_MAX) + if (page == PAGE_NAME) { + const char* name = get_charmap_name(s); + return strlen(name); + } if (page >= PAGE_EVBITS && page <= PAGE_EVBITS + EV_MAX) return s->ev_bits[page - PAGE_EVBITS].len; if (page == PAGE_ABSDATA) return s->abs_info_count * sizeof(s->abs_info[0]); @@ -171,9 +183,10 @@ static int get_page_data(events_state *s, int offset) int page = s->page; if (offset > page_len) return 0; - if (page == PAGE_NAME) - return s->name[offset]; - if (page >= PAGE_EVBITS && page <= PAGE_EVBITS + EV_MAX) + if (page == PAGE_NAME) { + const char* name = get_charmap_name(s); + return name[offset]; + } if (page >= PAGE_EVBITS && page <= PAGE_EVBITS + EV_MAX) return s->ev_bits[page - PAGE_EVBITS].bits[offset]; if (page == PAGE_ABSDATA) { return s->abs_info[offset / sizeof(s->abs_info[0])]; @@ -306,8 +319,9 @@ void events_dev_init(uint32_t base, qemu_irq irq) AndroidHwConfig* config = android_hw; s = (events_state *) qemu_mallocz(sizeof(events_state)); - // Use name of the default charmap. - s->name = android_get_default_charmap_name(); + + // charmap name will be determined on demand + s->name = NULL; /* now set the events capability bits depending on hardware configuration */ /* apparently, the EV_SYN array is used to indicate which other |