|
|
1 | /*----------------------------------------------------------------------* |
|
|
2 | * File: keyboard.C |
|
|
3 | *----------------------------------------------------------------------* |
|
|
4 | * |
|
|
5 | * All portions of code are copyright by their respective author/s. |
|
|
6 | * Copyright (c) 2005 WU Fengguang |
|
|
7 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
|
|
8 | * |
|
|
9 | * This program is free software; you can redistribute it and/or modify |
|
|
10 | * it under the terms of the GNU General Public License as published by |
|
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
|
12 | * (at your option) any later version. |
|
|
13 | * |
|
|
14 | * This program is distributed in the hope that it will be useful, |
|
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
17 | * GNU General Public License for more details. |
|
|
18 | * |
|
|
19 | * You should have received a copy of the GNU General Public License |
|
|
20 | * along with this program; if not, write to the Free Software |
|
|
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
22 | *----------------------------------------------------------------------*/ |
|
|
23 | |
1 | #include "../config.h" |
24 | #include "../config.h" |
2 | #include "rxvt.h" |
25 | #include "rxvt.h" |
3 | |
26 | |
4 | #ifdef KEYSYM_RESOURCE |
27 | #ifdef KEYSYM_RESOURCE |
5 | |
28 | |
… | |
… | |
45 | //////////////////////////////////////////////////////////////////////////////// |
68 | //////////////////////////////////////////////////////////////////////////////// |
46 | // default keycode translation map and keyevent handlers |
69 | // default keycode translation map and keyevent handlers |
47 | |
70 | |
48 | keysym_t keyboard_manager::stock_keymap[] = { |
71 | keysym_t keyboard_manager::stock_keymap[] = { |
49 | /* examples */ |
72 | /* examples */ |
50 | /* keysym, state, range, handler, str */ |
73 | /* keysym, state, range, type, str */ |
51 | //{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"}, |
74 | //{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"}, |
52 | //{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, |
75 | //{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, |
53 | //{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, |
76 | //{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, |
54 | //{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."}, |
77 | //{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."}, |
55 | //{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."}, |
78 | //{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."}, |
… | |
… | |
115 | } |
138 | } |
116 | |
139 | |
117 | return len; |
140 | return len; |
118 | } |
141 | } |
119 | |
142 | |
120 | //////////////////////////////////////////////////////////////////////////////// |
|
|
121 | // return: #bits of '1' |
|
|
122 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) |
|
|
123 | # define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n__); })) |
|
|
124 | #else |
|
|
125 | static int |
|
|
126 | bitcount (uint16_t n) |
|
|
127 | { |
|
|
128 | int i; |
|
|
129 | |
|
|
130 | for (i = 0; n; ++i, n &= n - 1) |
|
|
131 | ; |
|
|
132 | |
|
|
133 | return i; |
|
|
134 | } |
|
|
135 | #endif |
|
|
136 | |
|
|
137 | // return: priority_of_a - priority_of_b |
143 | // return: priority_of_a - priority_of_b |
138 | static int |
144 | static int |
139 | compare_priority (keysym_t *a, keysym_t *b) |
145 | compare_priority (keysym_t *a, keysym_t *b) |
140 | { |
146 | { |
141 | // (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 |
142 | int ca = bitcount (a->state /* & OtherModMask */); |
148 | int ca = popcount (a->state /* & OtherModMask */); |
143 | int cb = bitcount (b->state /* & OtherModMask */); |
149 | int cb = popcount (b->state /* & OtherModMask */); |
144 | |
150 | |
145 | if (ca != cb) |
151 | if (ca != cb) |
146 | return ca - cb; |
152 | return ca - cb; |
147 | //else if (a->state != b->state) // this behavior is to be disscussed |
153 | //else if (a->state != b->state) // this behavior is to be disscussed |
148 | // return b->state - a->state; |
154 | // return b->state - a->state; |
… | |
… | |
207 | |
213 | |
208 | if (strncmp (translation, "list", 4) == 0 && translation [4]) |
214 | if (strncmp (translation, "list", 4) == 0 && translation [4]) |
209 | { |
215 | { |
210 | char *middle = strchr (translation + 5, translation [4]); |
216 | char *middle = strchr (translation + 5, translation [4]); |
211 | char *suffix = strrchr (translation + 5, translation [4]); |
217 | char *suffix = strrchr (translation + 5, translation [4]); |
212 | |
218 | |
213 | if (suffix && middle && suffix > middle + 1) |
219 | if (suffix && middle && suffix > middle + 1) |
214 | { |
220 | { |
215 | key->type = keysym_t::LIST; |
221 | key->type = keysym_t::LIST; |
216 | key->range = suffix - middle - 1; |
222 | key->range = suffix - middle - 1; |
217 | |
223 | |
218 | strcpy (translation, translation + 4); |
224 | memmove (translation, translation + 4, strlen (translation + 4) + 1); |
219 | } |
225 | } |
220 | else |
226 | else |
221 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
227 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
222 | } |
228 | } |
223 | else if (strncmp (translation, "builtin:", 8) == 0) |
229 | else if (strncmp (translation, "builtin:", 8) == 0) |
… | |
… | |
459 | keyboard_manager::find_keysym (KeySym keysym, unsigned int state) |
465 | keyboard_manager::find_keysym (KeySym keysym, unsigned int state) |
460 | { |
466 | { |
461 | int hashkey = keysym & KEYSYM_HASH_MASK; |
467 | int hashkey = keysym & KEYSYM_HASH_MASK; |
462 | unsigned int index = hash [hashkey]; |
468 | unsigned int index = hash [hashkey]; |
463 | unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 |
469 | unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 |
464 | ? hash [hashkey + 1] |
470 | ? hash [hashkey + 1] |
465 | : keymap.size (); |
471 | : keymap.size (); |
466 | |
472 | |
467 | for (; index < end; ++index) |
473 | for (; index < end; ++index) |
468 | { |
474 | { |
469 | keysym_t *key = keymap [index]; |
475 | keysym_t *key = keymap [index]; |