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.12 by root, Sat Feb 12 18:55:04 2005 UTC vs.
Revision 1.17 by root, Mon Nov 28 19:35:04 2005 UTC

5 5
6#include <cstring> 6#include <cstring>
7 7
8#include "keyboard.h" 8#include "keyboard.h"
9#include "command.h" 9#include "command.h"
10
11/* an intro to the data structure:
12 *
13 * vector keymap[] is grouped.
14 *
15 * inside each group, elements are sorted by the criteria given by compare_priority().
16 * the lookup of keysym is done in two steps:
17 * 1) locate the group corresponds to the keysym;
18 * 2) do a linear search inside the group.
19 *
20 * array hash[] effectively defines a map from a keysym to a group in keymap[].
21 *
22 * each group has its address(the index of first group element in keymap[]),
23 * which is computed and stored in hash[].
24 * hash[] stores the addresses in the form of:
25 * index: 0 I1 I2 I3 In
26 * value: 0...0, A1...A1, A2...A2, A3...A3, ..., An...An
27 * where
28 * A1 = 0;
29 * Ai+1 = N1 + N2 + ... + Ni.
30 * it is computed from hash_budget_size[]:
31 * index: 0 I1 I2 I3 In
32 * value: 0...0, N1, 0...0, N2, 0...0, N3, ..., Nn, 0...0
33 * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the compution of hash[])
34 * or we can say
35 * hash_budget_size[Ii] = Ni; hash_budget_size[elsewhere] = 0,
36 * where
37 * set {I1, I2, ..., In} = { hashkey of keymap[0]->keysym, ..., keymap[keymap.size-1]->keysym }
38 * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK
39 * n(the number of groups) = the number of non-zero member of hash_budget_size[];
40 * Ni(the size of group i) = hash_budget_size[Ii].
41 */
10 42
11#if STOCK_KEYMAP 43#if STOCK_KEYMAP
12//////////////////////////////////////////////////////////////////////////////// 44////////////////////////////////////////////////////////////////////////////////
13// default keycode translation map and keyevent handlers 45// default keycode translation map and keyevent handlers
14 46
83} 115}
84 116
85//////////////////////////////////////////////////////////////////////////////// 117////////////////////////////////////////////////////////////////////////////////
86// return: #bits of '1' 118// return: #bits of '1'
87#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) 119#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
88# define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n); })) 120# define bitcount(n) (__extension__ ({ uint32_t n__ = (n); __builtin_popcount (n__); }))
89#else 121#else
90static int 122static int
91bitcount (uint16_t n) 123bitcount (uint16_t n)
92{ 124{
93 int i; 125 int i;
183 strcpy (translation, translation + 4); 215 strcpy (translation, translation + 4);
184 } 216 }
185 else 217 else
186 rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); 218 rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation);
187 } 219 }
220 else if (strncmp (translation, "builtin:", 8) == 0)
221 key->type = keysym_t::BUILTIN;
188 222
189 user_keymap.push_back (key); 223 user_keymap.push_back (key);
190 user_translations.push_back (translation); 224 user_translations.push_back (translation);
191 register_keymap (key); 225 register_keymap (key);
192 } 226 }
228bool 262bool
229keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) 263keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state)
230{ 264{
231 assert (hash[0] == 0 && "register_done() need to be called"); 265 assert (hash[0] == 0 && "register_done() need to be called");
232 266
267 state &= OtherModMask; // mask out uninteresting modifiers
268
233 if (state & term->ModMetaMask) state |= MetaMask; 269 if (state & term->ModMetaMask) state |= MetaMask;
234 if (state & term->ModNumLockMask) state |= NumLockMask; 270 if (state & term->ModNumLockMask) state |= NumLockMask;
235 if (state & term->ModLevel3Mask) state |= Level3Mask; 271 if (state & term->ModLevel3Mask) state |= Level3Mask;
236 272
237 if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) 273 if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask))
241 277
242 if (index >= 0) 278 if (index >= 0)
243 { 279 {
244 const keysym_t &key = *keymap [index]; 280 const keysym_t &key = *keymap [index];
245 281
282 if (key.type != keysym_t::BUILTIN)
283 {
246 int keysym_offset = keysym - key.keysym; 284 int keysym_offset = keysym - key.keysym;
247 285
248 wchar_t *wc = rxvt_utf8towcs (key.str); 286 wchar_t *wc = rxvt_utf8towcs (key.str);
249 char *str = rxvt_wcstombs (wc); 287 char *str = rxvt_wcstombs (wc);
250 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 288 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
251 free (wc); 289 free (wc);
252 290
253 switch (key.type) 291 switch (key.type)
254 {
255 case keysym_t::NORMAL:
256 output_string (term, str);
257 break;
258
259 case keysym_t::RANGE:
260 { 292 {
293 case keysym_t::NORMAL:
294 output_string (term, str);
295 break;
296
297 case keysym_t::RANGE:
298 {
261 char buf[STRING_MAX]; 299 char buf[STRING_MAX];
262 300
263 if (format_keyrange_string (str, keysym_offset, buf, sizeof (buf)) > 0) 301 if (format_keyrange_string (str, keysym_offset, buf, sizeof (buf)) > 0)
302 output_string (term, buf);
303 }
304 break;
305
306 case keysym_t::RANGE_META8:
307 {
308 int len;
309 char buf[STRING_MAX];
310
311 len = format_keyrange_string (str, keysym_offset, buf, sizeof (buf));
312 if (len > 0)
313 output_string_meta8 (term, state, buf, len);
314 }
315 break;
316
317 case keysym_t::LIST:
318 {
319 char buf[STRING_MAX];
320
321 char *prefix, *middle, *suffix;
322
323 prefix = str;
324 middle = strchr (prefix + 1, *prefix);
325 suffix = strrchr (middle + 1, *prefix);
326
327 memcpy (buf, prefix + 1, middle - prefix - 1);
328 buf [middle - prefix - 1] = middle [keysym_offset + 1];
329 strcpy (buf + (middle - prefix), suffix + 1);
330
264 output_string (term, buf); 331 output_string (term, buf);
332 }
333 break;
265 } 334 }
266 break;
267 335
268 case keysym_t::RANGE_META8:
269 {
270 int len;
271 char buf[STRING_MAX];
272
273 len = format_keyrange_string (str, keysym_offset, buf, sizeof (buf));
274 if (len > 0)
275 output_string_meta8 (term, state, buf, len);
276 }
277 break;
278
279 case keysym_t::LIST:
280 {
281 char buf[STRING_MAX];
282
283 char *prefix, *middle, *suffix;
284
285 prefix = str;
286 middle = strchr (prefix + 1, *prefix);
287 suffix = strrchr (middle + 1, *prefix);
288
289 memcpy (buf, prefix + 1, middle - prefix - 1);
290 buf [middle - prefix - 1] = middle [keysym_offset + 1];
291 strcpy (buf + (middle - prefix), suffix + 1);
292
293 output_string (term, buf);
294 }
295 break;
296 }
297
298 free (str); 336 free (str);
299 337
300 return true; 338 return true;
339 }
301 } 340 }
302 else 341
303 return false; 342 return false;
304} 343}
305 344
306// purge duplicate keymap entries 345// purge duplicate keymap entries
307void keyboard_manager::purge_duplicate_keymap () 346void keyboard_manager::purge_duplicate_keymap ()
308{ 347{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines