| 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 |
root |
1.3 |
#define Level3Mask 0x0800 // currently not supported |
| 19 |
root |
1.2 |
#define OtherModMask (ShiftMask | LockMask | ControlMask \ |
| 20 |
root |
1.1 |
| Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) |
| 21 |
|
|
|
| 22 |
root |
1.3 |
#if OtherModMask > 0xff |
| 23 |
|
|
# error FATAL: X modifiers might clash with rxvt-unicode ones |
| 24 |
root |
1.1 |
#endif |
| 25 |
|
|
|
| 26 |
|
|
struct rxvt_term; |
| 27 |
|
|
struct keysym_t; |
| 28 |
root |
1.2 |
|
| 29 |
root |
1.1 |
typedef void (keyevent_handler) (rxvt_term *rt, |
| 30 |
|
|
keysym_t *key, |
| 31 |
|
|
KeySym keysym, |
| 32 |
|
|
unsigned int state); |
| 33 |
|
|
|
| 34 |
|
|
struct keysym_t |
| 35 |
|
|
{ |
| 36 |
root |
1.2 |
enum keysym_type { |
| 37 |
|
|
NORMAL, RANGE, RANGE_META8, LIST |
| 38 |
|
|
}; |
| 39 |
|
|
|
| 40 |
|
|
KeySym keysym; |
| 41 |
root |
1.1 |
/* only the lower 8 bits of state are used for matching according to X.h */ |
| 42 |
|
|
/* the higher bits are preserved for Meta/NumLock keys */ |
| 43 |
|
|
/* which are mapped to corresponding lower bits at register time */ |
| 44 |
root |
1.2 |
uint16_t state; /* indicates each modifiers' DOWN/UP status */ |
| 45 |
|
|
uint16_t range; /* =1: single keysym; >1: a of range keysyms */ |
| 46 |
|
|
keysym_type type; |
| 47 |
|
|
const char *str; /* would normally be a keycode translation in UTF-8 */ |
| 48 |
root |
1.1 |
}; |
| 49 |
|
|
|
| 50 |
|
|
class keyboard_manager |
| 51 |
|
|
{ |
| 52 |
|
|
public: |
| 53 |
root |
1.2 |
keyboard_manager (); |
| 54 |
root |
1.1 |
~keyboard_manager (); |
| 55 |
|
|
|
| 56 |
|
|
void clear (); |
| 57 |
|
|
void register_user_translation (KeySym keysym, unsigned int state, const char *trans); |
| 58 |
|
|
void register_done (); // call this to make newly registered keymaps take effect |
| 59 |
root |
1.2 |
bool dispatch (rxvt_term *term, KeySym keysym, unsigned int state); |
| 60 |
root |
1.1 |
|
| 61 |
|
|
private: |
| 62 |
|
|
void register_keymap (keysym_t *key); |
| 63 |
|
|
void purge_duplicate_keymap (); |
| 64 |
|
|
void setup_hash (); |
| 65 |
|
|
int find_keysym (KeySym keysym, unsigned int state); |
| 66 |
|
|
|
| 67 |
|
|
private: |
| 68 |
root |
1.2 |
uint16_t hash[KEYSYM_HASH_BUDGETS]; |
| 69 |
|
|
vector<keysym_t *> keymap; |
| 70 |
root |
1.1 |
|
| 71 |
|
|
// stock keymaps are all static data |
| 72 |
root |
1.2 |
static keysym_t stock_keymap[]; |
| 73 |
|
|
// user keymaps and their .string are dynamicaly allocated and freed |
| 74 |
|
|
vector<keysym_t *> user_keymap; |
| 75 |
|
|
vector<const char *> user_translations; |
| 76 |
root |
1.1 |
}; |
| 77 |
|
|
|
| 78 |
|
|
#endif /* KEYSYM_RESOURCE */ |
| 79 |
|
|
#endif /* KEYBOARD_H_ */ |
| 80 |
root |
1.2 |
// vim:et:sw=2 |