… | |
… | |
63 | * n(the number of groups) = the number of non-zero member of hash_bucket_size[]; |
63 | * n(the number of groups) = the number of non-zero member of hash_bucket_size[]; |
64 | * Ni(the size of group i) = hash_bucket_size[Ii]. |
64 | * Ni(the size of group i) = hash_bucket_size[Ii]. |
65 | */ |
65 | */ |
66 | |
66 | |
67 | static void |
67 | static void |
68 | output_string (rxvt_term *rt, const char *str) |
68 | output_string (rxvt_term *term, const char *str) |
69 | { |
69 | { |
70 | if (strncmp (str, "command:", 8) == 0) |
70 | if (strncmp (str, "command:", 8) == 0) |
71 | rt->cmdbuf_append (str + 8, strlen (str) - 8); |
71 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
72 | else if (strncmp (str, "perl:", 5) == 0) |
72 | else if (strncmp (str, "perl:", 5) == 0) |
73 | HOOK_INVOKE((rt, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); |
73 | HOOK_INVOKE((term, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); |
74 | else |
74 | else |
75 | rt->tt_write (str, strlen (str)); |
75 | term->tt_write (str, strlen (str)); |
76 | } |
76 | } |
77 | |
77 | |
78 | // return: priority_of_a - priority_of_b |
78 | // return: priority_of_a - priority_of_b |
79 | static int |
79 | static int |
80 | compare_priority (keysym_t *a, keysym_t *b) |
80 | compare_priority (keysym_t *a, keysym_t *b) |
… | |
… | |
98 | hash [0] = 1; // hash[0] != 0 indicates uninitialized data |
98 | hash [0] = 1; // hash[0] != 0 indicates uninitialized data |
99 | } |
99 | } |
100 | |
100 | |
101 | keyboard_manager::~keyboard_manager () |
101 | keyboard_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 |
110 | // a wrapper for register_translation that converts the input string |
116 | // to utf-8 and expands 'list' syntax. |
111 | // to utf-8 and expands 'list' syntax. |
117 | void |
112 | void |
118 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) |
113 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
119 | { |
114 | { |
120 | wchar_t *wc = rxvt_mbstowcs (trans); |
|
|
121 | char *translation = rxvt_wcstoutf8 (wc); |
115 | char *translation = rxvt_wcstoutf8 (ws); |
122 | free (wc); |
|
|
123 | |
|
|
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 | |
116 | |
153 | register_translation (keysym, state, translation); |
117 | register_translation (keysym, state, translation); |
154 | } |
118 | } |
155 | |
119 | |
156 | void |
120 | void |
… | |
… | |
198 | |
162 | |
199 | int index = find_keysym (keysym, state); |
163 | int index = find_keysym (keysym, state); |
200 | |
164 | |
201 | if (index >= 0) |
165 | if (index >= 0) |
202 | { |
166 | { |
203 | const keysym_t &key = *keymap [index]; |
167 | keysym_t *key = keymap [index]; |
204 | |
168 | |
205 | if (key.type != keysym_t::BUILTIN) |
169 | if (key->type != keysym_t::BUILTIN) |
206 | { |
170 | { |
207 | wchar_t *wc = rxvt_utf8towcs (key.str); |
171 | wchar_t *ws = rxvt_utf8towcs (key->str); |
208 | char *str = rxvt_wcstombs (wc); |
172 | char *str = rxvt_wcstombs (ws); |
209 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
173 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
210 | free (wc); |
174 | free (ws); |
211 | |
175 | |
212 | output_string (term, str); |
176 | output_string (term, str); |
213 | |
177 | |
214 | free (str); |
178 | free (str); |
215 | |
179 | |