--- rxvt-unicode/src/keyboard.C 2011/11/30 20:01:41 1.50 +++ rxvt-unicode/src/keyboard.C 2014/04/26 15:05:17 1.61 @@ -26,11 +26,10 @@ #ifdef KEYSYM_RESOURCE -#include +#include #include "rxvtperl.h" #include "keyboard.h" -#include "command.h" /* an intro to the data structure: * @@ -83,12 +82,7 @@ int ca = ecb_popcount32 (a->state /* & OtherModMask */); int cb = ecb_popcount32 (b->state /* & OtherModMask */); - if (ca != cb) - return ca - cb; -//else if (a->state != b->state) // this behavior is to be discussed -// return b->state - a->state; - else - return 0; + return ca - cb; } //////////////////////////////////////////////////////////////////////////////// @@ -107,78 +101,30 @@ } } -// a wrapper for register_translation that converts the input string -// to utf-8 and expands 'list' syntax. void -keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) +keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) { - wchar_t *wc = rxvt_mbstowcs (trans); - char *translation = rxvt_wcstoutf8 (wc); - free (wc); - - if (strncmp (translation, "list", 4) == 0 && translation [4] - && strlen (translation) < STRING_MAX) - { - char *prefix = translation + 4; - char *middle = strchr (prefix + 1, translation [4]); - char *suffix = strrchr (prefix + 1, translation [4]); - - if (suffix && middle && suffix > middle + 1) - { - int range = suffix - middle - 1; - int prefix_len = middle - prefix - 1; - char buf[STRING_MAX]; - - memcpy (buf, prefix + 1, prefix_len); - strcpy (buf + prefix_len + 1, suffix + 1); - - for (int i = 0; i < range; i++) - { - buf [prefix_len] = middle [i + 1]; - register_translation (keysym + i, state, strdup (buf)); - } + char *translation = rxvt_wcstoutf8 (ws); - free (translation); - return; - } - else - rxvt_warn ("unable to parse list-type keysym '%s', processing as normal keysym.\n", translation); - } - - register_translation (keysym, state, translation); -} - -void -keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation) -{ keysym_t *key = new keysym_t; - if (key && translation) - { - key->keysym = keysym; - key->state = state; - key->str = translation; - key->type = keysym_t::STRING; + key->keysym = keysym; + key->state = state; + key->str = translation; + key->type = keysym_t::STRING; - if (strncmp (translation, "builtin:", 8) == 0) - key->type = keysym_t::BUILTIN; + if (strncmp (translation, "builtin:", 8) == 0) + key->type = keysym_t::BUILTIN; - if (keymap.size () == keymap.capacity ()) - keymap.reserve (keymap.size () * 2); + if (keymap.size () == keymap.capacity ()) + keymap.reserve (keymap.size () * 2); - keymap.push_back (key); - hash[0] = 3; - } - else - { - delete key; - free (translation); - rxvt_fatal ("memory allocation failure. aborting.\n"); - } + keymap.push_back (key); + hash[0] = 3; } bool -keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) +keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) { assert (("register_done() need to be called", hash[0] == 0)); @@ -199,10 +145,10 @@ if (key->type != keysym_t::BUILTIN) { - wchar_t *wc = rxvt_utf8towcs (key->str); - char *str = rxvt_wcstombs (wc); + wchar_t *ws = rxvt_utf8towcs (key->str); + char *str = rxvt_wcstombs (ws); // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) - free (wc); + free (ws); output_string (term, str); @@ -219,7 +165,6 @@ keyboard_manager::register_done () { unsigned int i, index, hashkey; - vector sorted_keymap; uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); @@ -233,15 +178,14 @@ // now we know the size of each bucket // compute the index of each bucket - hash [0] = 0; - for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) + for (index = 0, i = 0; i < KEYSYM_HASH_BUCKETS; ++i) { - index += hash_bucket_size [i - 1]; hash [i] = index; + index += hash_bucket_size [i]; } // and allocate just enough space - sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); + simplevec sorted_keymap (index, 0); memset (hash_bucket_size, 0, sizeof (hash_bucket_size));