--- rxvt-unicode/src/keyboard.C 2011/12/03 11:47:19 1.55 +++ rxvt-unicode/src/keyboard.C 2014/04/29 13:17:54 1.65 @@ -26,11 +26,10 @@ #ifdef KEYSYM_RESOURCE -#include +#include #include "rxvtperl.h" #include "keyboard.h" -#include "command.h" /* an intro to the data structure: * @@ -64,17 +63,6 @@ * Ni(the size of group i) = hash_bucket_size[Ii]. */ -static void -output_string (rxvt_term *term, const char *str) -{ - if (strncmp (str, "command:", 8) == 0) - term->cmdbuf_append (str + 8, strlen (str) - 8); - else if (strncmp (str, "perl:", 5) == 0) - HOOK_INVOKE((term, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); - else - term->tt_write (str, strlen (str)); -} - // return: priority_of_a - priority_of_b static int compare_priority (keysym_t *a, keysym_t *b) @@ -83,12 +71,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; } //////////////////////////////////////////////////////////////////////////////// @@ -114,9 +97,6 @@ keysym_t *key = new keysym_t; - if (!key) - rxvt_fatal ("memory allocation failure. aborting.\n"); - key->keysym = keysym; key->state = state; key->str = translation; @@ -124,6 +104,8 @@ if (strncmp (translation, "builtin:", 8) == 0) key->type = keysym_t::BUILTIN; + else if (strncmp (translation, "builtin-string:", 15) == 0) + key->type = keysym_t::BUILTIN_STRING; if (keymap.size () == keymap.capacity ()) keymap.reserve (keymap.size () * 2); @@ -133,7 +115,7 @@ } 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)); @@ -152,14 +134,31 @@ { keysym_t *key = keymap [index]; - if (key->type != keysym_t::BUILTIN) + if (key->type == keysym_t::BUILTIN_STRING) + { + term->tt_write_user_input (kbuf, len); + return true; + } + else if (key->type != keysym_t::BUILTIN) { wchar_t *ws = rxvt_utf8towcs (key->str); char *str = rxvt_wcstombs (ws); // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) free (ws); - output_string (term, str); + if (char *colon = strchr (str, ':')) + { + if (strncmp (str, "command:", 8) == 0) + term->cmdbuf_append (str + 8, strlen (str) - 8); + else if (strncmp (str, "string:", 7) == 0) + term->tt_write_user_input (colon + 1, strlen (colon + 1)); + else if (strncmp (str, "perl:", 8) == 0) + HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); + else + HOOK_INVOKE ((term, HOOK_KEYBOARD_DISPATCH, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_END)); + } + else + term->tt_write_user_input (str, strlen (str)); free (str); @@ -174,7 +173,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)); @@ -188,15 +186,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));