ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/keyboard.C
(Generate patch)

Comparing rxvt-unicode/src/keyboard.C (file contents):
Revision 1.26 by root, Mon Oct 9 23:12:45 2006 UTC vs.
Revision 1.33 by sf-exg, Mon Jul 26 09:57:53 2010 UTC

52 * A1 = 0; 52 * A1 = 0;
53 * Ai+1 = N1 + N2 + ... + Ni. 53 * Ai+1 = N1 + N2 + ... + Ni.
54 * it is computed from hash_budget_size[]: 54 * it is computed from hash_budget_size[]:
55 * index: 0 I1 I2 I3 In 55 * index: 0 I1 I2 I3 In
56 * value: 0...0, N1, 0...0, N2, 0...0, N3, ..., Nn, 0...0 56 * value: 0...0, N1, 0...0, N2, 0...0, N3, ..., Nn, 0...0
57 * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the compution of hash[]) 57 * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the computation of hash[])
58 * or we can say 58 * or we can say
59 * hash_budget_size[Ii] = Ni; hash_budget_size[elsewhere] = 0, 59 * hash_budget_size[Ii] = Ni; hash_budget_size[elsewhere] = 0,
60 * where 60 * where
61 * set {I1, I2, ..., In} = { hashkey of keymap[0]->keysym, ..., keymap[keymap.size-1]->keysym } 61 * set {I1, I2, ..., In} = { hashkey of keymap[0]->keysym, ..., keymap[keymap.size-1]->keysym }
62 * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK 62 * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK
68//////////////////////////////////////////////////////////////////////////////// 68////////////////////////////////////////////////////////////////////////////////
69// default keycode translation map and keyevent handlers 69// default keycode translation map and keyevent handlers
70 70
71keysym_t keyboard_manager::stock_keymap[] = { 71keysym_t keyboard_manager::stock_keymap[] = {
72 /* examples */ 72 /* examples */
73 /* keysym, state, range, handler, str */ 73 /* keysym, state, range, type, str */
74//{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"}, 74//{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"},
75//{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, 75//{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"},
76//{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, 76//{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"},
77//{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."}, 77//{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."},
78//{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."}, 78//{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."},
138 } 138 }
139 139
140 return len; 140 return len;
141} 141}
142 142
143////////////////////////////////////////////////////////////////////////////////
144// return: #bits of '1'
145#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
146# define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n__); }))
147#else
148static int
149bitcount (uint16_t n)
150{
151 int i;
152
153 for (i = 0; n; ++i, n &= n - 1)
154 ;
155
156 return i;
157}
158#endif
159
160// return: priority_of_a - priority_of_b 143// return: priority_of_a - priority_of_b
161static int 144static int
162compare_priority (keysym_t *a, keysym_t *b) 145compare_priority (keysym_t *a, keysym_t *b)
163{ 146{
164 // (the more '1's in state; the less range): the greater priority 147 // (the more '1's in state; the less range): the greater priority
165 int ca = bitcount (a->state /* & OtherModMask */); 148 int ca = rxvt_popcount (a->state /* & OtherModMask */);
166 int cb = bitcount (b->state /* & OtherModMask */); 149 int cb = rxvt_popcount (b->state /* & OtherModMask */);
167 150
168 if (ca != cb) 151 if (ca != cb)
169 return ca - cb; 152 return ca - cb;
170//else if (a->state != b->state) // this behavior is to be disscussed 153//else if (a->state != b->state) // this behavior is to be discussed
171// return b->state - a->state; 154// return b->state - a->state;
172 else 155 else
173 return b->range - a->range; 156 return b->range - a->range;
174} 157}
175 158
230 213
231 if (strncmp (translation, "list", 4) == 0 && translation [4]) 214 if (strncmp (translation, "list", 4) == 0 && translation [4])
232 { 215 {
233 char *middle = strchr (translation + 5, translation [4]); 216 char *middle = strchr (translation + 5, translation [4]);
234 char *suffix = strrchr (translation + 5, translation [4]); 217 char *suffix = strrchr (translation + 5, translation [4]);
235 218
236 if (suffix && middle && suffix > middle + 1) 219 if (suffix && middle && suffix > middle + 1)
237 { 220 {
238 key->type = keysym_t::LIST; 221 key->type = keysym_t::LIST;
239 key->range = suffix - middle - 1; 222 key->range = suffix - middle - 1;
240 223
443 ++hash_budget_counter [hashkey]; 426 ++hash_budget_counter [hashkey];
444 } 427 }
445 428
446 keymap.swap (sorted_keymap); 429 keymap.swap (sorted_keymap);
447 430
448#ifdef DEBUG_STRICT 431#ifndef NDEBUG
449 // check for invariants 432 // check for invariants
450 for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i) 433 for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i)
451 { 434 {
452 index = hash[i]; 435 index = hash[i];
453 for (int j = 0; j < hash_budget_size [i]; ++j) 436 for (int j = 0; j < hash_budget_size [i]; ++j)
469 { 452 {
470 int index = find_keysym (a->keysym + j, a->state); 453 int index = find_keysym (a->keysym + j, a->state);
471 454
472 assert (index >= 0); 455 assert (index >= 0);
473 keysym_t *b = keymap [index]; 456 keysym_t *b = keymap [index];
474 assert (i == (signed) index || // the normally expected result 457 assert (i == index // the normally expected result
475 (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 458 || IN_RANGE_INC (a->keysym + j, b->keysym, b->keysym + b->range)
459 && compare_priority (a, b) <= 0); // is effectively the same or a closer match
476 } 460 }
477 } 461 }
478#endif 462#endif
479} 463}
480 464
482keyboard_manager::find_keysym (KeySym keysym, unsigned int state) 466keyboard_manager::find_keysym (KeySym keysym, unsigned int state)
483{ 467{
484 int hashkey = keysym & KEYSYM_HASH_MASK; 468 int hashkey = keysym & KEYSYM_HASH_MASK;
485 unsigned int index = hash [hashkey]; 469 unsigned int index = hash [hashkey];
486 unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 470 unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1
487 ? hash [hashkey + 1] 471 ? hash [hashkey + 1]
488 : keymap.size (); 472 : keymap.size ();
489 473
490 for (; index < end; ++index) 474 for (; index < end; ++index)
491 { 475 {
492 keysym_t *key = keymap [index]; 476 keysym_t *key = keymap [index];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines