… | |
… | |
3 | |
3 | |
4 | #ifdef KEYSYM_RESOURCE |
4 | #ifdef KEYSYM_RESOURCE |
5 | |
5 | |
6 | #include <cstring> |
6 | #include <cstring> |
7 | |
7 | |
|
|
8 | #include "rxvtperl.h" |
8 | #include "keyboard.h" |
9 | #include "keyboard.h" |
9 | #include "command.h" |
10 | #include "command.h" |
10 | |
11 | |
11 | /* an intro to the data structure: |
12 | /* an intro to the data structure: |
12 | * |
13 | * |
… | |
… | |
72 | static void |
73 | static void |
73 | output_string (rxvt_term *rt, const char *str) |
74 | output_string (rxvt_term *rt, const char *str) |
74 | { |
75 | { |
75 | if (strncmp (str, "command:", 8) == 0) |
76 | if (strncmp (str, "command:", 8) == 0) |
76 | rt->cmd_write ((unsigned char *)str + 8, strlen (str) - 8); |
77 | rt->cmd_write ((unsigned char *)str + 8, strlen (str) - 8); |
|
|
78 | else if (strncmp (str, "perl:", 5) == 0) |
|
|
79 | PERL_INVOKE((rt, HOOK_KEYBOARD_COMMAND, DT_STRING, str + 5, DT_END)); |
77 | else |
80 | else |
78 | rt->tt_write ((unsigned char *)str, strlen (str)); |
81 | rt->tt_write ((unsigned char *)str, strlen (str)); |
79 | } |
82 | } |
80 | |
83 | |
81 | static void |
84 | static void |
… | |
… | |
115 | } |
118 | } |
116 | |
119 | |
117 | //////////////////////////////////////////////////////////////////////////////// |
120 | //////////////////////////////////////////////////////////////////////////////// |
118 | // return: #bits of '1' |
121 | // return: #bits of '1' |
119 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) |
122 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) |
120 | # define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n); })) |
123 | # define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n__); })) |
121 | #else |
124 | #else |
122 | static int |
125 | static int |
123 | bitcount (uint16_t n) |
126 | bitcount (uint16_t n) |
124 | { |
127 | { |
125 | int i; |
128 | int i; |
… | |
… | |
215 | strcpy (translation, translation + 4); |
218 | strcpy (translation, translation + 4); |
216 | } |
219 | } |
217 | else |
220 | else |
218 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
221 | rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); |
219 | } |
222 | } |
|
|
223 | else if (strncmp (translation, "builtin:", 8) == 0) |
|
|
224 | key->type = keysym_t::BUILTIN; |
220 | |
225 | |
221 | user_keymap.push_back (key); |
226 | user_keymap.push_back (key); |
222 | user_translations.push_back (translation); |
227 | user_translations.push_back (translation); |
223 | register_keymap (key); |
228 | register_keymap (key); |
224 | } |
229 | } |
… | |
… | |
260 | bool |
265 | bool |
261 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
266 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
262 | { |
267 | { |
263 | assert (hash[0] == 0 && "register_done() need to be called"); |
268 | assert (hash[0] == 0 && "register_done() need to be called"); |
264 | |
269 | |
|
|
270 | state &= OtherModMask; // mask out uninteresting modifiers |
|
|
271 | |
265 | if (state & term->ModMetaMask) state |= MetaMask; |
272 | if (state & term->ModMetaMask) state |= MetaMask; |
266 | if (state & term->ModNumLockMask) state |= NumLockMask; |
273 | if (state & term->ModNumLockMask) state |= NumLockMask; |
267 | if (state & term->ModLevel3Mask) state |= Level3Mask; |
274 | if (state & term->ModLevel3Mask) state |= Level3Mask; |
268 | |
275 | |
269 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
276 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
… | |
… | |
273 | |
280 | |
274 | if (index >= 0) |
281 | if (index >= 0) |
275 | { |
282 | { |
276 | const keysym_t &key = *keymap [index]; |
283 | const keysym_t &key = *keymap [index]; |
277 | |
284 | |
|
|
285 | if (key.type != keysym_t::BUILTIN) |
|
|
286 | { |
278 | int keysym_offset = keysym - key.keysym; |
287 | int keysym_offset = keysym - key.keysym; |
279 | |
288 | |
280 | wchar_t *wc = rxvt_utf8towcs (key.str); |
289 | wchar_t *wc = rxvt_utf8towcs (key.str); |
281 | char *str = rxvt_wcstombs (wc); |
290 | char *str = rxvt_wcstombs (wc); |
282 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
291 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
283 | free (wc); |
292 | free (wc); |
284 | |
293 | |
285 | switch (key.type) |
294 | switch (key.type) |
286 | { |
|
|
287 | case keysym_t::NORMAL: |
|
|
288 | output_string (term, str); |
|
|
289 | break; |
|
|
290 | |
|
|
291 | case keysym_t::RANGE: |
|
|
292 | { |
295 | { |
|
|
296 | case keysym_t::NORMAL: |
|
|
297 | output_string (term, str); |
|
|
298 | break; |
|
|
299 | |
|
|
300 | case keysym_t::RANGE: |
|
|
301 | { |
293 | char buf[STRING_MAX]; |
302 | char buf[STRING_MAX]; |
294 | |
303 | |
295 | if (format_keyrange_string (str, keysym_offset, buf, sizeof (buf)) > 0) |
304 | if (format_keyrange_string (str, keysym_offset, buf, sizeof (buf)) > 0) |
|
|
305 | output_string (term, buf); |
|
|
306 | } |
|
|
307 | break; |
|
|
308 | |
|
|
309 | case keysym_t::RANGE_META8: |
|
|
310 | { |
|
|
311 | int len; |
|
|
312 | char buf[STRING_MAX]; |
|
|
313 | |
|
|
314 | len = format_keyrange_string (str, keysym_offset, buf, sizeof (buf)); |
|
|
315 | if (len > 0) |
|
|
316 | output_string_meta8 (term, state, buf, len); |
|
|
317 | } |
|
|
318 | break; |
|
|
319 | |
|
|
320 | case keysym_t::LIST: |
|
|
321 | { |
|
|
322 | char buf[STRING_MAX]; |
|
|
323 | |
|
|
324 | char *prefix, *middle, *suffix; |
|
|
325 | |
|
|
326 | prefix = str; |
|
|
327 | middle = strchr (prefix + 1, *prefix); |
|
|
328 | suffix = strrchr (middle + 1, *prefix); |
|
|
329 | |
|
|
330 | memcpy (buf, prefix + 1, middle - prefix - 1); |
|
|
331 | buf [middle - prefix - 1] = middle [keysym_offset + 1]; |
|
|
332 | strcpy (buf + (middle - prefix), suffix + 1); |
|
|
333 | |
296 | output_string (term, buf); |
334 | output_string (term, buf); |
|
|
335 | } |
|
|
336 | break; |
297 | } |
337 | } |
298 | break; |
|
|
299 | |
338 | |
300 | case keysym_t::RANGE_META8: |
|
|
301 | { |
|
|
302 | int len; |
|
|
303 | char buf[STRING_MAX]; |
|
|
304 | |
|
|
305 | len = format_keyrange_string (str, keysym_offset, buf, sizeof (buf)); |
|
|
306 | if (len > 0) |
|
|
307 | output_string_meta8 (term, state, buf, len); |
|
|
308 | } |
|
|
309 | break; |
|
|
310 | |
|
|
311 | case keysym_t::LIST: |
|
|
312 | { |
|
|
313 | char buf[STRING_MAX]; |
|
|
314 | |
|
|
315 | char *prefix, *middle, *suffix; |
|
|
316 | |
|
|
317 | prefix = str; |
|
|
318 | middle = strchr (prefix + 1, *prefix); |
|
|
319 | suffix = strrchr (middle + 1, *prefix); |
|
|
320 | |
|
|
321 | memcpy (buf, prefix + 1, middle - prefix - 1); |
|
|
322 | buf [middle - prefix - 1] = middle [keysym_offset + 1]; |
|
|
323 | strcpy (buf + (middle - prefix), suffix + 1); |
|
|
324 | |
|
|
325 | output_string (term, buf); |
|
|
326 | } |
|
|
327 | break; |
|
|
328 | } |
|
|
329 | |
|
|
330 | free (str); |
339 | free (str); |
331 | |
340 | |
332 | return true; |
341 | return true; |
|
|
342 | } |
333 | } |
343 | } |
334 | else |
344 | |
335 | return false; |
345 | return false; |
336 | } |
346 | } |
337 | |
347 | |
338 | // purge duplicate keymap entries |
348 | // purge duplicate keymap entries |
339 | void keyboard_manager::purge_duplicate_keymap () |
349 | void keyboard_manager::purge_duplicate_keymap () |
340 | { |
350 | { |