|
|
1 | /*----------------------------------------------------------------------* |
|
|
2 | * File: keyboard.h |
|
|
3 | *----------------------------------------------------------------------* |
|
|
4 | * |
|
|
5 | * All portions of code are copyright by their respective author/s. |
|
|
6 | * Copyright (c) 2005 WU Fengguang |
|
|
7 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
|
|
8 | * |
|
|
9 | * This program is free software; you can redistribute it and/or modify |
|
|
10 | * it under the terms of the GNU General Public License as published by |
|
|
11 | * the Free Software Foundation; either version 2 of the License, or |
|
|
12 | * (at your option) any later version. |
|
|
13 | * |
|
|
14 | * This program is distributed in the hope that it will be useful, |
|
|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
17 | * GNU General Public License for more details. |
|
|
18 | * |
|
|
19 | * You should have received a copy of the GNU General Public License |
|
|
20 | * along with this program; if not, write to the Free Software |
|
|
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
22 | *----------------------------------------------------------------------*/ |
|
|
23 | |
1 | #ifndef KEYBOARD_H_ |
24 | #ifndef KEYBOARD_H_ |
2 | #define KEYBOARD_H_ |
25 | #define KEYBOARD_H_ |
|
|
26 | |
|
|
27 | #ifdef KEYSYM_RESOURCE |
|
|
28 | |
|
|
29 | #include <inttypes.h> |
3 | |
30 | |
4 | #include "feature.h" |
31 | #include "feature.h" |
5 | #include "rxvtutil.h" |
32 | #include "rxvtutil.h" |
6 | |
33 | |
7 | #ifdef KEYSYM_RESOURCE |
|
|
8 | |
|
|
9 | #define KEYSYM_HASH_BITS 9 /* lowest #bits of keysym is used as hash key */ |
34 | #define KEYSYM_HASH_BITS 4 /* lowest #bits of keysym is used as hash key */ |
10 | #define KEYSYM_HASH_BUDGETS (1<<KEYSYM_HASH_BITS) |
35 | #define KEYSYM_HASH_BUCKETS (1<<KEYSYM_HASH_BITS) |
11 | #define KEYSYM_HASH_MASK (KEYSYM_HASH_BUDGETS-1) |
36 | #define KEYSYM_HASH_MASK (KEYSYM_HASH_BUCKETS-1) |
12 | |
37 | |
13 | #define MetaMask 0x0100 |
38 | #define MetaMask 0x0100 |
14 | #define NumLockMask 0x0200 |
39 | #define NumLockMask 0x0200 |
|
|
40 | #define AppKeypadMask 0x0400 |
|
|
41 | #define Level3Mask 0x0800 // currently not supported |
15 | #define AllModMask (ShiftMask | LockMask | ControlMask \ |
42 | #define OtherModMask (ShiftMask | LockMask | ControlMask \ |
16 | | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) |
43 | | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) |
17 | |
44 | |
18 | #if (AllModMask & (MetaMask | NumLockMask)) != 0 |
45 | #if OtherModMask > 0xff |
19 | #error redefine MetaMask or NumLockMask! |
46 | # error FATAL: X modifiers might clash with rxvt-unicode ones |
20 | #endif |
47 | #endif |
21 | |
48 | |
22 | struct rxvt_term; |
49 | struct rxvt_term; |
23 | struct keysym_t; |
50 | struct keysym_t; |
|
|
51 | |
24 | typedef void (keyevent_handler) (rxvt_term *rt, |
52 | typedef void (keyevent_handler) (rxvt_term *rt, |
25 | keysym_t *key, |
53 | keysym_t *key, |
26 | KeySym keysym, |
54 | KeySym keysym, |
27 | unsigned int state); |
55 | unsigned int state); |
28 | typedef unsigned short u16; |
|
|
29 | |
56 | |
30 | struct keysym_t |
57 | struct keysym_t |
31 | { |
58 | { |
|
|
59 | enum keysym_type { |
|
|
60 | STRING, RANGE, RANGE_META8, LIST, BUILTIN, |
|
|
61 | }; |
|
|
62 | |
32 | KeySym keysym; |
63 | KeySym keysym; |
33 | /* only the lower 8 bits of state are used for matching according to X.h */ |
64 | /* only the lower 8 bits of state are used for matching according to X.h */ |
34 | /* the higher bits are preserved for Meta/NumLock keys */ |
65 | /* the higher bits are preserved for Meta/NumLock keys */ |
35 | /* which are mapped to corresponding lower bits at register time */ |
66 | /* which are mapped to corresponding lower bits at register time */ |
36 | u16 state; /* indicates each modifiers' DOWN/UP status */ |
67 | uint16_t state; /* indicates each modifiers' DOWN/UP status */ |
37 | u16 range; /* =1: single keysym; >1: a of range keysyms */ |
68 | uint16_t range; /* =1: single keysym; >1: a of range keysyms */ |
38 | keyevent_handler *handler; /* event handler */ |
69 | keysym_type type; |
39 | const char *str; /* would normally be a keycode translation */ |
70 | const char *str; /* would normally be a keycode translation in UTF-8 */ |
40 | }; |
71 | }; |
41 | |
|
|
42 | |
72 | |
43 | class keyboard_manager |
73 | class keyboard_manager |
44 | { |
74 | { |
45 | public: |
75 | public: |
46 | keyboard_manager (rxvt_term *rt); |
76 | keyboard_manager (); |
47 | ~keyboard_manager (); |
77 | ~keyboard_manager (); |
48 | |
78 | |
49 | void clear (); |
79 | void clear (); |
50 | void register_user_translation (KeySym keysym, unsigned int state, const char *trans); |
80 | void register_user_translation (KeySym keysym, unsigned int state, const char *trans); |
51 | void register_done (); // call this to make newly registered keymaps take effect |
81 | void register_done (); // call this to make newly registered keymaps take effect |
52 | bool dispatch (KeySym keysym, unsigned int state); |
82 | bool dispatch (rxvt_term *term, KeySym keysym, unsigned int state); |
53 | |
83 | |
54 | private: |
84 | private: |
55 | void register_keymap (keysym_t *key); |
85 | void register_keymap (keysym_t *key); |
56 | void purge_duplicate_keymap (); |
86 | void purge_duplicate_keymap (); |
57 | void setup_hash (); |
87 | void setup_hash (); |
58 | int find_keysym (KeySym keysym, unsigned int state); |
88 | int find_keysym (KeySym keysym, unsigned int state); |
59 | |
89 | |
60 | private: |
90 | private: |
61 | rxvt_term * const term_; |
91 | uint16_t hash[KEYSYM_HASH_BUCKETS]; |
|
|
92 | vector<keysym_t *> keymap; |
62 | |
93 | |
63 | u16 hash_[KEYSYM_HASH_BUDGETS]; // |
94 | #if STOCK_KEYMAP |
64 | vector<keysym_t *> keymap_; |
|
|
65 | |
|
|
66 | // stock keymaps are all static data |
95 | // stock keymaps are all static data |
67 | static keysym_t stock_keymap_[]; |
96 | static keysym_t stock_keymap[]; |
68 | // user keymaps and their .string are dynamicly allocated and freed |
97 | #endif |
69 | vector<keysym_t *> user_keymap_; |
|
|
70 | vector<const char *> user_translations_; |
|
|
71 | }; |
98 | }; |
72 | |
99 | |
73 | #endif /* KEYSYM_RESOURCE */ |
100 | #endif /* KEYSYM_RESOURCE */ |
|
|
101 | |
74 | #endif /* KEYBOARD_H_ */ |
102 | #endif /* KEYBOARD_H_ */ |
75 | // vim:et:ts=2:sw=2 |
|
|