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.49 by sf-exg, Sun Nov 27 12:12:49 2011 UTC vs.
Revision 1.55 by sf-exg, Sat Dec 3 11:47:19 2011 UTC

98 hash [0] = 1; // hash[0] != 0 indicates uninitialized data 98 hash [0] = 1; // hash[0] != 0 indicates uninitialized data
99} 99}
100 100
101keyboard_manager::~keyboard_manager () 101keyboard_manager::~keyboard_manager ()
102{ 102{
103 hash [0] = 2;
104
105 for (unsigned int i = 0; i < keymap.size (); ++i) 103 for (unsigned int i = 0; i < keymap.size (); ++i)
106 { 104 {
107 free (keymap [i]->str); 105 free (keymap [i]->str);
108 delete keymap [i]; 106 delete keymap [i];
109 keymap [i] = 0;
110 } 107 }
111
112 keymap.clear ();
113} 108}
114 109
115// a wrapper for register_translation that converts the input string
116// to utf-8 and expands 'list' syntax.
117void 110void
118keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) 111keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws)
119{ 112{
120 wchar_t *wc = rxvt_mbstowcs (trans);
121 char *translation = rxvt_wcstoutf8 (wc); 113 char *translation = rxvt_wcstoutf8 (ws);
122 free (wc);
123 114
124 if (strncmp (translation, "list", 4) == 0 && translation [4]
125 && strlen (translation) < STRING_MAX)
126 {
127 char *prefix = translation + 4;
128 char *middle = strchr (prefix + 1, translation [4]);
129 char *suffix = strrchr (prefix + 1, translation [4]);
130
131 if (suffix && middle && suffix > middle + 1)
132 {
133 int range = suffix - middle - 1;
134 int prefix_len = middle - prefix - 1;
135 char buf[STRING_MAX];
136
137 memcpy (buf, prefix + 1, prefix_len);
138 strcpy (buf + prefix_len + 1, suffix + 1);
139
140 for (int i = 0; i < range; i++)
141 {
142 buf [prefix_len] = middle [i + 1];
143 register_translation (keysym + i, state, strdup (buf));
144 }
145
146 free (translation);
147 return;
148 }
149 else
150 rxvt_warn ("unable to parse list-type keysym '%s', processing as normal keysym.\n", translation);
151 }
152
153 register_translation (keysym, state, translation);
154}
155
156void
157keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation)
158{
159 keysym_t *key = new keysym_t; 115 keysym_t *key = new keysym_t;
160 116
161 if (key && translation) 117 if (!key)
162 {
163 key->keysym = keysym;
164 key->state = state;
165 key->str = translation;
166 key->type = keysym_t::STRING;
167
168 if (strncmp (translation, "builtin:", 8) == 0)
169 key->type = keysym_t::BUILTIN;
170
171 if (keymap.size () == keymap.capacity ())
172 keymap.reserve (keymap.size () * 2);
173
174 keymap.push_back (key);
175 hash[0] = 3;
176 }
177 else
178 {
179 delete key;
180 free (translation);
181 rxvt_fatal ("memory allocation failure. aborting.\n"); 118 rxvt_fatal ("memory allocation failure. aborting.\n");
182 } 119
120 key->keysym = keysym;
121 key->state = state;
122 key->str = translation;
123 key->type = keysym_t::STRING;
124
125 if (strncmp (translation, "builtin:", 8) == 0)
126 key->type = keysym_t::BUILTIN;
127
128 if (keymap.size () == keymap.capacity ())
129 keymap.reserve (keymap.size () * 2);
130
131 keymap.push_back (key);
132 hash[0] = 3;
183} 133}
184 134
185bool 135bool
186keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) 136keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state)
187{ 137{
202 { 152 {
203 keysym_t *key = keymap [index]; 153 keysym_t *key = keymap [index];
204 154
205 if (key->type != keysym_t::BUILTIN) 155 if (key->type != keysym_t::BUILTIN)
206 { 156 {
207 wchar_t *wc = rxvt_utf8towcs (key->str); 157 wchar_t *ws = rxvt_utf8towcs (key->str);
208 char *str = rxvt_wcstombs (wc); 158 char *str = rxvt_wcstombs (ws);
209 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 159 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
210 free (wc); 160 free (ws);
211 161
212 output_string (term, str); 162 output_string (term, str);
213 163
214 free (str); 164 free (str);
215 165

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines