… | |
… | |
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 | |
33 | |
34 | /* an intro to the data structure: |
34 | /* an intro to the data structure: |
… | |
… | |
80 | { |
80 | { |
81 | // (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 |
82 | int ca = ecb_popcount32 (a->state /* & OtherModMask */); |
82 | int ca = ecb_popcount32 (a->state /* & OtherModMask */); |
83 | int cb = ecb_popcount32 (b->state /* & OtherModMask */); |
83 | int cb = ecb_popcount32 (b->state /* & OtherModMask */); |
84 | |
84 | |
85 | if (ca != cb) |
|
|
86 | return ca - cb; |
85 | return ca - cb; |
87 | //else if (a->state != b->state) // this behavior is to be discussed |
|
|
88 | // return b->state - a->state; |
|
|
89 | else |
|
|
90 | return 0; |
|
|
91 | } |
86 | } |
92 | |
87 | |
93 | //////////////////////////////////////////////////////////////////////////////// |
88 | //////////////////////////////////////////////////////////////////////////////// |
94 | keyboard_manager::keyboard_manager () |
89 | keyboard_manager::keyboard_manager () |
95 | { |
90 | { |
… | |
… | |
127 | keymap.push_back (key); |
122 | keymap.push_back (key); |
128 | hash[0] = 3; |
123 | hash[0] = 3; |
129 | } |
124 | } |
130 | |
125 | |
131 | bool |
126 | bool |
132 | 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) |
133 | { |
128 | { |
134 | assert (("register_done() need to be called", hash[0] == 0)); |
129 | assert (("register_done() need to be called", hash[0] == 0)); |
135 | |
130 | |
136 | state &= OtherModMask; // mask out uninteresting modifiers |
131 | state &= OtherModMask; // mask out uninteresting modifiers |
137 | |
132 | |
… | |
… | |
168 | |
163 | |
169 | void |
164 | void |
170 | keyboard_manager::register_done () |
165 | keyboard_manager::register_done () |
171 | { |
166 | { |
172 | unsigned int i, index, hashkey; |
167 | unsigned int i, index, hashkey; |
173 | vector <keysym_t *> sorted_keymap; |
|
|
174 | 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 |
175 | |
169 | |
176 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
170 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
177 | |
171 | |
178 | // determine hash bucket size |
172 | // determine hash bucket size |
… | |
… | |
182 | ++hash_bucket_size [hashkey]; |
176 | ++hash_bucket_size [hashkey]; |
183 | } |
177 | } |
184 | |
178 | |
185 | // now we know the size of each bucket |
179 | // now we know the size of each bucket |
186 | // compute the index of each bucket |
180 | // compute the index of each bucket |
187 | hash [0] = 0; |
|
|
188 | for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) |
181 | for (index = 0, i = 0; i < KEYSYM_HASH_BUCKETS; ++i) |
189 | { |
182 | { |
190 | index += hash_bucket_size [i - 1]; |
|
|
191 | hash [i] = index; |
183 | hash [i] = index; |
|
|
184 | index += hash_bucket_size [i]; |
192 | } |
185 | } |
193 | |
186 | |
194 | // and allocate just enough space |
187 | // and allocate just enough space |
195 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); |
188 | simplevec <keysym_t *> sorted_keymap (index, 0); |
196 | |
189 | |
197 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
190 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
198 | |
191 | |
199 | // fill in sorted_keymap |
192 | // fill in sorted_keymap |
200 | // it is sorted in each bucket |
193 | // it is sorted in each bucket |