--- rxvt-unicode/src/keyboard.C 2011/12/03 11:31:56 1.54 +++ rxvt-unicode/src/keyboard.C 2014/05/23 22:25:34 1.70 @@ -8,7 +8,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -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; } //////////////////////////////////////////////////////////////////////////////// @@ -108,38 +91,31 @@ } void -keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) +keyboard_manager::register_action (KeySym keysym, unsigned int state, const wchar_t *ws) { - char *translation = rxvt_wcstoutf8 (ws); + char *action = rxvt_wcstoutf8 (ws); keysym_t *key = new keysym_t; - if (key && translation) - { - 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; + key->keysym = keysym; + key->state = state; + key->str = action; + key->type = keysym_t::STRING; + + if (strncmp (action, "builtin:", 8) == 0) + key->type = keysym_t::BUILTIN; + else if (strncmp (action, "builtin-string:", 15) == 0) + key->type = keysym_t::BUILTIN_STRING; - 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)); @@ -158,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:", 5) == 0) + HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); + else + HOOK_INVOKE ((term, HOOK_ACTION, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_INT, 0, DT_STR_LEN, kbuf, len, DT_END)); + } + else + term->tt_write_user_input (str, strlen (str)); free (str); @@ -180,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)); @@ -194,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));