… | |
… | |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005 WU Fengguang |
6 | * Copyright (c) 2005 WU Fengguang |
7 | * Copyright (c) 2005-2006 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2005-2006 Marc Lehmann <schmorp@schmorp.de> |
|
|
8 | * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * |
9 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * the Free Software Foundation; either version 3 of the License, or |
12 | * (at your option) any later version. |
13 | * (at your option) any later version. |
13 | * |
14 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
89 | delete keymap [i]; |
90 | delete keymap [i]; |
90 | } |
91 | } |
91 | } |
92 | } |
92 | |
93 | |
93 | void |
94 | void |
|
|
95 | keyboard_manager::unregister_action (KeySym keysym, unsigned int state) |
|
|
96 | { |
|
|
97 | for (unsigned int i = 0; i < keymap.size (); ++i) |
|
|
98 | if (keymap [i]->keysym == keysym |
|
|
99 | && keymap [i]->state == state) |
|
|
100 | { |
|
|
101 | free (keymap [i]->str); |
|
|
102 | delete keymap [i]; |
|
|
103 | |
|
|
104 | if (i < keymap.size () - 1) |
|
|
105 | keymap [i] = keymap [keymap.size () - 1]; |
|
|
106 | keymap.pop_back (); |
|
|
107 | |
|
|
108 | break; |
|
|
109 | } |
|
|
110 | } |
|
|
111 | |
|
|
112 | void |
94 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
113 | keyboard_manager::register_action (KeySym keysym, unsigned int state, const wchar_t *ws) |
95 | { |
114 | { |
96 | char *translation = rxvt_wcstoutf8 (ws); |
115 | char *action = rxvt_wcstoutf8 (ws); |
97 | |
116 | |
98 | keysym_t *key = new keysym_t; |
117 | keysym_t *key = new keysym_t; |
99 | |
118 | |
100 | key->keysym = keysym; |
119 | key->keysym = keysym; |
101 | key->state = state; |
120 | key->state = state; |
102 | key->str = translation; |
121 | key->str = action; |
103 | key->type = keysym_t::STRING; |
122 | key->type = keysym_t::STRING; |
104 | |
123 | |
105 | if (strncmp (translation, "builtin:", 8) == 0) |
124 | if (strncmp (action, "builtin:", 8) == 0) |
106 | key->type = keysym_t::BUILTIN; |
125 | key->type = keysym_t::BUILTIN; |
107 | else if (strncmp (translation, "builtin-string:", 15) == 0) |
126 | else if (strncmp (action, "builtin-string:", 15) == 0) |
108 | key->type = keysym_t::BUILTIN_STRING; |
127 | key->type = keysym_t::BUILTIN_STRING; |
|
|
128 | |
|
|
129 | unregister_action (keysym, state); |
109 | |
130 | |
110 | if (keymap.size () == keymap.capacity ()) |
131 | if (keymap.size () == keymap.capacity ()) |
111 | keymap.reserve (keymap.size () * 2); |
132 | keymap.reserve (keymap.size () * 2); |
112 | |
133 | |
113 | keymap.push_back (key); |
134 | keymap.push_back (key); |
114 | hash[0] = 3; |
135 | hash[0] = 3; |
115 | } |
136 | } |
116 | |
137 | |
117 | bool |
138 | keysym_t * |
118 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) |
139 | keyboard_manager::lookup_keysym (rxvt_term *term, KeySym keysym, unsigned int state) |
119 | { |
140 | { |
120 | assert (("register_done() need to be called", hash[0] == 0)); |
141 | assert (("register_done() need to be called", hash[0] == 0)); |
121 | |
142 | |
122 | state &= OtherModMask; // mask out uninteresting modifiers |
143 | state &= OtherModMask; // mask out uninteresting modifiers |
123 | |
144 | |
… | |
… | |
128 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
149 | if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) |
129 | state |= AppKeypadMask; |
150 | state |= AppKeypadMask; |
130 | |
151 | |
131 | int index = find_keysym (keysym, state); |
152 | int index = find_keysym (keysym, state); |
132 | |
153 | |
133 | if (index >= 0) |
154 | return index >= 0 ? keymap [index] : 0; |
134 | { |
155 | } |
135 | keysym_t *key = keymap [index]; |
|
|
136 | |
156 | |
|
|
157 | bool |
|
|
158 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) |
|
|
159 | { |
|
|
160 | keysym_t *key = lookup_keysym (term, keysym, state); |
|
|
161 | |
|
|
162 | if (key) |
|
|
163 | { |
137 | if (key->type == keysym_t::BUILTIN_STRING) |
164 | if (key->type == keysym_t::BUILTIN_STRING) |
138 | { |
165 | { |
139 | term->tt_write_user_input (kbuf, len); |
166 | term->tt_write_user_input (kbuf, len); |
140 | return true; |
167 | return true; |
141 | } |
168 | } |
… | |
… | |
150 | { |
177 | { |
151 | if (strncmp (str, "command:", 8) == 0) |
178 | if (strncmp (str, "command:", 8) == 0) |
152 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
179 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
153 | else if (strncmp (str, "string:", 7) == 0) |
180 | else if (strncmp (str, "string:", 7) == 0) |
154 | term->tt_write_user_input (colon + 1, strlen (colon + 1)); |
181 | term->tt_write_user_input (colon + 1, strlen (colon + 1)); |
155 | else if (strncmp (str, "perl:", 8) == 0) |
182 | else if (strncmp (str, "perl:", 5) == 0) |
156 | HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); |
183 | HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); |
157 | else |
184 | else |
158 | HOOK_INVOKE ((term, HOOK_KEYBOARD_DISPATCH, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_END)); |
185 | HOOK_INVOKE ((term, HOOK_ACTION, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_INT, 0, DT_STR_LEN, kbuf, len, DT_END)); |
159 | } |
186 | } |
160 | else |
187 | else |
161 | term->tt_write_user_input (str, strlen (str)); |
188 | term->tt_write_user_input (str, strlen (str)); |
162 | |
189 | |
163 | free (str); |
190 | free (str); |