… | |
… | |
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 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * 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 |
10 | * 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 |
11 | * the Free Software Foundation; either version 3 of the License, or |
12 | * (at your option) any later version. |
12 | * (at your option) any later version. |
13 | * |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
89 | delete keymap [i]; |
89 | delete keymap [i]; |
90 | } |
90 | } |
91 | } |
91 | } |
92 | |
92 | |
93 | void |
93 | void |
94 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
94 | keyboard_manager::register_action (KeySym keysym, unsigned int state, const wchar_t *ws) |
95 | { |
95 | { |
96 | char *translation = rxvt_wcstoutf8 (ws); |
96 | char *action = rxvt_wcstoutf8 (ws); |
97 | |
97 | |
98 | keysym_t *key = new keysym_t; |
98 | keysym_t *key = new keysym_t; |
99 | |
99 | |
100 | key->keysym = keysym; |
100 | key->keysym = keysym; |
101 | key->state = state; |
101 | key->state = state; |
102 | key->str = translation; |
102 | key->str = action; |
103 | key->type = keysym_t::STRING; |
103 | key->type = keysym_t::STRING; |
104 | |
104 | |
105 | if (strncmp (translation, "builtin:", 8) == 0) |
105 | if (strncmp (action, "builtin:", 8) == 0) |
106 | key->type = keysym_t::BUILTIN; |
106 | key->type = keysym_t::BUILTIN; |
|
|
107 | else if (strncmp (action, "builtin-string:", 15) == 0) |
|
|
108 | key->type = keysym_t::BUILTIN_STRING; |
107 | |
109 | |
108 | if (keymap.size () == keymap.capacity ()) |
110 | if (keymap.size () == keymap.capacity ()) |
109 | keymap.reserve (keymap.size () * 2); |
111 | keymap.reserve (keymap.size () * 2); |
110 | |
112 | |
111 | keymap.push_back (key); |
113 | keymap.push_back (key); |
… | |
… | |
130 | |
132 | |
131 | if (index >= 0) |
133 | if (index >= 0) |
132 | { |
134 | { |
133 | keysym_t *key = keymap [index]; |
135 | keysym_t *key = keymap [index]; |
134 | |
136 | |
|
|
137 | if (key->type == keysym_t::BUILTIN_STRING) |
|
|
138 | { |
|
|
139 | term->tt_write_user_input (kbuf, len); |
|
|
140 | return true; |
|
|
141 | } |
135 | if (key->type != keysym_t::BUILTIN) |
142 | else if (key->type != keysym_t::BUILTIN) |
136 | { |
143 | { |
137 | wchar_t *ws = rxvt_utf8towcs (key->str); |
144 | wchar_t *ws = rxvt_utf8towcs (key->str); |
138 | char *str = rxvt_wcstombs (ws); |
145 | char *str = rxvt_wcstombs (ws); |
139 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
146 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
140 | free (ws); |
147 | free (ws); |
… | |
… | |
143 | { |
150 | { |
144 | if (strncmp (str, "command:", 8) == 0) |
151 | if (strncmp (str, "command:", 8) == 0) |
145 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
152 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
146 | else if (strncmp (str, "string:", 7) == 0) |
153 | else if (strncmp (str, "string:", 7) == 0) |
147 | term->tt_write_user_input (colon + 1, strlen (colon + 1)); |
154 | term->tt_write_user_input (colon + 1, strlen (colon + 1)); |
148 | else if (strncmp (str, "perl:", 8) == 0) |
155 | else if (strncmp (str, "perl:", 5) == 0) |
149 | HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); |
156 | HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); |
150 | else |
157 | else |
151 | HOOK_INVOKE ((term, HOOK_KEYBOARD_DISPATCH, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_END)); |
158 | 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)); |
152 | } |
159 | } |
153 | else |
160 | else |
154 | term->tt_write_user_input (str, strlen (str)); |
161 | term->tt_write_user_input (str, strlen (str)); |
155 | |
162 | |
156 | free (str); |
163 | free (str); |