… | |
… | |
116 | } |
116 | } |
117 | |
117 | |
118 | keymap.clear (); |
118 | keymap.clear (); |
119 | } |
119 | } |
120 | |
120 | |
121 | // a wrapper for register_keymap, |
121 | // a wrapper for register_translation that converts the input string |
122 | // so that outside codes don't have to know so much details. |
122 | // to utf-8 and expands 'list' syntax. |
123 | // |
|
|
124 | // the string 'trans' is copied to an internal managed buffer, |
|
|
125 | // so the caller can free memory of 'trans' at any time. |
|
|
126 | void |
123 | void |
127 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) |
124 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) |
128 | { |
125 | { |
129 | keysym_t *key = new keysym_t; |
|
|
130 | wchar_t *wc = rxvt_mbstowcs (trans); |
126 | wchar_t *wc = rxvt_mbstowcs (trans); |
131 | char *translation = rxvt_wcstoutf8 (wc); |
127 | char *translation = rxvt_wcstoutf8 (wc); |
132 | free (wc); |
128 | free (wc); |
|
|
129 | |
|
|
130 | if (strncmp (translation, "list", 4) == 0 && translation [4] |
|
|
131 | && strlen (translation) < STRING_MAX) |
|
|
132 | { |
|
|
133 | char *prefix = translation + 4; |
|
|
134 | char *middle = strchr (prefix + 1, translation [4]); |
|
|
135 | char *suffix = strrchr (prefix + 1, translation [4]); |
|
|
136 | |
|
|
137 | if (suffix && middle && suffix > middle + 1) |
|
|
138 | { |
|
|
139 | int range = suffix - middle - 1; |
|
|
140 | int prefix_len = middle - prefix - 1; |
|
|
141 | char buf[STRING_MAX]; |
|
|
142 | |
|
|
143 | memcpy (buf, prefix + 1, prefix_len); |
|
|
144 | strcpy (buf + prefix_len + 1, suffix + 1); |
|
|
145 | |
|
|
146 | for (int i = 0; i < range; i++) |
|
|
147 | { |
|
|
148 | buf [prefix_len] = middle [i + 1]; |
|
|
149 | register_translation (keysym + i, state, strdup (buf)); |
|
|
150 | } |
|
|
151 | |
|
|
152 | free (translation); |
|
|
153 | return; |
|
|
154 | } |
|
|
155 | else |
|
|
156 | rxvt_warn ("cannot parse list-type keysym '%s', processing as normal keysym.\n", translation); |
|
|
157 | } |
|
|
158 | |
|
|
159 | register_translation (keysym, state, translation); |
|
|
160 | } |
|
|
161 | |
|
|
162 | void |
|
|
163 | keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation) |
|
|
164 | { |
|
|
165 | keysym_t *key = new keysym_t; |
133 | |
166 | |
134 | if (key && translation) |
167 | if (key && translation) |
135 | { |
168 | { |
136 | key->keysym = keysym; |
169 | key->keysym = keysym; |
137 | key->state = state; |
170 | key->state = state; |