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.7 by root, Sun Jan 16 23:55:42 2005 UTC vs.
Revision 1.10 by root, Thu Feb 3 10:24:10 2005 UTC

11//////////////////////////////////////////////////////////////////////////////// 11////////////////////////////////////////////////////////////////////////////////
12// default keycode translation map and keyevent handlers 12// default keycode translation map and keyevent handlers
13 13
14keysym_t keyboard_manager::stock_keymap[] = { 14keysym_t keyboard_manager::stock_keymap[] = {
15 /* examples */ 15 /* examples */
16 /* keysym, state, range, handler, str */ 16 /* keysym, state, range, handler, str */
17//{XK_ISO_Left_Tab, 0, 1, NORMAL, "\033[Z"}, 17//{XK_ISO_Left_Tab, 0, 1, keysym_t::NORMAL, "\033[Z"},
18//{ 'a', 0, 26, RANGE_META8, "a" "%c"}, 18//{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"},
19//{ 'a', ControlMask, 26, RANGE_META8, "" "%c"}, 19//{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"},
20//{ XK_Left, 0, 4, LIST, "DACBZ" "\033[Z"}, 20//{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."},
21//{ XK_Left, ShiftMask, 4, LIST, "dacbZ" "\033[Z"}, 21//{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."},
22//{ XK_Left, ControlMask, 4, LIST, "dacbZ" "\033OZ"}, 22//{ XK_Left, ControlMask, 4, keysym_t::LIST, ".\033O.dacb."},
23//{ XK_Tab, ControlMask, 1, NORMAL, "\033<C-Tab>"}, 23//{ XK_Tab, ControlMask, 1, keysym_t::NORMAL, "\033<C-Tab>"},
24//{ XK_apostrophe, ControlMask, 1, NORMAL, "\033<C-'>"}, 24//{ XK_apostrophe, ControlMask, 1, keysym_t::NORMAL, "\033<C-'>"},
25//{ XK_slash, ControlMask, 1, NORMAL, "\033<C-/>"}, 25//{ XK_slash, ControlMask, 1, keysym_t::NORMAL, "\033<C-/>"},
26//{ XK_semicolon, ControlMask, 1, NORMAL, "\033<C-;>"}, 26//{ XK_semicolon, ControlMask, 1, keysym_t::NORMAL, "\033<C-;>"},
27//{ XK_grave, ControlMask, 1, NORMAL, "\033<C-`>"}, 27//{ XK_grave, ControlMask, 1, keysym_t::NORMAL, "\033<C-`>"},
28//{ XK_comma, ControlMask, 1, NORMAL, "\033<C-\054>"}, 28//{ XK_comma, ControlMask, 1, keysym_t::NORMAL, "\033<C-\054>"},
29//{ XK_Return, ControlMask, 1, NORMAL, "\033<C-Return>"}, 29//{ XK_Return, ControlMask, 1, keysym_t::NORMAL, "\033<C-Return>"},
30//{ XK_Return, ShiftMask, 1, NORMAL, "\033<S-Return>"}, 30//{ XK_Return, ShiftMask, 1, keysym_t::NORMAL, "\033<S-Return>"},
31//{ ' ', ShiftMask, 1, NORMAL, "\033<S-Space>"}, 31//{ ' ', ShiftMask, 1, keysym_t::NORMAL, "\033<S-Space>"},
32//{ '.', ControlMask, 1, NORMAL, "\033<C-.>"}, 32//{ '.', ControlMask, 1, keysym_t::NORMAL, "\033<C-.>"},
33//{ '0', ControlMask, 10, RANGE, "0" "\033<C-%c>"}, 33//{ '0', ControlMask, 10, keysym_t::RANGE, "0" "\033<C-%c>"},
34//{ '0', MetaMask|ControlMask, 10, RANGE, "0" "\033<M-C-%c>"}, 34//{ '0', MetaMask|ControlMask, 10, keysym_t::RANGE, "0" "\033<M-C-%c>"},
35//{ 'a', MetaMask|ControlMask, 26, RANGE, "a" "\033<M-C-%c>"}, 35//{ 'a', MetaMask|ControlMask, 26, keysym_t::RANGE, "a" "\033<M-C-%c>"},
36}; 36};
37 37
38static void 38static void
39output_string (rxvt_term *rt, const char *str) 39output_string (rxvt_term *rt, const char *str)
40{ 40{
41 assert (rt && str);
42
43 if (strncmp (str, "proto:", 6) == 0) 41 if (strncmp (str, "command:", 8) == 0)
44 rt->cmd_write ((unsigned char *)str + 6, strlen (str) - 6); 42 rt->cmd_write ((unsigned char *)str + 8, strlen (str) - 8);
45 else 43 else
46 rt->tt_write ((unsigned char *)str, strlen (str)); 44 rt->tt_write ((unsigned char *)str, strlen (str));
47} 45}
48 46
49static void 47static void
101 99
102// return: priority_of_a - priority_of_b 100// return: priority_of_a - priority_of_b
103static int 101static int
104compare_priority (keysym_t *a, keysym_t *b) 102compare_priority (keysym_t *a, keysym_t *b)
105{ 103{
106 assert (a && b);
107
108 // (the more '1's in state; the less range): the greater priority 104 // (the more '1's in state; the less range): the greater priority
109 int ca = bitcount (a->state /* & OtherModMask */); 105 int ca = bitcount (a->state /* & OtherModMask */);
110 int cb = bitcount (b->state /* & OtherModMask */); 106 int cb = bitcount (b->state /* & OtherModMask */);
111 107
112 if (ca != cb) 108 if (ca != cb)
157// the string 'trans' is copied to an internal managed buffer, 153// the string 'trans' is copied to an internal managed buffer,
158// so the caller can free memory of 'trans' at any time. 154// so the caller can free memory of 'trans' at any time.
159void 155void
160keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) 156keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans)
161{ 157{
162 assert (trans);
163
164 keysym_t *key = new keysym_t; 158 keysym_t *key = new keysym_t;
165 wchar_t *wc = rxvt_mbstowcs (trans); 159 wchar_t *wc = rxvt_mbstowcs (trans);
166printf ("CONV <%s> %x %x %x %x\n", trans, (int)wc[0], (int)wc[1], (int)wc[2], (int)wc[3]);
167 const char *translation = rxvt_wcstoutf8 (wc); 160 const char *translation = rxvt_wcstoutf8 (wc);
168 free (wc); 161 free (wc);
169 162
170 if (key && translation) 163 if (key && translation)
171 { 164 {
204} 197}
205 198
206void 199void
207keyboard_manager::register_keymap (keysym_t *key) 200keyboard_manager::register_keymap (keysym_t *key)
208{ 201{
209 assert (key);
210 assert (key->range >= 1);
211
212 if (keymap.size () == keymap.capacity ()) 202 if (keymap.size () == keymap.capacity ())
213 keymap.reserve (keymap.size () * 2); 203 keymap.reserve (keymap.size () * 2);
214 204
215 keymap.push_back (key); 205 keymap.push_back (key);
216 hash[0] = 3; 206 hash[0] = 3;
347 memset (hash_budget_counter, 0, sizeof (hash_budget_counter)); 337 memset (hash_budget_counter, 0, sizeof (hash_budget_counter));
348 338
349 // count keysyms for corresponding hash budgets 339 // count keysyms for corresponding hash budgets
350 for (i = 0; i < keymap.size (); ++i) 340 for (i = 0; i < keymap.size (); ++i)
351 { 341 {
352 assert (keymap [i]);
353 hashkey = (keymap [i]->keysym & KEYSYM_HASH_MASK); 342 hashkey = keymap [i]->keysym & KEYSYM_HASH_MASK;
354 ++hash_budget_size [hashkey]; 343 ++hash_budget_size [hashkey];
355 } 344 }
356 345
357 // keysym A with range>1 is counted one more time for 346 // a keysym_t with range>1 is counted one more time for every keysym that
358 // every keysym B lies in its range 347 // lies in its range
359 for (i = 0; i < keymap.size (); ++i) 348 for (i = 0; i < keymap.size (); ++i)
360 { 349 {
361 if (keymap[i]->range > 1) 350 if (keymap[i]->range > 1)
362 { 351 {
363 for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j > 0; --j) 352 for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j > 0; --j)
377 index += hash_budget_size [i - 1]; 366 index += hash_budget_size [i - 1];
378 hash[i] = (hash_budget_size [i] ? index : hash [i - 1]); 367 hash[i] = (hash_budget_size [i] ? index : hash [i - 1]);
379 } 368 }
380 369
381 // and allocate just enough space 370 // and allocate just enough space
382 //sorted_keymap.reserve (hash[i - 1] + hash_budget_size[i - 1]);
383 sorted_keymap.insert (sorted_keymap.begin (), index + hash_budget_size [i - 1], 0); 371 sorted_keymap.insert (sorted_keymap.begin (), index + hash_budget_size [i - 1], 0);
384 372
385 // fill in sorted_keymap 373 // fill in sorted_keymap
386 // it is sorted in each budget 374 // it is sorted in each budget
387 for (i = 0; i < keymap.size (); ++i) 375 for (i = 0; i < keymap.size (); ++i)
434 int index = find_keysym (a->keysym + j, a->state); 422 int index = find_keysym (a->keysym + j, a->state);
435 423
436 assert (index >= 0); 424 assert (index >= 0);
437 keysym_t *b = keymap [index]; 425 keysym_t *b = keymap [index];
438 assert (i == (signed) index || // the normally expected result 426 assert (i == (signed) index || // the normally expected result
439 (a->keysym + j) >= b->keysym && (a->keysym + j) <= (b->keysym + b->range) && compare_priority (a, b) <= 0); // is effectively the same 427 (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
440 } 428 }
441 } 429 }
442#endif 430#endif
443} 431}
444 432
449 unsigned int index = hash [hashkey]; 437 unsigned int index = hash [hashkey];
450 438
451 for (; index < keymap.size (); ++index) 439 for (; index < keymap.size (); ++index)
452 { 440 {
453 keysym_t *key = keymap [index]; 441 keysym_t *key = keymap [index];
454 assert (key);
455 442
456 if (key->keysym <= keysym && key->keysym + key->range > keysym 443 if (key->keysym <= keysym && key->keysym + key->range > keysym
457 // match only the specified bits in state and ignore others 444 // match only the specified bits in state and ignore others
458 && (key->state & state) == key->state) 445 && (key->state & state) == key->state)
459 return index; 446 return index;
460 else if (key->keysym > keysym && key->range == 1) 447 else if ((key->keysym & KEYSYM_HASH_MASK) > hashkey && key->range == 1)
461 return -1; 448 return -1;
462 } 449 }
463 450
464 return -1; 451 return -1;
465} 452}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines