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.16 by root, Fri Apr 22 02:09:39 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]);
288 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 291 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
289 free (wc); 292 free (wc);
290 293
291 switch (key.type) 294 switch (key.type)
292 { 295 {
293 case keysym_t::NORMAL: 296 case keysym_t::STRING:
294 output_string (term, str); 297 output_string (term, str);
295 break; 298 break;
296 299
297 case keysym_t::RANGE: 300 case keysym_t::RANGE:
298 { 301 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines