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.14 by root, Sat Mar 12 23:35:14 2005 UTC vs.
Revision 1.22 by root, Mon Jan 9 22:41:41 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 *
45// default keycode translation map and keyevent handlers 46// default keycode translation map and keyevent handlers
46 47
47keysym_t keyboard_manager::stock_keymap[] = { 48keysym_t keyboard_manager::stock_keymap[] = {
48 /* examples */ 49 /* examples */
49 /* keysym, state, range, handler, str */ 50 /* keysym, state, range, handler, str */
50//{XK_ISO_Left_Tab, 0, 1, keysym_t::NORMAL, "\033[Z"}, 51//{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"},
51//{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, 52//{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"},
52//{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, 53//{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"},
53//{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."}, 54//{ XK_Left, 0, 4, keysym_t::LIST, ".\033[.DACB."},
54//{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."}, 55//{ XK_Left, ShiftMask, 4, keysym_t::LIST, ".\033[.dacb."},
55//{ XK_Left, ControlMask, 4, keysym_t::LIST, ".\033O.dacb."}, 56//{ XK_Left, ControlMask, 4, keysym_t::LIST, ".\033O.dacb."},
56//{ XK_Tab, ControlMask, 1, keysym_t::NORMAL, "\033<C-Tab>"}, 57//{ XK_Tab, ControlMask, 1, keysym_t::STRING, "\033<C-Tab>"},
57//{ XK_apostrophe, ControlMask, 1, keysym_t::NORMAL, "\033<C-'>"}, 58//{ XK_apostrophe, ControlMask, 1, keysym_t::STRING, "\033<C-'>"},
58//{ XK_slash, ControlMask, 1, keysym_t::NORMAL, "\033<C-/>"}, 59//{ XK_slash, ControlMask, 1, keysym_t::STRING, "\033<C-/>"},
59//{ XK_semicolon, ControlMask, 1, keysym_t::NORMAL, "\033<C-;>"}, 60//{ XK_semicolon, ControlMask, 1, keysym_t::STRING, "\033<C-;>"},
60//{ XK_grave, ControlMask, 1, keysym_t::NORMAL, "\033<C-`>"}, 61//{ XK_grave, ControlMask, 1, keysym_t::STRING, "\033<C-`>"},
61//{ XK_comma, ControlMask, 1, keysym_t::NORMAL, "\033<C-\054>"}, 62//{ XK_comma, ControlMask, 1, keysym_t::STRING, "\033<C-\054>"},
62//{ XK_Return, ControlMask, 1, keysym_t::NORMAL, "\033<C-Return>"}, 63//{ XK_Return, ControlMask, 1, keysym_t::STRING, "\033<C-Return>"},
63//{ XK_Return, ShiftMask, 1, keysym_t::NORMAL, "\033<S-Return>"}, 64//{ XK_Return, ShiftMask, 1, keysym_t::STRING, "\033<S-Return>"},
64//{ ' ', ShiftMask, 1, keysym_t::NORMAL, "\033<S-Space>"}, 65//{ ' ', ShiftMask, 1, keysym_t::STRING, "\033<S-Space>"},
65//{ '.', ControlMask, 1, keysym_t::NORMAL, "\033<C-.>"}, 66//{ '.', ControlMask, 1, keysym_t::STRING, "\033<C-.>"},
66//{ '0', ControlMask, 10, keysym_t::RANGE, "0" "\033<C-%c>"}, 67//{ '0', ControlMask, 10, keysym_t::RANGE, "0" "\033<C-%c>"},
67//{ '0', MetaMask|ControlMask, 10, keysym_t::RANGE, "0" "\033<M-C-%c>"}, 68//{ '0', MetaMask|ControlMask, 10, keysym_t::RANGE, "0" "\033<M-C-%c>"},
68//{ 'a', MetaMask|ControlMask, 26, keysym_t::RANGE, "a" "\033<M-C-%c>"}, 69//{ 'a', MetaMask|ControlMask, 26, keysym_t::RANGE, "a" "\033<M-C-%c>"},
69}; 70};
70#endif 71#endif
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 HOOK_INVOKE((rt, HOOK_KEYBOARD_COMMAND, DT_STR, 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;
200 key->state = state; 203 key->state = state;
201 key->range = 1; 204 key->range = 1;
202 key->str = translation; 205 key->str = translation;
203 key->type = keysym_t::NORMAL; 206 key->type = keysym_t::STRING;
204 207
205 if (strncmp (translation, "list", 4) == 0 && translation [4]) 208 if (strncmp (translation, "list", 4) == 0 && translation [4])
206 { 209 {
207 char *middle = strchr (translation + 5, translation [4]); 210 char *middle = strchr (translation + 5, translation [4]);
208 char *suffix = strrchr (translation + 5, translation [4]); 211 char *suffix = strrchr (translation + 5, translation [4]);
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::STRING:
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{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines