ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/keyboard.C
(Generate patch)

Comparing rxvt-unicode/src/keyboard.C (file contents):
Revision 1.64 by sf-exg, Tue Apr 29 13:10:06 2014 UTC vs.
Revision 1.73 by sf-exg, Tue Oct 13 08:10:43 2015 UTC

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
93void 94void
95keyboard_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
112void
94keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) 113keyboard_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;
126 else if (strncmp (action, "builtin-string:", 15) == 0)
127 key->type = keysym_t::BUILTIN_STRING;
128
129 unregister_action (keysym, state);
107 130
108 if (keymap.size () == keymap.capacity ()) 131 if (keymap.size () == keymap.capacity ())
109 keymap.reserve (keymap.size () * 2); 132 keymap.reserve (keymap.size () * 2);
110 133
111 keymap.push_back (key); 134 keymap.push_back (key);
112 hash[0] = 3; 135 hash[0] = 3;
113} 136}
114 137
115bool 138keysym_t *
116keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state, const char *kbuf, int len) 139keyboard_manager::lookup_keysym (rxvt_term *term, KeySym keysym, unsigned int state)
117{ 140{
118 assert (("register_done() need to be called", hash[0] == 0)); 141 assert (("register_done() need to be called", hash[0] == 0));
119 142
120 state &= OtherModMask; // mask out uninteresting modifiers 143 state &= OtherModMask; // mask out uninteresting modifiers
121 144
126 if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask)) 149 if (!!(term->priv_modes & PrivMode_aplKP) != !!(state & ShiftMask))
127 state |= AppKeypadMask; 150 state |= AppKeypadMask;
128 151
129 int index = find_keysym (keysym, state); 152 int index = find_keysym (keysym, state);
130 153
131 if (index >= 0) 154 return index >= 0 ? keymap [index] : 0;
132 { 155}
133 keysym_t *key = keymap [index];
134 156
157bool
158keyboard_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 {
164 if (key->type == keysym_t::BUILTIN_STRING)
165 {
166 term->tt_write_user_input (kbuf, len);
167 return true;
168 }
135 if (key->type != keysym_t::BUILTIN) 169 else if (key->type != keysym_t::BUILTIN)
136 { 170 {
137 wchar_t *ws = rxvt_utf8towcs (key->str); 171 wchar_t *ws = rxvt_utf8towcs (key->str);
138 char *str = rxvt_wcstombs (ws); 172 char *str = rxvt_wcstombs (ws);
139 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 173 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
140 free (ws); 174 free (ws);
143 { 177 {
144 if (strncmp (str, "command:", 8) == 0) 178 if (strncmp (str, "command:", 8) == 0)
145 term->cmdbuf_append (str + 8, strlen (str) - 8); 179 term->cmdbuf_append (str + 8, strlen (str) - 8);
146 else if (strncmp (str, "string:", 7) == 0) 180 else if (strncmp (str, "string:", 7) == 0)
147 term->tt_write_user_input (colon + 1, strlen (colon + 1)); 181 term->tt_write_user_input (colon + 1, strlen (colon + 1));
148 else if (strncmp (str, "perl:", 8) == 0) 182 else if (strncmp (str, "perl:", 5) == 0)
149 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));
150 else 184 else
151 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));
152 } 186 }
153 else 187 else
154 term->tt_write_user_input (str, strlen (str)); 188 term->tt_write_user_input (str, strlen (str));
155 189
156 free (str); 190 free (str);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines