1 |
root |
1.1 |
#ifndef KEYBOARD_H_ |
2 |
|
|
#define KEYBOARD_H_ |
3 |
|
|
|
4 |
root |
1.2 |
#include <inttypes.h> |
5 |
|
|
|
6 |
root |
1.1 |
#include "feature.h" |
7 |
|
|
#include "rxvtutil.h" |
8 |
|
|
|
9 |
|
|
#ifdef KEYSYM_RESOURCE |
10 |
|
|
|
11 |
root |
1.2 |
#define KEYSYM_HASH_BITS 4 /* lowest #bits of keysym is used as hash key */ |
12 |
root |
1.1 |
#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 |
root |
1.2 |
#define AppKeypadMask 0x0400 |
18 |
|
|
#define OtherModMask (ShiftMask | LockMask | ControlMask \ |
19 |
root |
1.1 |
| Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) |
20 |
|
|
|
21 |
root |
1.2 |
#if (OtherModMask & (MetaMask | NumLockMask | AppKeypadMask)) != 0 |
22 |
|
|
# error FATAL: MetaMask, NumLockMask and/or AppKeypadMask clashes with X modifiers! |
23 |
root |
1.1 |
#endif |
24 |
|
|
|
25 |
|
|
struct rxvt_term; |
26 |
|
|
struct keysym_t; |
27 |
root |
1.2 |
|
28 |
root |
1.1 |
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 |
root |
1.2 |
enum keysym_type { |
36 |
|
|
NORMAL, RANGE, RANGE_META8, LIST |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
KeySym keysym; |
40 |
root |
1.1 |
/* 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 |
root |
1.2 |
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 |
root |
1.1 |
}; |
48 |
|
|
|
49 |
|
|
class keyboard_manager |
50 |
|
|
{ |
51 |
|
|
public: |
52 |
root |
1.2 |
keyboard_manager (); |
53 |
root |
1.1 |
~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 |
root |
1.2 |
bool dispatch (rxvt_term *term, KeySym keysym, unsigned int state); |
59 |
root |
1.1 |
|
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 |
root |
1.2 |
uint16_t hash[KEYSYM_HASH_BUDGETS]; |
68 |
|
|
vector<keysym_t *> keymap; |
69 |
root |
1.1 |
|
70 |
|
|
// stock keymaps are all static data |
71 |
root |
1.2 |
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 |
root |
1.1 |
}; |
76 |
|
|
|
77 |
|
|
#endif /* KEYSYM_RESOURCE */ |
78 |
|
|
#endif /* KEYBOARD_H_ */ |
79 |
root |
1.2 |
// vim:et:sw=2 |