1 | #include "../config.h" |
1 | #include "../config.h" |
2 | #include "rxvt.h" |
2 | #include "rxvt.h" |
|
|
3 | |
|
|
4 | #ifdef KEYSYM_RESOURCE |
|
|
5 | |
|
|
6 | #include <cstring> |
|
|
7 | |
3 | #include "keyboard.h" |
8 | #include "keyboard.h" |
4 | #include "command.h" |
9 | #include "command.h" |
5 | #include <string.h> |
|
|
6 | #include <X11/X.h> |
|
|
7 | |
|
|
8 | #ifdef KEYSYM_RESOURCE |
|
|
9 | |
10 | |
10 | //////////////////////////////////////////////////////////////////////////////// |
11 | //////////////////////////////////////////////////////////////////////////////// |
11 | // default keycode translation map and keyevent handlers |
12 | // default keycode translation map and keyevent handlers |
12 | |
13 | |
13 | keysym_t keyboard_manager::stock_keymap[] = { |
14 | keysym_t keyboard_manager::stock_keymap[] = { |
14 | /* examples */ |
15 | /* examples */ |
15 | /* keysym, state, range, handler, str */ |
16 | /* keysym, state, range, handler, str */ |
16 | //{XK_ISO_Left_Tab, 0, 1, NORMAL, "\033[Z"}, |
17 | //{XK_ISO_Left_Tab, 0, 1, keysym_t::NORMAL, "\033[Z"}, |
17 | //{ 'a', 0, 26, RANGE_META8, "a" "%c"}, |
18 | //{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, |
18 | //{ 'a', ControlMask, 26, RANGE_META8, "" "%c"}, |
19 | //{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, |
19 | //{ XK_Left, 0, 4, LIST, "DACBZ" "\033[Z"}, |
20 | //{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."}, |
20 | //{ XK_Left, ShiftMask, 4, LIST, "dacbZ" "\033[Z"}, |
21 | //{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."}, |
21 | //{ XK_Left, ControlMask, 4, LIST, "dacbZ" "\033OZ"}, |
22 | //{ XK_Left, ControlMask, 4, keysym_t::LIST, ".\033O.dacb."}, |
22 | //{ XK_Tab, ControlMask, 1, NORMAL, "\033<C-Tab>"}, |
23 | //{ XK_Tab, ControlMask, 1, keysym_t::NORMAL, "\033<C-Tab>"}, |
23 | //{ XK_apostrophe, ControlMask, 1, NORMAL, "\033<C-'>"}, |
24 | //{ XK_apostrophe, ControlMask, 1, keysym_t::NORMAL, "\033<C-'>"}, |
24 | //{ XK_slash, ControlMask, 1, NORMAL, "\033<C-/>"}, |
25 | //{ XK_slash, ControlMask, 1, keysym_t::NORMAL, "\033<C-/>"}, |
25 | //{ XK_semicolon, ControlMask, 1, NORMAL, "\033<C-;>"}, |
26 | //{ XK_semicolon, ControlMask, 1, keysym_t::NORMAL, "\033<C-;>"}, |
26 | //{ XK_grave, ControlMask, 1, NORMAL, "\033<C-`>"}, |
27 | //{ XK_grave, ControlMask, 1, keysym_t::NORMAL, "\033<C-`>"}, |
27 | //{ XK_comma, ControlMask, 1, NORMAL, "\033<C-\054>"}, |
28 | //{ XK_comma, ControlMask, 1, keysym_t::NORMAL, "\033<C-\054>"}, |
28 | //{ XK_Return, ControlMask, 1, NORMAL, "\033<C-Return>"}, |
29 | //{ XK_Return, ControlMask, 1, keysym_t::NORMAL, "\033<C-Return>"}, |
29 | //{ XK_Return, ShiftMask, 1, NORMAL, "\033<S-Return>"}, |
30 | //{ XK_Return, ShiftMask, 1, keysym_t::NORMAL, "\033<S-Return>"}, |
30 | //{ ' ', ShiftMask, 1, NORMAL, "\033<S-Space>"}, |
31 | //{ ' ', ShiftMask, 1, keysym_t::NORMAL, "\033<S-Space>"}, |
31 | //{ '.', ControlMask, 1, NORMAL, "\033<C-.>"}, |
32 | //{ '.', ControlMask, 1, keysym_t::NORMAL, "\033<C-.>"}, |
32 | //{ '0', ControlMask, 10, RANGE, "0" "\033<C-%c>"}, |
33 | //{ '0', ControlMask, 10, keysym_t::RANGE, "0" "\033<C-%c>"}, |
33 | //{ '0', MetaMask|ControlMask, 10, RANGE, "0" "\033<M-C-%c>"}, |
34 | //{ '0', MetaMask|ControlMask, 10, keysym_t::RANGE, "0" "\033<M-C-%c>"}, |
34 | //{ 'a', MetaMask|ControlMask, 26, RANGE, "a" "\033<M-C-%c>"}, |
35 | //{ 'a', MetaMask|ControlMask, 26, keysym_t::RANGE, "a" "\033<M-C-%c>"}, |
35 | }; |
36 | }; |
36 | |
37 | |
37 | static void |
38 | static void |
38 | output_string (rxvt_term *rt, const char *str) |
39 | output_string (rxvt_term *rt, const char *str) |
39 | { |
40 | { |
40 | assert (rt && str); |
|
|
41 | |
|
|
42 | if (strncmp (str, "proto:", 6) == 0) |
41 | if (strncmp (str, "command:", 8) == 0) |
43 | rt->cmd_write ((unsigned char *)str + 6, strlen (str) - 6); |
42 | rt->cmd_write ((unsigned char *)str + 8, strlen (str) - 8); |
44 | else |
43 | else |
45 | rt->tt_write ((unsigned char *)str, strlen (str)); |
44 | rt->tt_write ((unsigned char *)str, strlen (str)); |
46 | } |
45 | } |
47 | |
46 | |
48 | static void |
47 | static void |
… | |
… | |
57 | *ch |= 0x80; |
56 | *ch |= 0x80; |
58 | } |
57 | } |
59 | else if (rt->meta_char == C0_ESC) /* escape prefix */ |
58 | else if (rt->meta_char == C0_ESC) /* escape prefix */ |
60 | #endif |
59 | #endif |
61 | { |
60 | { |
62 | const unsigned char |
61 | const unsigned char ch = C0_ESC; |
63 | ch = C0_ESC; |
|
|
64 | rt->tt_write (&ch, 1); |
62 | rt->tt_write (&ch, 1); |
65 | } |
63 | } |
66 | } |
64 | } |
67 | |
65 | |
68 | rt->tt_write ((unsigned char *) buf, buflen); |
66 | rt->tt_write ((unsigned char *) buf, buflen); |
69 | } |
67 | } |
70 | |
68 | |
71 | static int |
69 | static int |
72 | format_keyrange_string (const char *str, int keysym_offset, char *buf, int bufsize) |
70 | format_keyrange_string (const char *str, int keysym_offset, char *buf, int bufsize) |
73 | { |
71 | { |
74 | int len = snprintf (buf, bufsize, str + 1, keysym_offset + str [0]); |
72 | size_t len = snprintf (buf, bufsize, str + 1, keysym_offset + str [0]); |
75 | |
73 | |
76 | if (len >= bufsize) |
74 | if (len >= (size_t)bufsize) |
77 | { |
|
|
78 | fprintf (stderr, "buffer overflowed!\n"); |
|
|
79 | buf[bufsize - 1] = '\0'; |
|
|
80 | } |
75 | { |
81 | else if (len < 0) |
76 | rxvt_warn ("format_keyrange_string: formatting failed, ignoring key.\n"); |
82 | { |
77 | *buf = 0; |
83 | perror ("keyrange_translator()"); |
|
|
84 | } |
78 | } |
85 | |
79 | |
86 | return len; |
80 | return len; |
87 | } |
81 | } |
88 | |
82 | |
89 | //////////////////////////////////////////////////////////////////////////////// |
83 | //////////////////////////////////////////////////////////////////////////////// |
90 | // return: #bits of '1' |
84 | // return: #bits of '1' |
|
|
85 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) |
|
|
86 | # define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n); })) |
|
|
87 | #else |
91 | static int |
88 | static int |
92 | bitcount (unsigned int n) |
89 | bitcount (uint16_t n) |
93 | { |
90 | { |
94 | int i; |
91 | int i; |
95 | |
92 | |
96 | for (i = 0; n; ++i, n &= (n - 1)) |
93 | for (i = 0; n; ++i, n &= n - 1) |
97 | ; |
94 | ; |
98 | |
95 | |
99 | return i; |
96 | return i; |
100 | } |
97 | } |
|
|
98 | #endif |
101 | |
99 | |
102 | // return: priority_of_a - priority_of_b |
100 | // return: priority_of_a - priority_of_b |
103 | static int |
101 | static int |
104 | compare_priority (keysym_t *a, keysym_t *b) |
102 | compare_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) |
… | |
… | |
119 | |
115 | |
120 | //////////////////////////////////////////////////////////////////////////////// |
116 | //////////////////////////////////////////////////////////////////////////////// |
121 | keyboard_manager::keyboard_manager () |
117 | keyboard_manager::keyboard_manager () |
122 | { |
118 | { |
123 | keymap.reserve (256); |
119 | keymap.reserve (256); |
124 | hash[0] = 1; // hash[0] != 0 indicates uninitialized data |
120 | hash [0] = 1; // hash[0] != 0 indicates uninitialized data |
125 | } |
121 | } |
126 | |
122 | |
127 | keyboard_manager::~keyboard_manager () |
123 | keyboard_manager::~keyboard_manager () |
128 | { |
124 | { |
129 | clear (); |
125 | clear (); |
… | |
… | |
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. |
159 | void |
155 | void |
160 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) |
156 | keyboard_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); |
166 | const char *translation = rxvt_wcstoutf8 (wc); |
160 | const char *translation = rxvt_wcstoutf8 (wc); |
167 | free (wc); |
161 | free (wc); |
168 | |
162 | |
… | |
… | |
185 | key->range = suffix - middle - 1; |
179 | key->range = suffix - middle - 1; |
186 | |
180 | |
187 | strcpy (translation, translation + 4); |
181 | strcpy (translation, translation + 4); |
188 | } |
182 | } |
189 | else |
183 | else |
190 | { |
|
|
191 | key->range = 1; |
|
|
192 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
184 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
193 | } |
185 | } |
194 | } |
|
|
195 | else |
|
|
196 | |
186 | |
197 | user_keymap.push_back (key); |
187 | user_keymap.push_back (key); |
198 | user_translations.push_back (translation); |
188 | user_translations.push_back (translation); |
199 | register_keymap (key); |
189 | register_keymap (key); |
200 | } |
190 | } |
… | |
… | |
207 | } |
197 | } |
208 | |
198 | |
209 | void |
199 | void |
210 | keyboard_manager::register_keymap (keysym_t *key) |
200 | keyboard_manager::register_keymap (keysym_t *key) |
211 | { |
201 | { |
212 | assert (key); |
|
|
213 | assert (key->range >= 1); |
|
|
214 | |
|
|
215 | if (keymap.size () == keymap.capacity ()) |
202 | if (keymap.size () == keymap.capacity ()) |
216 | keymap.reserve (keymap.size () * 2); |
203 | keymap.reserve (keymap.size () * 2); |
217 | |
204 | |
218 | keymap.push_back (key); |
205 | keymap.push_back (key); |
219 | hash[0] = 3; |
206 | hash[0] = 3; |
… | |
… | |
236 | bool |
223 | bool |
237 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
224 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
238 | { |
225 | { |
239 | assert (hash[0] == 0 && "register_done() need to be called"); |
226 | assert (hash[0] == 0 && "register_done() need to be called"); |
240 | |
227 | |
241 | if (state & term->ModMetaMask) |
228 | if (state & term->ModMetaMask) state |= MetaMask; |
242 | state |= MetaMask; |
|
|
243 | |
|
|
244 | if (state & term->ModNumLockMask) |
229 | if (state & term->ModNumLockMask) state |= NumLockMask; |
245 | state |= NumLockMask; |
230 | if (state & term->ModLevel3Mask) state |= Level3Mask; |
246 | |
231 | |
247 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
232 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
248 | state |= AppKeypadMask; |
233 | state |= AppKeypadMask; |
249 | |
234 | |
250 | int index = find_keysym (keysym, state); |
235 | int index = find_keysym (keysym, state); |
251 | |
236 | |
252 | if (index >= 0) |
237 | if (index >= 0) |
253 | { |
238 | { |
254 | assert (term && keymap [index]); |
|
|
255 | const keysym_t &key = *keymap [index]; |
239 | const keysym_t &key = *keymap [index]; |
256 | |
240 | |
257 | int keysym_offset = keysym - key.keysym; |
241 | int keysym_offset = keysym - key.keysym; |
258 | |
242 | |
259 | wchar_t *wc = rxvt_utf8towcs (key.str); |
243 | wchar_t *wc = rxvt_utf8towcs (key.str); |
260 | char *str = rxvt_wcstombs (wc); |
244 | char *str = rxvt_wcstombs (wc); |
261 | // TODO: do translations, unescaping etc, here (allow \u escape etc.) |
245 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
262 | free (wc); |
246 | free (wc); |
263 | |
247 | |
264 | switch (key.type) |
248 | switch (key.type) |
265 | { |
249 | { |
266 | case keysym_t::NORMAL: |
250 | case keysym_t::NORMAL: |
… | |
… | |
309 | free (str); |
293 | free (str); |
310 | |
294 | |
311 | return true; |
295 | return true; |
312 | } |
296 | } |
313 | else |
297 | else |
314 | { |
|
|
315 | // fprintf(stderr,"[%x:%x]",state,keysym); |
|
|
316 | return false; |
298 | return false; |
317 | } |
|
|
318 | } |
299 | } |
319 | |
300 | |
320 | // purge duplicate keymap entries |
301 | // purge duplicate keymap entries |
321 | void keyboard_manager::purge_duplicate_keymap () |
302 | void keyboard_manager::purge_duplicate_keymap () |
322 | { |
303 | { |
323 | for (unsigned int i = 0; i < keymap.size (); ++i) |
304 | for (unsigned int i = 0; i < keymap.size (); ++i) |
324 | { |
305 | { |
325 | for (unsigned int j = 0; j < i; ++j) |
306 | for (unsigned int j = 0; j < i; ++j) |
326 | { |
307 | { |
327 | if (keymap[i] == keymap[j]) |
308 | if (keymap [i] == keymap [j]) |
328 | { |
309 | { |
329 | while (keymap[i] == keymap.back ()) |
310 | while (keymap [i] == keymap.back ()) |
330 | keymap.pop_back (); |
311 | keymap.pop_back (); |
331 | |
312 | |
332 | if (i < keymap.size ()) |
313 | if (i < keymap.size ()) |
333 | { |
314 | { |
334 | keymap[i] = keymap.back (); |
315 | keymap[i] = keymap.back (); |
335 | keymap.pop_back (); |
316 | keymap.pop_back (); |
336 | } |
317 | } |
|
|
318 | |
337 | break; |
319 | break; |
338 | } |
320 | } |
339 | } |
321 | } |
340 | } |
322 | } |
341 | } |
323 | } |
… | |
… | |
349 | uint16_t hash_budget_counter[KEYSYM_HASH_BUDGETS]; // #elements in each budget |
331 | uint16_t hash_budget_counter[KEYSYM_HASH_BUDGETS]; // #elements in each budget |
350 | |
332 | |
351 | memset (hash_budget_size, 0, sizeof (hash_budget_size)); |
333 | memset (hash_budget_size, 0, sizeof (hash_budget_size)); |
352 | memset (hash_budget_counter, 0, sizeof (hash_budget_counter)); |
334 | memset (hash_budget_counter, 0, sizeof (hash_budget_counter)); |
353 | |
335 | |
354 | // count keysyms for corresponding hash budgets |
336 | // determine hash bucket size |
355 | for (i = 0; i < keymap.size (); ++i) |
337 | for (i = 0; i < keymap.size (); ++i) |
|
|
338 | for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j >= 0; --j) |
356 | { |
339 | { |
357 | assert (keymap[i]); |
|
|
358 | hashkey = (keymap[i]->keysym & KEYSYM_HASH_MASK); |
340 | hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; |
359 | ++hash_budget_size[hashkey]; |
341 | ++hash_budget_size [hashkey]; |
360 | } |
|
|
361 | |
|
|
362 | // keysym A with range>1 is counted one more time for |
|
|
363 | // every keysym B lies in its range |
|
|
364 | for (i = 0; i < keymap.size (); ++i) |
|
|
365 | { |
|
|
366 | if (keymap[i]->range > 1) |
|
|
367 | { |
|
|
368 | for (int j = min (keymap[i]->range, KEYSYM_HASH_BUDGETS) - 1; j > 0; --j) |
|
|
369 | { |
|
|
370 | hashkey = ((keymap[i]->keysym + j) & KEYSYM_HASH_MASK); |
|
|
371 | if (hash_budget_size[hashkey]) |
|
|
372 | ++hash_budget_size[hashkey]; |
|
|
373 | } |
|
|
374 | } |
342 | } |
375 | } |
|
|
376 | |
343 | |
377 | // now we know the size of each budget |
344 | // now we know the size of each budget |
378 | // compute the index of each budget |
345 | // compute the index of each budget |
379 | hash[0] = 0; |
346 | hash [0] = 0; |
380 | for (index = 0, i = 1; i < KEYSYM_HASH_BUDGETS; ++i) |
347 | for (index = 0, i = 1; i < KEYSYM_HASH_BUDGETS; ++i) |
381 | { |
348 | { |
382 | index += hash_budget_size[i - 1]; |
349 | index += hash_budget_size [i - 1]; |
383 | hash[i] = (hash_budget_size[i] ? index : hash[i - 1]); |
350 | hash [i] = index; |
384 | } |
351 | } |
385 | |
352 | |
386 | // and allocate just enough space |
353 | // and allocate just enough space |
387 | //sorted_keymap.reserve (hash[i - 1] + hash_budget_size[i - 1]); |
|
|
388 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_budget_size[i - 1], 0); |
354 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_budget_size [i - 1], 0); |
389 | |
355 | |
390 | // fill in sorted_keymap |
356 | // fill in sorted_keymap |
391 | // it is sorted in each budget |
357 | // it is sorted in each budget |
392 | for (i = 0; i < keymap.size (); ++i) |
358 | for (i = 0; i < keymap.size (); ++i) |
393 | { |
|
|
394 | for (int j = min (keymap[i]->range, KEYSYM_HASH_BUDGETS) - 1; j >= 0; --j) |
359 | for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j >= 0; --j) |
395 | { |
360 | { |
396 | hashkey = ((keymap[i]->keysym + j) & KEYSYM_HASH_MASK); |
361 | hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; |
397 | |
362 | |
398 | if (hash_budget_size[hashkey]) |
|
|
399 | { |
|
|
400 | index = hash[hashkey] + hash_budget_counter[hashkey]; |
363 | index = hash [hashkey] + hash_budget_counter [hashkey]; |
401 | |
364 | |
402 | while (index > hash[hashkey] |
365 | while (index > hash [hashkey] |
403 | && compare_priority (keymap[i], sorted_keymap[index - 1]) > 0) |
366 | && compare_priority (keymap [i], sorted_keymap [index - 1]) > 0) |
404 | { |
367 | { |
405 | sorted_keymap[index] = sorted_keymap[index - 1]; |
368 | sorted_keymap [index] = sorted_keymap [index - 1]; |
406 | --index; |
369 | --index; |
407 | } |
370 | } |
408 | |
371 | |
409 | sorted_keymap[index] = keymap[i]; |
372 | sorted_keymap [index] = keymap [i]; |
410 | ++hash_budget_counter[hashkey]; |
373 | ++hash_budget_counter [hashkey]; |
411 | } |
|
|
412 | } |
374 | } |
413 | } |
|
|
414 | |
375 | |
415 | keymap.swap (sorted_keymap); |
376 | keymap.swap (sorted_keymap); |
416 | |
377 | |
417 | #if defined (DEBUG_STRICT) || defined (DEBUG_KEYBOARD) |
378 | #if defined (DEBUG_STRICT) || defined (DEBUG_KEYBOARD) |
418 | // check for invariants |
379 | // check for invariants |
419 | for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i) |
380 | for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i) |
420 | { |
381 | { |
421 | index = hash[i]; |
382 | index = hash[i]; |
422 | for (int j = 0; j < hash_budget_size[i]; ++j) |
383 | for (int j = 0; j < hash_budget_size [i]; ++j) |
423 | { |
384 | { |
424 | if (keymap[index + j]->range == 1) |
385 | if (keymap [index + j]->range == 1) |
425 | assert (i == (keymap[index + j]->keysym & KEYSYM_HASH_MASK)); |
386 | assert (i == (keymap [index + j]->keysym & KEYSYM_HASH_MASK)); |
426 | |
387 | |
427 | if (j) |
388 | if (j) |
428 | assert (compare_priority (keymap[index + j - 1], |
389 | assert (compare_priority (keymap [index + j - 1], |
429 | keymap[index + j]) >= 0); |
390 | keymap [index + j]) >= 0); |
430 | } |
391 | } |
431 | } |
392 | } |
432 | |
393 | |
433 | // this should be able to detect most possible bugs |
394 | // this should be able to detect most possible bugs |
434 | for (i = 0; i < sorted_keymap.size (); ++i) |
395 | for (i = 0; i < sorted_keymap.size (); ++i) |
435 | { |
396 | { |
436 | keysym_t *a = sorted_keymap[i]; |
397 | keysym_t *a = sorted_keymap[i]; |
437 | for (int j = 0; j < a->range; ++j) |
398 | for (int j = 0; j < a->range; ++j) |
438 | { |
399 | { |
439 | int index = find_keysym (a->keysym + j, a->state & OtherModMask); |
400 | int index = find_keysym (a->keysym + j, a->state); |
|
|
401 | |
440 | assert (index >= 0); |
402 | assert (index >= 0); |
441 | keysym_t *b = keymap[index]; |
403 | keysym_t *b = keymap [index]; |
442 | assert (i == (signed) index || // the normally expected result |
404 | assert (i == (signed) index || // the normally expected result |
443 | (a->keysym + j) >= b->keysym && (a->keysym + j) <= (b->keysym + b->range) && compare_priority (a, b) <= 0); // is effectively the same |
405 | (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 |
444 | } |
406 | } |
445 | } |
407 | } |
446 | #endif |
408 | #endif |
447 | } |
409 | } |
448 | |
410 | |
449 | int |
411 | int |
450 | keyboard_manager::find_keysym (KeySym keysym, unsigned int state) |
412 | keyboard_manager::find_keysym (KeySym keysym, unsigned int state) |
451 | { |
413 | { |
452 | int hashkey = keysym & KEYSYM_HASH_MASK; |
414 | int hashkey = keysym & KEYSYM_HASH_MASK; |
453 | unsigned int index = hash [hashkey]; |
415 | unsigned int index = hash [hashkey]; |
|
|
416 | unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 |
|
|
417 | ? hash [hashkey + 1] |
|
|
418 | : keymap.size (); |
454 | |
419 | |
455 | for (; index < keymap.size (); ++index) |
420 | for (; index < end; ++index) |
456 | { |
421 | { |
457 | keysym_t *key = keymap[index]; |
422 | keysym_t *key = keymap [index]; |
458 | assert (key); |
|
|
459 | |
423 | |
460 | if (key->keysym <= keysym && key->keysym + key->range > keysym |
424 | if (key->keysym <= keysym && keysym < key->keysym + key->range |
461 | // match only the specified bits in state and ignore others |
425 | // match only the specified bits in state and ignore others |
462 | && (key->state & OtherModMask) == (key->state & state)) |
426 | && (key->state & state) == key->state) |
463 | return index; |
427 | return index; |
464 | else if (key->keysym > keysym && key->range == 1) |
|
|
465 | return -1; |
|
|
466 | } |
428 | } |
467 | |
429 | |
468 | return -1; |
430 | return -1; |
469 | } |
431 | } |
470 | |
432 | |