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.52 by sf-exg, Fri Dec 2 09:02:05 2011 UTC vs.
Revision 1.58 by sf-exg, Thu Jan 19 13:33:43 2012 UTC

24#include "../config.h" 24#include "../config.h"
25#include "rxvt.h" 25#include "rxvt.h"
26 26
27#ifdef KEYSYM_RESOURCE 27#ifdef KEYSYM_RESOURCE
28 28
29#include <cstring> 29#include <string.h>
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.
112void 109void
113keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) 110keyboard_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 if (strncmp (translation, "list", 4) == 0 && translation [4]
118 && strlen (translation) < STRING_MAX)
119 {
120 char *prefix = translation + 4;
121 char *middle = strchr (prefix + 1, translation [4]);
122 char *suffix = strrchr (prefix + 1, translation [4]);
123
124 if (suffix && middle && suffix > middle + 1)
125 {
126 int range = suffix - middle - 1;
127 int prefix_len = middle - prefix - 1;
128 char buf[STRING_MAX];
129
130 memcpy (buf, prefix + 1, prefix_len);
131 strcpy (buf + prefix_len + 1, suffix + 1);
132
133 for (int i = 0; i < range; i++)
134 {
135 buf [prefix_len] = middle [i + 1];
136 register_translation (keysym + i, state, strdup (buf));
137 }
138
139 free (translation);
140 return;
141 }
142 else
143 rxvt_warn ("unable to parse list-type keysym '%s', processing as normal keysym.\n", translation);
144 }
145
146 register_translation (keysym, state, translation);
147}
148
149void
150keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation)
151{
152 keysym_t *key = new keysym_t; 114 keysym_t *key = new keysym_t;
153 115
154 if (key && translation)
155 {
156 key->keysym = keysym; 116 key->keysym = keysym;
157 key->state = state; 117 key->state = state;
158 key->str = translation; 118 key->str = translation;
159 key->type = keysym_t::STRING; 119 key->type = keysym_t::STRING;
160 120
161 if (strncmp (translation, "builtin:", 8) == 0) 121 if (strncmp (translation, "builtin:", 8) == 0)
162 key->type = keysym_t::BUILTIN; 122 key->type = keysym_t::BUILTIN;
163 123
164 if (keymap.size () == keymap.capacity ()) 124 if (keymap.size () == keymap.capacity ())
165 keymap.reserve (keymap.size () * 2); 125 keymap.reserve (keymap.size () * 2);
166 126
167 keymap.push_back (key); 127 keymap.push_back (key);
168 hash[0] = 3; 128 hash[0] = 3;
169 }
170 else
171 {
172 delete key;
173 free (translation);
174 rxvt_fatal ("memory allocation failure. aborting.\n");
175 }
176} 129}
177 130
178bool 131bool
179keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state) 132keyboard_manager::dispatch (rxvt_term *term, KeySym keysym, unsigned int state)
180{ 133{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines