… | |
… | |
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 | { |
… | |
… | |
111 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
105 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
112 | { |
106 | { |
113 | char *translation = rxvt_wcstoutf8 (ws); |
107 | char *translation = rxvt_wcstoutf8 (ws); |
114 | |
108 | |
115 | keysym_t *key = new keysym_t; |
109 | keysym_t *key = new keysym_t; |
116 | |
|
|
117 | if (!key) |
|
|
118 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
119 | |
110 | |
120 | key->keysym = keysym; |
111 | key->keysym = keysym; |
121 | key->state = state; |
112 | key->state = state; |
122 | key->str = translation; |
113 | key->str = translation; |
123 | key->type = keysym_t::STRING; |
114 | key->type = keysym_t::STRING; |
… | |
… | |
172 | |
163 | |
173 | void |
164 | void |
174 | keyboard_manager::register_done () |
165 | keyboard_manager::register_done () |
175 | { |
166 | { |
176 | unsigned int i, index, hashkey; |
167 | unsigned int i, index, hashkey; |
177 | vector <keysym_t *> sorted_keymap; |
|
|
178 | 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 |
179 | |
169 | |
180 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
170 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
181 | |
171 | |
182 | // determine hash bucket size |
172 | // determine hash bucket size |
… | |
… | |
186 | ++hash_bucket_size [hashkey]; |
176 | ++hash_bucket_size [hashkey]; |
187 | } |
177 | } |
188 | |
178 | |
189 | // now we know the size of each bucket |
179 | // now we know the size of each bucket |
190 | // compute the index of each bucket |
180 | // compute the index of each bucket |
191 | hash [0] = 0; |
|
|
192 | for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) |
181 | for (index = 0, i = 0; i < KEYSYM_HASH_BUCKETS; ++i) |
193 | { |
182 | { |
194 | index += hash_bucket_size [i - 1]; |
|
|
195 | hash [i] = index; |
183 | hash [i] = index; |
|
|
184 | index += hash_bucket_size [i]; |
196 | } |
185 | } |
197 | |
186 | |
198 | // and allocate just enough space |
187 | // and allocate just enough space |
199 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); |
188 | simplevec <keysym_t *> sorted_keymap (index, 0); |
200 | |
189 | |
201 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
190 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
202 | |
191 | |
203 | // fill in sorted_keymap |
192 | // fill in sorted_keymap |
204 | // it is sorted in each bucket |
193 | // it is sorted in each bucket |