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.15 by root, Sun Apr 17 22:36:13 2005 UTC vs.
Revision 1.19 by root, Wed Jan 4 04:42:45 2006 UTC

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 *
71 72
72static void 73static void
73output_string (rxvt_term *rt, const char *str) 74output_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 (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 (str, strlen (str));
79} 82}
80 83
81static void 84static void
82output_string_meta8 (rxvt_term *rt, unsigned int state, char *buf, int buflen) 85output_string_meta8 (rxvt_term *rt, unsigned int state, char *buf, int buflen)
83{ 86{
90 *ch |= 0x80; 93 *ch |= 0x80;
91 } 94 }
92 else if (rt->meta_char == C0_ESC) /* escape prefix */ 95 else if (rt->meta_char == C0_ESC) /* escape prefix */
93#endif 96#endif
94 { 97 {
95 const unsigned char ch = C0_ESC; 98 const char ch = C0_ESC;
96 rt->tt_write (&ch, 1); 99 rt->tt_write (&ch, 1);
97 } 100 }
98 } 101 }
99 102
100 rt->tt_write ((unsigned char *) buf, buflen); 103 rt->tt_write (buf, buflen);
101} 104}
102 105
103static int 106static int
104format_keyrange_string (const char *str, int keysym_offset, char *buf, int bufsize) 107format_keyrange_string (const char *str, int keysym_offset, char *buf, int bufsize)
105{ 108{
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
122static int 125static int
123bitcount (uint16_t n) 126bitcount (uint16_t n)
124{ 127{
125 int i; 128 int i;
189void 192void
190keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) 193keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans)
191{ 194{
192 keysym_t *key = new keysym_t; 195 keysym_t *key = new keysym_t;
193 wchar_t *wc = rxvt_mbstowcs (trans); 196 wchar_t *wc = rxvt_mbstowcs (trans);
194 const char *translation = rxvt_wcstoutf8 (wc); 197 char *translation = rxvt_wcstoutf8 (wc);
195 free (wc); 198 free (wc);
196 199
197 if (key && translation) 200 if (key && translation)
198 { 201 {
199 key->keysym = keysym; 202 key->keysym = keysym;
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 }
275 280
276 if (index >= 0) 281 if (index >= 0)
277 { 282 {
278 const keysym_t &key = *keymap [index]; 283 const keysym_t &key = *keymap [index];
279 284
285 if (key.type != keysym_t::BUILTIN)
286 {
280 int keysym_offset = keysym - key.keysym; 287 int keysym_offset = keysym - key.keysym;
281 288
282 wchar_t *wc = rxvt_utf8towcs (key.str); 289 wchar_t *wc = rxvt_utf8towcs (key.str);
283 char *str = rxvt_wcstombs (wc); 290 char *str = rxvt_wcstombs (wc);
284 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 291 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
285 free (wc); 292 free (wc);
286 293
287 switch (key.type) 294 switch (key.type)
288 {
289 case keysym_t::NORMAL:
290 output_string (term, str);
291 break;
292
293 case keysym_t::RANGE:
294 { 295 {
296 case keysym_t::NORMAL:
297 output_string (term, str);
298 break;
299
300 case keysym_t::RANGE:
301 {
295 char buf[STRING_MAX]; 302 char buf[STRING_MAX];
296 303
297 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
298 output_string (term, buf); 334 output_string (term, buf);
335 }
336 break;
299 } 337 }
300 break;
301 338
302 case keysym_t::RANGE_META8:
303 {
304 int len;
305 char buf[STRING_MAX];
306
307 len = format_keyrange_string (str, keysym_offset, buf, sizeof (buf));
308 if (len > 0)
309 output_string_meta8 (term, state, buf, len);
310 }
311 break;
312
313 case keysym_t::LIST:
314 {
315 char buf[STRING_MAX];
316
317 char *prefix, *middle, *suffix;
318
319 prefix = str;
320 middle = strchr (prefix + 1, *prefix);
321 suffix = strrchr (middle + 1, *prefix);
322
323 memcpy (buf, prefix + 1, middle - prefix - 1);
324 buf [middle - prefix - 1] = middle [keysym_offset + 1];
325 strcpy (buf + (middle - prefix), suffix + 1);
326
327 output_string (term, buf);
328 }
329 break;
330 }
331
332 free (str); 339 free (str);
333 340
334 return true; 341 return true;
342 }
335 } 343 }
336 else 344
337 return false; 345 return false;
338} 346}
339 347
340// purge duplicate keymap entries 348// purge duplicate keymap entries
341void keyboard_manager::purge_duplicate_keymap () 349void keyboard_manager::purge_duplicate_keymap ()
342{ 350{
459 for (; index < end; ++index) 467 for (; index < end; ++index)
460 { 468 {
461 keysym_t *key = keymap [index]; 469 keysym_t *key = keymap [index];
462 470
463 if (key->keysym <= keysym && keysym < key->keysym + key->range 471 if (key->keysym <= keysym && keysym < key->keysym + key->range
464#if 0 // disabled because the custom ekymap does not know the builtin keymap
465 // match only the specified bits in state and ignore others 472 // match only the specified bits in state and ignore others
466 && (key->state & state) == key->state 473 && (key->state & state) == key->state)
467#else // re-enable this part once the builtin keymap is handled here, too
468 && key->state == state
469#endif
470 )
471 return index; 474 return index;
472 } 475 }
473 476
474 return -1; 477 return -1;
475} 478}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines