--- rxvt-unicode/src/keyboard.C 2010/08/24 23:57:04 1.37 +++ rxvt-unicode/src/keyboard.C 2011/04/30 18:45:38 1.41 @@ -4,7 +4,7 @@ * * All portions of code are copyright by their respective author/s. * Copyright (c) 2005 WU Fengguang - * Copyright (c) 2005-2006 Marc Lehmann + * Copyright (c) 2005-2006 Marc Lehmann * * 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 @@ -68,7 +68,7 @@ output_string (rxvt_term *rt, const char *str) { if (strncmp (str, "command:", 8) == 0) - rt->cmd_write (str + 8, strlen (str) - 8); + rt->cmdbuf_append (str + 8, strlen (str) - 8); else if (strncmp (str, "perl:", 5) == 0) HOOK_INVOKE((rt, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); else @@ -88,7 +88,7 @@ //else if (a->state != b->state) // this behavior is to be discussed // return b->state - a->state; else - return b->range - a->range; + return 0; } //////////////////////////////////////////////////////////////////////////////// @@ -135,26 +135,10 @@ { key->keysym = keysym; key->state = state; - key->range = 1; key->str = translation; key->type = keysym_t::STRING; - if (strncmp (translation, "list", 4) == 0 && translation [4]) - { - char *middle = strchr (translation + 5, translation [4]); - char *suffix = strrchr (translation + 5, translation [4]); - - if (suffix && middle && suffix > middle + 1) - { - key->type = keysym_t::LIST; - key->range = suffix - middle - 1; - - memmove (translation, translation + 4, strlen (translation + 4) + 1); - } - else - rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); - } - else if (strncmp (translation, "builtin:", 8) == 0) + if (strncmp (translation, "builtin:", 8) == 0) key->type = keysym_t::BUILTIN; register_keymap (key); @@ -205,8 +189,6 @@ if (key.type != keysym_t::BUILTIN) { - int keysym_offset = keysym - key.keysym; - wchar_t *wc = rxvt_utf8towcs (key.str); char *str = rxvt_wcstombs (wc); // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) @@ -217,24 +199,6 @@ case keysym_t::STRING: output_string (term, str); break; - - case keysym_t::LIST: - { - char buf[STRING_MAX]; - - char *prefix, *middle, *suffix; - - prefix = str; - middle = strchr (prefix + 1, *prefix); - suffix = strrchr (middle + 1, *prefix); - - memcpy (buf, prefix + 1, middle - prefix - 1); - buf [middle - prefix - 1] = middle [keysym_offset + 1]; - strcpy (buf + (middle - prefix), suffix + 1); - - output_string (term, buf); - } - break; } free (str); @@ -252,18 +216,15 @@ unsigned int i, index, hashkey; vector sorted_keymap; uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket - uint16_t hash_bucket_counter[KEYSYM_HASH_BUCKETS]; // #elements in each bucket memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); - memset (hash_bucket_counter, 0, sizeof (hash_bucket_counter)); // determine hash bucket size for (i = 0; i < keymap.size (); ++i) - for (int j = min (keymap [i]->range, KEYSYM_HASH_BUCKETS) - 1; j >= 0; --j) - { - hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; - ++hash_bucket_size [hashkey]; - } + { + hashkey = keymap [i]->keysym & KEYSYM_HASH_MASK; + ++hash_bucket_size [hashkey]; + } // now we know the size of each bucket // compute the index of each bucket @@ -277,25 +238,26 @@ // and allocate just enough space sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); + memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); + // fill in sorted_keymap // it is sorted in each bucket for (i = 0; i < keymap.size (); ++i) - for (int j = min (keymap [i]->range, KEYSYM_HASH_BUCKETS) - 1; j >= 0; --j) - { - hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; - - index = hash [hashkey] + hash_bucket_counter [hashkey]; - - while (index > hash [hashkey] - && compare_priority (keymap [i], sorted_keymap [index - 1]) > 0) - { - sorted_keymap [index] = sorted_keymap [index - 1]; - --index; - } - - sorted_keymap [index] = keymap [i]; - ++hash_bucket_counter [hashkey]; - } + { + hashkey = keymap [i]->keysym & KEYSYM_HASH_MASK; + + index = hash [hashkey] + hash_bucket_size [hashkey]; + + while (index > hash [hashkey] + && compare_priority (keymap [i], sorted_keymap [index - 1]) > 0) + { + sorted_keymap [index] = sorted_keymap [index - 1]; + --index; + } + + sorted_keymap [index] = keymap [i]; + ++hash_bucket_size [hashkey]; + } keymap.swap (sorted_keymap); @@ -306,8 +268,7 @@ index = hash[i]; for (int j = 0; j < hash_bucket_size [i]; ++j) { - if (keymap [index + j]->range == 1) - assert (i == (keymap [index + j]->keysym & KEYSYM_HASH_MASK)); + assert (i == (keymap [index + j]->keysym & KEYSYM_HASH_MASK)); if (j) assert (compare_priority (keymap [index + j - 1], @@ -319,16 +280,13 @@ for (i = 0; i < sorted_keymap.size (); ++i) { keysym_t *a = sorted_keymap[i]; - for (int j = 0; j < a->range; ++j) - { - int index = find_keysym (a->keysym + j, a->state); + int index = find_keysym (a->keysym, a->state); - assert (index >= 0); - keysym_t *b = keymap [index]; - assert (i == index // the normally expected result - || IN_RANGE_INC (a->keysym + j, b->keysym, b->keysym + b->range) - && compare_priority (a, b) <= 0); // is effectively the same or a closer match - } + assert (index >= 0); + keysym_t *b = keymap [index]; + assert (i == index // the normally expected result + || a->keysym == b->keysym + && compare_priority (a, b) <= 0); // is effectively the same or a closer match } #endif } @@ -346,7 +304,7 @@ { keysym_t *key = keymap [index]; - if (key->keysym <= keysym && keysym < key->keysym + key->range + if (key->keysym == keysym // match only the specified bits in state and ignore others && (key->state & state) == key->state) return index;