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.68 by root, Sat May 17 15:25:04 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_action (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;
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
117bool 138keysym_t *
118keyboard_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)
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
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 {
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 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines