ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/keyboard.h
Revision: 1.2
Committed: Sun Jan 16 18:05:37 2005 UTC (19 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +26 -22 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef KEYBOARD_H_
2 #define KEYBOARD_H_
3
4 #include <inttypes.h>
5
6 #include "feature.h"
7 #include "rxvtutil.h"
8
9 #ifdef KEYSYM_RESOURCE
10
11 #define KEYSYM_HASH_BITS 4 /* lowest #bits of keysym is used as hash key */
12 #define KEYSYM_HASH_BUDGETS (1<<KEYSYM_HASH_BITS)
13 #define KEYSYM_HASH_MASK (KEYSYM_HASH_BUDGETS-1)
14
15 #define MetaMask 0x0100
16 #define NumLockMask 0x0200
17 #define AppKeypadMask 0x0400
18 #define OtherModMask (ShiftMask | LockMask | ControlMask \
19 | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask)
20
21 #if (OtherModMask & (MetaMask | NumLockMask | AppKeypadMask)) != 0
22 # error FATAL: MetaMask, NumLockMask and/or AppKeypadMask clashes with X modifiers!
23 #endif
24
25 struct rxvt_term;
26 struct keysym_t;
27
28 typedef void (keyevent_handler) (rxvt_term *rt,
29 keysym_t *key,
30 KeySym keysym,
31 unsigned int state);
32
33 struct keysym_t
34 {
35 enum keysym_type {
36 NORMAL, RANGE, RANGE_META8, LIST
37 };
38
39 KeySym keysym;
40 /* only the lower 8 bits of state are used for matching according to X.h */
41 /* the higher bits are preserved for Meta/NumLock keys */
42 /* which are mapped to corresponding lower bits at register time */
43 uint16_t state; /* indicates each modifiers' DOWN/UP status */
44 uint16_t range; /* =1: single keysym; >1: a of range keysyms */
45 keysym_type type;
46 const char *str; /* would normally be a keycode translation in UTF-8 */
47 };
48
49 class keyboard_manager
50 {
51 public:
52 keyboard_manager ();
53 ~keyboard_manager ();
54
55 void clear ();
56 void register_user_translation (KeySym keysym, unsigned int state, const char *trans);
57 void register_done (); // call this to make newly registered keymaps take effect
58 bool dispatch (rxvt_term *term, KeySym keysym, unsigned int state);
59
60 private:
61 void register_keymap (keysym_t *key);
62 void purge_duplicate_keymap ();
63 void setup_hash ();
64 int find_keysym (KeySym keysym, unsigned int state);
65
66 private:
67 uint16_t hash[KEYSYM_HASH_BUDGETS];
68 vector<keysym_t *> keymap;
69
70 // stock keymaps are all static data
71 static keysym_t stock_keymap[];
72 // user keymaps and their .string are dynamicaly allocated and freed
73 vector<keysym_t *> user_keymap;
74 vector<const char *> user_translations;
75 };
76
77 #endif /* KEYSYM_RESOURCE */
78 #endif /* KEYBOARD_H_ */
79 // vim:et:sw=2