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.41 by sf-exg, Sat Apr 30 18:45:38 2011 UTC vs.
Revision 1.44 by sf-exg, Sun Nov 27 09:07:48 2011 UTC

78// return: priority_of_a - priority_of_b 78// return: priority_of_a - priority_of_b
79static int 79static int
80compare_priority (keysym_t *a, keysym_t *b) 80compare_priority (keysym_t *a, keysym_t *b)
81{ 81{
82 // (the more '1's in state; the less range): the greater priority 82 // (the more '1's in state; the less range): the greater priority
83 int ca = rxvt_popcount (a->state /* & OtherModMask */); 83 int ca = ecb_popcount32 (a->state /* & OtherModMask */);
84 int cb = rxvt_popcount (b->state /* & OtherModMask */); 84 int cb = ecb_popcount32 (b->state /* & OtherModMask */);
85 85
86 if (ca != cb) 86 if (ca != cb)
87 return ca - cb; 87 return ca - cb;
88//else if (a->state != b->state) // this behavior is to be discussed 88//else if (a->state != b->state) // this behavior is to be discussed
89// return b->state - a->state; 89// return b->state - a->state;
116 } 116 }
117 117
118 keymap.clear (); 118 keymap.clear ();
119} 119}
120 120
121// a wrapper for register_keymap, 121// a wrapper for register_translation that converts the input string
122// so that outside codes don't have to know so much details. 122// to utf-8 and expands 'list' syntax.
123//
124// the string 'trans' is copied to an internal managed buffer,
125// so the caller can free memory of 'trans' at any time.
126void 123void
127keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) 124keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans)
128{ 125{
129 keysym_t *key = new keysym_t;
130 wchar_t *wc = rxvt_mbstowcs (trans); 126 wchar_t *wc = rxvt_mbstowcs (trans);
131 char *translation = rxvt_wcstoutf8 (wc); 127 char *translation = rxvt_wcstoutf8 (wc);
132 free (wc); 128 free (wc);
129
130 if (strncmp (translation, "list", 4) == 0 && translation [4]
131 && strlen (translation) < STRING_MAX)
132 {
133 char *prefix = translation + 4;
134 char *middle = strchr (prefix + 1, translation [4]);
135 char *suffix = strrchr (prefix + 1, translation [4]);
136
137 if (suffix && middle && suffix > middle + 1)
138 {
139 int range = suffix - middle - 1;
140 int prefix_len = middle - prefix - 1;
141 char buf[STRING_MAX];
142
143 memcpy (buf, prefix + 1, prefix_len);
144 strcpy (buf + prefix_len + 1, suffix + 1);
145
146 for (int i = 0; i < range; i++)
147 {
148 buf [prefix_len] = middle [i + 1];
149 register_translation (keysym + i, state, strdup (buf));
150 }
151
152 free (translation);
153 return;
154 }
155 else
156 rxvt_warn ("cannot parse list-type keysym '%s', processing as normal keysym.\n", translation);
157 }
158
159 register_translation (keysym, state, translation);
160}
161
162void
163keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation)
164{
165 keysym_t *key = new keysym_t;
133 166
134 if (key && translation) 167 if (key && translation)
135 { 168 {
136 key->keysym = keysym; 169 key->keysym = keysym;
137 key->state = state; 170 key->state = state;
192 wchar_t *wc = rxvt_utf8towcs (key.str); 225 wchar_t *wc = rxvt_utf8towcs (key.str);
193 char *str = rxvt_wcstombs (wc); 226 char *str = rxvt_wcstombs (wc);
194 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) 227 // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.)
195 free (wc); 228 free (wc);
196 229
197 switch (key.type)
198 {
199 case keysym_t::STRING:
200 output_string (term, str); 230 output_string (term, str);
201 break;
202 }
203 231
204 free (str); 232 free (str);
205 233
206 return true; 234 return true;
207 } 235 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines