… | |
… | |
105 | free (keymap [i]->str); |
105 | free (keymap [i]->str); |
106 | delete keymap [i]; |
106 | delete keymap [i]; |
107 | } |
107 | } |
108 | } |
108 | } |
109 | |
109 | |
110 | // a wrapper for register_translation that converts the input string |
|
|
111 | // to utf-8 and expands 'list' syntax. |
|
|
112 | void |
110 | void |
113 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) |
111 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
114 | { |
112 | { |
115 | wchar_t *wc = rxvt_mbstowcs (trans); |
|
|
116 | char *translation = rxvt_wcstoutf8 (wc); |
113 | char *translation = rxvt_wcstoutf8 (ws); |
117 | free (wc); |
|
|
118 | |
114 | |
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 | |
|
|
151 | void |
|
|
152 | keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation) |
|
|
153 | { |
|
|
154 | keysym_t *key = new keysym_t; |
115 | keysym_t *key = new keysym_t; |
155 | |
116 | |
156 | if (key && translation) |
117 | if (!key) |
157 | { |
|
|
158 | key->keysym = keysym; |
|
|
159 | key->state = state; |
|
|
160 | key->str = translation; |
|
|
161 | key->type = keysym_t::STRING; |
|
|
162 | |
|
|
163 | if (strncmp (translation, "builtin:", 8) == 0) |
|
|
164 | key->type = keysym_t::BUILTIN; |
|
|
165 | |
|
|
166 | if (keymap.size () == keymap.capacity ()) |
|
|
167 | keymap.reserve (keymap.size () * 2); |
|
|
168 | |
|
|
169 | keymap.push_back (key); |
|
|
170 | hash[0] = 3; |
|
|
171 | } |
|
|
172 | else |
|
|
173 | { |
|
|
174 | delete key; |
|
|
175 | free (translation); |
|
|
176 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
118 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
177 | } |
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; |
178 | } |
133 | } |
179 | |
134 | |
180 | bool |
135 | bool |
181 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
136 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
182 | { |
137 | { |
… | |
… | |
197 | { |
152 | { |
198 | keysym_t *key = keymap [index]; |
153 | keysym_t *key = keymap [index]; |
199 | |
154 | |
200 | if (key->type != keysym_t::BUILTIN) |
155 | if (key->type != keysym_t::BUILTIN) |
201 | { |
156 | { |
202 | wchar_t *wc = rxvt_utf8towcs (key->str); |
157 | wchar_t *ws = rxvt_utf8towcs (key->str); |
203 | char *str = rxvt_wcstombs (wc); |
158 | char *str = rxvt_wcstombs (ws); |
204 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
159 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
205 | free (wc); |
160 | free (ws); |
206 | |
161 | |
207 | output_string (term, str); |
162 | output_string (term, str); |
208 | |
163 | |
209 | free (str); |
164 | free (str); |
210 | |
165 | |