--- rxvt-unicode/src/keyboard.C 2006/01/24 19:40:12 1.23 +++ rxvt-unicode/src/keyboard.C 2009/12/26 10:24:04 1.32 @@ -1,3 +1,26 @@ +/*----------------------------------------------------------------------* + * File: keyboard.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2005 WU Fengguang + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + #include "../config.h" #include "rxvt.h" @@ -47,7 +70,7 @@ keysym_t keyboard_manager::stock_keymap[] = { /* examples */ - /* keysym, state, range, handler, str */ + /* keysym, state, range, type, str */ //{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"}, //{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, //{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, @@ -76,7 +99,7 @@ if (strncmp (str, "command:", 8) == 0) rt->cmd_write (str + 8, strlen (str) - 8); else if (strncmp (str, "perl:", 5) == 0) - HOOK_INVOKE((rt, HOOK_KEYBOARD_COMMAND, DT_STR, str + 5, DT_END)); + HOOK_INVOKE((rt, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); else rt->tt_write (str, strlen (str)); } @@ -117,30 +140,13 @@ return len; } -//////////////////////////////////////////////////////////////////////////////// -// return: #bits of '1' -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) -# define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n__); })) -#else -static int -bitcount (uint16_t n) -{ - int i; - - for (i = 0; n; ++i, n &= n - 1) - ; - - return i; -} -#endif - // return: priority_of_a - priority_of_b static int compare_priority (keysym_t *a, keysym_t *b) { // (the more '1's in state; the less range): the greater priority - int ca = bitcount (a->state /* & OtherModMask */); - int cb = bitcount (b->state /* & OtherModMask */); + int ca = rxvt_popcount (a->state /* & OtherModMask */); + int cb = rxvt_popcount (b->state /* & OtherModMask */); if (ca != cb) return ca - cb; @@ -209,13 +215,13 @@ { 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; - strcpy (translation, translation + 4); + memmove (translation, translation + 4, strlen (translation + 4) + 1); } else rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); @@ -422,7 +428,7 @@ keymap.swap (sorted_keymap); -#ifdef DEBUG_STRICT +#ifndef NDEBUG // check for invariants for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i) { @@ -448,8 +454,9 @@ assert (index >= 0); keysym_t *b = keymap [index]; - assert (i == (signed) index || // the normally expected result - (a->keysym + j) >= b->keysym && (a->keysym + j) <= (b->keysym + b->range) && compare_priority (a, b) <= 0); // is effectively the same or a closer match + 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 } } #endif @@ -461,7 +468,7 @@ int hashkey = keysym & KEYSYM_HASH_MASK; unsigned int index = hash [hashkey]; unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 - ? hash [hashkey + 1] + ? hash [hashkey + 1] : keymap.size (); for (; index < end; ++index)