ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/keyboard.C
(Generate patch)

Comparing rxvt-unicode/src/keyboard.C (file contents):
Revision 1.53 by sf-exg, Fri Dec 2 09:13:50 2011 UTC vs.
Revision 1.60 by sf-exg, Fri Dec 28 13:29:05 2012 UTC

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////////////////////////////////////////////////////////////////////////////////
95keyboard_manager::keyboard_manager () 89keyboard_manager::keyboard_manager ()
96{ 90{
105 free (keymap [i]->str); 99 free (keymap [i]->str);
106 delete keymap [i]; 100 delete keymap [i];
107 } 101 }
108} 102}
109 103
110// a wrapper for register_translation that converts the input string
111// to utf-8 and expands 'list' syntax.
112void 104void
113keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) 105keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws)
114{ 106{
115 char *translation = rxvt_wcstoutf8 (ws); 107 char *translation = rxvt_wcstoutf8 (ws);
116 108
117 register_translation (keysym, state, translation);
118}
119
120void
121keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation)
122{
123 keysym_t *key = new keysym_t; 109 keysym_t *key = new keysym_t;
124 110
125 if (key && translation)
126 {
127 key->keysym = keysym; 111 key->keysym = keysym;
128 key->state = state; 112 key->state = state;
129 key->str = translation; 113 key->str = translation;
130 key->type = keysym_t::STRING; 114 key->type = keysym_t::STRING;
131 115
132 if (strncmp (translation, "builtin:", 8) == 0) 116 if (strncmp (translation, "builtin:", 8) == 0)
133 key->type = keysym_t::BUILTIN; 117 key->type = keysym_t::BUILTIN;
134 118
135 if (keymap.size () == keymap.capacity ()) 119 if (keymap.size () == keymap.capacity ())
136 keymap.reserve (keymap.size () * 2); 120 keymap.reserve (keymap.size () * 2);
137 121
138 keymap.push_back (key); 122 keymap.push_back (key);
139 hash[0] = 3; 123 hash[0] = 3;
140 }
141 else
142 {
143 delete key;
144 free (translation);
145 rxvt_fatal ("memory allocation failure. aborting.\n");
146 }
147} 124}
148 125
149bool 126bool
150keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) 127keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state)
151{ 128{
186 163
187void 164void
188keyboard_manager::register_done () 165keyboard_manager::register_done ()
189{ 166{
190 unsigned int i, index, hashkey; 167 unsigned int i, index, hashkey;
191 vector <keysym_t *> sorted_keymap;
192 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
193 169
194 memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); 170 memset (hash_bucket_size, 0, sizeof (hash_bucket_size));
195 171
196 // determine hash bucket size 172 // determine hash bucket size
200 ++hash_bucket_size [hashkey]; 176 ++hash_bucket_size [hashkey];
201 } 177 }
202 178
203 // now we know the size of each bucket 179 // now we know the size of each bucket
204 // compute the index of each bucket 180 // compute the index of each bucket
205 hash [0] = 0;
206 for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) 181 for (index = 0, i = 0; i < KEYSYM_HASH_BUCKETS; ++i)
207 { 182 {
208 index += hash_bucket_size [i - 1];
209 hash [i] = index; 183 hash [i] = index;
184 index += hash_bucket_size [i];
210 } 185 }
211 186
212 // and allocate just enough space 187 // and allocate just enough space
213 sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); 188 simplevec <keysym_t *> sorted_keymap (index, 0);
214 189
215 memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); 190 memset (hash_bucket_size, 0, sizeof (hash_bucket_size));
216 191
217 // fill in sorted_keymap 192 // fill in sorted_keymap
218 // it is sorted in each bucket 193 // it is sorted in each bucket

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines