… | |
… | |
28 | |
28 | |
29 | #include <cstring> |
29 | #include <cstring> |
30 | |
30 | |
31 | #include "rxvtperl.h" |
31 | #include "rxvtperl.h" |
32 | #include "keyboard.h" |
32 | #include "keyboard.h" |
33 | #include "command.h" |
|
|
34 | |
33 | |
35 | /* an intro to the data structure: |
34 | /* an intro to the data structure: |
36 | * |
35 | * |
37 | * vector keymap[] is grouped. |
36 | * vector keymap[] is grouped. |
38 | * |
37 | * |
… | |
… | |
105 | free (keymap [i]->str); |
104 | free (keymap [i]->str); |
106 | delete keymap [i]; |
105 | delete keymap [i]; |
107 | } |
106 | } |
108 | } |
107 | } |
109 | |
108 | |
110 | // a wrapper for register_translation that converts the input string |
|
|
111 | // to utf-8 and expands 'list' syntax. |
|
|
112 | void |
109 | void |
113 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
110 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
114 | { |
111 | { |
115 | char *translation = rxvt_wcstoutf8 (ws); |
112 | char *translation = rxvt_wcstoutf8 (ws); |
116 | |
113 | |
117 | register_translation (keysym, state, translation); |
|
|
118 | } |
|
|
119 | |
|
|
120 | void |
|
|
121 | keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation) |
|
|
122 | { |
|
|
123 | keysym_t *key = new keysym_t; |
114 | keysym_t *key = new keysym_t; |
124 | |
115 | |
125 | if (key && translation) |
|
|
126 | { |
|
|
127 | key->keysym = keysym; |
116 | key->keysym = keysym; |
128 | key->state = state; |
117 | key->state = state; |
129 | key->str = translation; |
118 | key->str = translation; |
130 | key->type = keysym_t::STRING; |
119 | key->type = keysym_t::STRING; |
131 | |
120 | |
132 | if (strncmp (translation, "builtin:", 8) == 0) |
121 | if (strncmp (translation, "builtin:", 8) == 0) |
133 | key->type = keysym_t::BUILTIN; |
122 | key->type = keysym_t::BUILTIN; |
134 | |
123 | |
135 | if (keymap.size () == keymap.capacity ()) |
124 | if (keymap.size () == keymap.capacity ()) |
136 | keymap.reserve (keymap.size () * 2); |
125 | keymap.reserve (keymap.size () * 2); |
137 | |
126 | |
138 | keymap.push_back (key); |
127 | keymap.push_back (key); |
139 | hash[0] = 3; |
128 | hash[0] = 3; |
140 | } |
|
|
141 | else |
|
|
142 | { |
|
|
143 | delete key; |
|
|
144 | free (translation); |
|
|
145 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
146 | } |
|
|
147 | } |
129 | } |
148 | |
130 | |
149 | bool |
131 | bool |
150 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
132 | keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) |
151 | { |
133 | { |