--- rxvt-unicode/src/keyboard.C 2014/05/17 15:25:04 1.68 +++ rxvt-unicode/src/keyboard.C 2015/03/17 09:23:08 1.72 @@ -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, @@ -91,22 +91,42 @@ } void +keyboard_manager::unregister_action (KeySym keysym, unsigned int state) +{ + for (unsigned int i = 0; i < keymap.size (); ++i) + if (keymap [i]->keysym == keysym + && keymap [i]->state == state) + { + free (keymap [i]->str); + delete keymap [i]; + + if (i < keymap.size () - 1) + keymap [i] = keymap [keymap.size () - 1]; + keymap.pop_back (); + + break; + } +} + +void 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; key->keysym = keysym; key->state = state; - key->str = translation; + key->str = action; key->type = keysym_t::STRING; - if (strncmp (translation, "builtin:", 8) == 0) + if (strncmp (action, "builtin:", 8) == 0) key->type = keysym_t::BUILTIN; - else if (strncmp (translation, "builtin-string:", 15) == 0) + else if (strncmp (action, "builtin-string:", 15) == 0) key->type = keysym_t::BUILTIN_STRING; + unregister_action (keysym, state); + if (keymap.size () == keymap.capacity ()) keymap.reserve (keymap.size () * 2); @@ -114,8 +134,8 @@ hash[0] = 3; } -bool -keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) +keysym_t * +keyboard_manager::lookup_keysym (rxvt_term *term, KeySym keysym, unsigned int state) { assert (("register_done() need to be called", hash[0] == 0)); @@ -130,10 +150,16 @@ int index = find_keysym (keysym, state); - if (index >= 0) - { - keysym_t *key = keymap [index]; + return index >= 0 ? keymap [index] : 0; +} + +bool +keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) +{ + keysym_t *key = lookup_keysym (term, keysym, state); + if (key) + { if (key->type == keysym_t::BUILTIN_STRING) { term->tt_write_user_input (kbuf, len);