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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines