… | |
… | |
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 | * |
… | |
… | |
112 | { |
111 | { |
113 | char *translation = rxvt_wcstoutf8 (ws); |
112 | char *translation = rxvt_wcstoutf8 (ws); |
114 | |
113 | |
115 | keysym_t *key = new keysym_t; |
114 | keysym_t *key = new keysym_t; |
116 | |
115 | |
117 | if (key && translation) |
|
|
118 | { |
|
|
119 | key->keysym = keysym; |
116 | key->keysym = keysym; |
120 | key->state = state; |
117 | key->state = state; |
121 | key->str = translation; |
118 | key->str = translation; |
122 | key->type = keysym_t::STRING; |
119 | key->type = keysym_t::STRING; |
123 | |
120 | |
124 | if (strncmp (translation, "builtin:", 8) == 0) |
121 | if (strncmp (translation, "builtin:", 8) == 0) |
125 | key->type = keysym_t::BUILTIN; |
122 | key->type = keysym_t::BUILTIN; |
126 | |
123 | |
127 | if (keymap.size () == keymap.capacity ()) |
124 | if (keymap.size () == keymap.capacity ()) |
128 | keymap.reserve (keymap.size () * 2); |
125 | keymap.reserve (keymap.size () * 2); |
129 | |
126 | |
130 | keymap.push_back (key); |
127 | keymap.push_back (key); |
131 | hash[0] = 3; |
128 | hash[0] = 3; |
132 | } |
|
|
133 | else |
|
|
134 | { |
|
|
135 | delete key; |
|
|
136 | free (translation); |
|
|
137 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
138 | } |
|
|
139 | } |
129 | } |
140 | |
130 | |
141 | bool |
131 | bool |
142 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
132 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
143 | { |
133 | { |
… | |
… | |
178 | |
168 | |
179 | void |
169 | void |
180 | keyboard_manager::register_done () |
170 | keyboard_manager::register_done () |
181 | { |
171 | { |
182 | unsigned int i, index, hashkey; |
172 | unsigned int i, index, hashkey; |
183 | vector <keysym_t *> sorted_keymap; |
|
|
184 | uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket |
173 | uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket |
185 | |
174 | |
186 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
175 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
187 | |
176 | |
188 | // determine hash bucket size |
177 | // determine hash bucket size |
… | |
… | |
200 | index += hash_bucket_size [i - 1]; |
189 | index += hash_bucket_size [i - 1]; |
201 | hash [i] = index; |
190 | hash [i] = index; |
202 | } |
191 | } |
203 | |
192 | |
204 | // and allocate just enough space |
193 | // and allocate just enough space |
205 | sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); |
194 | simplevec <keysym_t *> sorted_keymap (index + hash_bucket_size [i - 1], 0); |
206 | |
195 | |
207 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
196 | memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); |
208 | |
197 | |
209 | // fill in sorted_keymap |
198 | // fill in sorted_keymap |
210 | // it is sorted in each bucket |
199 | // it is sorted in each bucket |