keymaps.c (23ad24e48cf28ac2542ade657efbf7f802d7c8a0) keymaps.c (abb4f2c9655503f14dc55064f29c4f59b07e96ff)
1/*
2 * QEMU keysym to keycode conversion using rdesktop keymaps
3 *
4 * Copyright (c) 2004 Johannes Schindelin
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 162 unchanged lines hidden (view full) ---

171
172kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
173 const char *language)
174{
175 return parse_keyboard_layout(table, language, NULL);
176}
177
178
1/*
2 * QEMU keysym to keycode conversion using rdesktop keymaps
3 *
4 * Copyright (c) 2004 Johannes Schindelin
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 162 unchanged lines hidden (view full) ---

171
172kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
173 const char *language)
174{
175 return parse_keyboard_layout(table, language, NULL);
176}
177
178
179int keysym2scancode(kbd_layout_t *k, int keysym)
179int keysym2scancode(kbd_layout_t *k, int keysym,
180 bool shift, bool altgr, bool ctrl)
180{
181{
182 static const uint32_t mask =
183 SCANCODE_SHIFT | SCANCODE_ALTGR | SCANCODE_CTRL;
184 uint32_t mods, i;
181 struct keysym2code *keysym2code;
182
183#ifdef XK_ISO_Left_Tab
184 if (keysym == XK_ISO_Left_Tab) {
185 keysym = XK_Tab;
186 }
187#endif
188
189 keysym2code = g_hash_table_lookup(k->hash, GINT_TO_POINTER(keysym));
190 if (!keysym2code) {
191 trace_keymap_unmapped(keysym);
192 warn_report("no scancode found for keysym %d", keysym);
193 return 0;
194 }
195
185 struct keysym2code *keysym2code;
186
187#ifdef XK_ISO_Left_Tab
188 if (keysym == XK_ISO_Left_Tab) {
189 keysym = XK_Tab;
190 }
191#endif
192
193 keysym2code = g_hash_table_lookup(k->hash, GINT_TO_POINTER(keysym));
194 if (!keysym2code) {
195 trace_keymap_unmapped(keysym);
196 warn_report("no scancode found for keysym %d", keysym);
197 return 0;
198 }
199
200 if (keysym2code->count == 1) {
201 return keysym2code->keycodes[0];
202 }
203
204 /*
205 * We have multiple keysym -> keycode mappings.
206 *
207 * Check whenever we find one mapping where the modifier state of
208 * the mapping matches the current user interface modifier state.
209 * If so, prefer that one.
210 */
211 mods = 0;
212 if (shift) {
213 mods |= SCANCODE_SHIFT;
214 }
215 if (altgr) {
216 mods |= SCANCODE_ALTGR;
217 }
218 if (ctrl) {
219 mods |= SCANCODE_CTRL;
220 }
221
222 for (i = 0; i < keysym2code->count; i++) {
223 if ((keysym2code->keycodes[i] & mask) == mods) {
224 return keysym2code->keycodes[i];
225 }
226 }
196 return keysym2code->keycodes[0];
197}
198
199int keycode_is_keypad(kbd_layout_t *k, int keycode)
200{
201 if (keycode >= 0x47 && keycode <= 0x53) {
202 return true;
203 }

--- 13 unchanged lines hidden ---
227 return keysym2code->keycodes[0];
228}
229
230int keycode_is_keypad(kbd_layout_t *k, int keycode)
231{
232 if (keycode >= 0x47 && keycode <= 0x53) {
233 return true;
234 }

--- 13 unchanged lines hidden ---