… | |
… | |
24 | #include "../config.h" |
24 | #include "../config.h" |
25 | #include "rxvt.h" |
25 | #include "rxvt.h" |
26 | |
26 | |
27 | #ifdef KEYSYM_RESOURCE |
27 | #ifdef KEYSYM_RESOURCE |
28 | |
28 | |
29 | #include <cstring> |
29 | #include <string.h> |
30 | |
30 | |
31 | #include "rxvtperl.h" |
31 | #include "rxvtperl.h" |
32 | #include "keyboard.h" |
32 | #include "keyboard.h" |
33 | #include "command.h" |
|
|
34 | |
33 | |
35 | /* an intro to the data structure: |
34 | /* an intro to the data structure: |
36 | * |
35 | * |
37 | * vector keymap[] is grouped. |
36 | * vector keymap[] is grouped. |
38 | * |
37 | * |
… | |
… | |
81 | { |
80 | { |
82 | // (the more '1's in state; the less range): the greater priority |
81 | // (the more '1's in state; the less range): the greater priority |
83 | int ca = ecb_popcount32 (a->state /* & OtherModMask */); |
82 | int ca = ecb_popcount32 (a->state /* & OtherModMask */); |
84 | int cb = ecb_popcount32 (b->state /* & OtherModMask */); |
83 | int cb = ecb_popcount32 (b->state /* & OtherModMask */); |
85 | |
84 | |
86 | if (ca != cb) |
|
|
87 | return ca - cb; |
85 | return ca - cb; |
88 | //else if (a->state != b->state) // this behavior is to be discussed |
|
|
89 | // return b->state - a->state; |
|
|
90 | else |
|
|
91 | return 0; |
|
|
92 | } |
86 | } |
93 | |
87 | |
94 | //////////////////////////////////////////////////////////////////////////////// |
88 | //////////////////////////////////////////////////////////////////////////////// |
95 | keyboard_manager::keyboard_manager () |
89 | keyboard_manager::keyboard_manager () |
96 | { |
90 | { |
… | |
… | |
128 | keymap.push_back (key); |
122 | keymap.push_back (key); |
129 | hash[0] = 3; |
123 | hash[0] = 3; |
130 | } |
124 | } |
131 | |
125 | |
132 | bool |
126 | bool |
133 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
127 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) |
134 | { |
128 | { |
135 | assert (("register_done() need to be called", hash[0] == 0)); |
129 | assert (("register_done() need to be called", hash[0] == 0)); |
136 | |
130 | |
137 | state &= OtherModMask; // mask out uninteresting modifiers |
131 | state &= OtherModMask; // mask out uninteresting modifiers |
138 | |
132 | |
… | |
… | |
169 | |
163 | |
170 | void |
164 | void |
171 | keyboard_manager::register_done () |
165 | keyboard_manager::register_done () |
172 | { |
166 | { |
173 | unsigned int i, index, hashkey; |
167 | unsigned int i, index, hashkey; |
174 | vector <keysym_t *> sorted_keymap; |
|
|
175 | uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket |
168 | uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket |
176 | |
169 | |
177 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
170 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
178 | |
171 | |
179 | // determine hash bucket size |
172 | // determine hash bucket size |
… | |
… | |
183 | ++hash_bucket_size [hashkey]; |
176 | ++hash_bucket_size [hashkey]; |
184 | } |
177 | } |
185 | |
178 | |
186 | // now we know the size of each bucket |
179 | // now we know the size of each bucket |
187 | // compute the index of each bucket |
180 | // compute the index of each bucket |
188 | hash [0] = 0; |
|
|
189 | for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) |
181 | for (index = 0, i = 0; i < KEYSYM_HASH_BUCKETS; ++i) |
190 | { |
182 | { |
191 | index += hash_bucket_size [i - 1]; |
|
|
192 | hash [i] = index; |
183 | hash [i] = index; |
|
|
184 | index += hash_bucket_size [i]; |
193 | } |
185 | } |
194 | |
186 | |
195 | // and allocate just enough space |
187 | // and allocate just enough space |
196 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); |
188 | simplevec <keysym_t *> sorted_keymap (index, 0); |
197 | |
189 | |
198 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
190 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
199 | |
191 | |
200 | // fill in sorted_keymap |
192 | // fill in sorted_keymap |
201 | // it is sorted in each bucket |
193 | // it is sorted in each bucket |