38 |
extern BOOL enable_compose; |
extern BOOL enable_compose; |
39 |
|
|
40 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
41 |
static unsigned int min_keycode; |
static int min_keycode; |
42 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
43 |
|
|
44 |
|
static void update_modifier_state(uint16 modifiers, BOOL pressed); |
45 |
|
|
46 |
static void |
static void |
47 |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
48 |
{ |
{ |
55 |
return; |
return; |
56 |
} |
} |
57 |
|
|
58 |
DEBUG_KBD("Adding translation, keysym=0x%x, scancode=0x%x, " |
DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " |
59 |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); |
|
modifiers); |
|
60 |
|
|
61 |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
62 |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
118 |
if (strncmp(line, "map ", 4) == 0) |
if (strncmp(line, "map ", 4) == 0) |
119 |
{ |
{ |
120 |
keylayout = strtol(line + 4, NULL, 16); |
keylayout = strtol(line + 4, NULL, 16); |
121 |
DEBUG_KBD("Keylayout 0x%x\n", keylayout); |
DEBUG_KBD(("Keylayout 0x%x\n", keylayout)); |
122 |
continue; |
continue; |
123 |
} |
} |
124 |
|
|
125 |
/* compose */ |
/* compose */ |
126 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
127 |
{ |
{ |
128 |
DEBUG_KBD("Enabling compose handling\n"); |
DEBUG_KBD(("Enabling compose handling\n")); |
129 |
enable_compose = True; |
enable_compose = True; |
130 |
continue; |
continue; |
131 |
} |
} |
141 |
p = strchr(line, ' '); |
p = strchr(line, ' '); |
142 |
if (p == NULL) |
if (p == NULL) |
143 |
{ |
{ |
144 |
error("Bad line %d in keymap %s\n", line_num, |
error("Bad line %d in keymap %s\n", line_num, mapname); |
|
mapname); |
|
145 |
continue; |
continue; |
146 |
} |
} |
147 |
else |
else |
177 |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
178 |
} |
} |
179 |
|
|
180 |
|
if (strstr(line_rest, "inhibit")) |
181 |
|
{ |
182 |
|
MASK_ADD_BITS(modifiers, MapInhibitMask); |
183 |
|
} |
184 |
|
|
185 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
186 |
|
|
187 |
if (strstr(line_rest, "addupper")) |
if (strstr(line_rest, "addupper")) |
202 |
|
|
203 |
/* Before connecting and creating UI */ |
/* Before connecting and creating UI */ |
204 |
void |
void |
205 |
xkeymap_init1(void) |
xkeymap_init(void) |
206 |
{ |
{ |
207 |
|
unsigned int max_keycode; |
208 |
int i; |
int i; |
209 |
|
|
|
/* Zeroing keymap */ |
|
|
for (i = 0; i < KEYMAP_SIZE; i++) |
|
|
{ |
|
|
keymap[i].scancode = 0; |
|
|
keymap[i].modifiers = 0; |
|
|
} |
|
|
|
|
210 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
|
{ |
|
211 |
xkeymap_read(keymapname); |
xkeymap_read(keymapname); |
|
} |
|
212 |
|
|
213 |
|
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
214 |
} |
} |
215 |
|
|
216 |
/* After connecting and creating UI */ |
/* Handles, for example, multi-scancode keypresses (which is not |
217 |
void |
possible via keymap-files) */ |
218 |
xkeymap_init2(void) |
BOOL |
219 |
|
handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) |
220 |
{ |
{ |
221 |
unsigned int max_keycode; |
switch (keysym) |
222 |
XDisplayKeycodes(display, &min_keycode, &max_keycode); |
{ |
223 |
|
case XK_Break: /* toggle full screen */ |
224 |
|
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
225 |
|
{ |
226 |
|
xwin_toggle_fullscreen(); |
227 |
|
return True; |
228 |
|
} |
229 |
|
break; |
230 |
|
|
231 |
|
case XK_Meta_L: /* Windows keys */ |
232 |
|
case XK_Super_L: |
233 |
|
case XK_Hyper_L: |
234 |
|
case XK_Meta_R: |
235 |
|
case XK_Super_R: |
236 |
|
case XK_Hyper_R: |
237 |
|
if (pressed) |
238 |
|
{ |
239 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
240 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
241 |
|
} |
242 |
|
else |
243 |
|
{ |
244 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
245 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
246 |
|
} |
247 |
|
return True; |
248 |
|
break; |
249 |
|
} |
250 |
|
return False; |
251 |
} |
} |
252 |
|
|
253 |
|
|
258 |
|
|
259 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
260 |
|
|
261 |
|
if (tr.modifiers & MapInhibitMask) |
262 |
|
{ |
263 |
|
DEBUG_KBD(("Inhibiting key\n")); |
264 |
|
tr.scancode = 0; |
265 |
|
return tr; |
266 |
|
} |
267 |
|
|
268 |
if (tr.modifiers & MapLocalStateMask) |
if (tr.modifiers & MapLocalStateMask) |
269 |
{ |
{ |
270 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
278 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
279 |
{ |
{ |
280 |
DEBUG_KBD |
DEBUG_KBD |
281 |
("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
282 |
tr.scancode, tr.modifiers); |
tr.scancode, tr.modifiers)); |
283 |
return tr; |
return tr; |
284 |
} |
} |
285 |
|
|
286 |
printf("No translation for (keysym 0x%lx, %s)\n", keysym, |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
|
get_ksname(keysym)); |
|
287 |
|
|
288 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
289 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
290 |
{ |
{ |
291 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
292 |
printf("Sending guessed scancode 0x%x\n", tr.scancode); |
|
293 |
|
/* The modifiers to send for this key should be |
294 |
|
obtained from the local state. Currently, only |
295 |
|
shift is implemented. */ |
296 |
|
if (state & ShiftMask) |
297 |
|
{ |
298 |
|
tr.modifiers = MapLeftShiftMask; |
299 |
|
} |
300 |
|
|
301 |
|
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
302 |
} |
} |
303 |
else |
else |
304 |
{ |
{ |
305 |
printf("No good guess for keycode 0x%x found\n", keycode); |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
306 |
} |
} |
307 |
|
|
308 |
return tr; |
return tr; |
341 |
return ksname; |
return ksname; |
342 |
} |
} |
343 |
|
|
|
BOOL |
|
|
inhibit_key(KeySym keysym) |
|
|
{ |
|
|
switch (keysym) |
|
|
{ |
|
|
case XK_Caps_Lock: |
|
|
return True; |
|
|
break; |
|
|
case XK_Multi_key: |
|
|
return True; |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
return False; |
|
|
} |
|
344 |
|
|
345 |
void |
void |
346 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
370 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
371 |
{ |
{ |
372 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
373 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
374 |
} |
} |
375 |
else |
else |
376 |
{ |
{ |
377 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
378 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
379 |
SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
380 |
} |
} |
381 |
} |
} |
382 |
|
|
388 |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
389 |
{ |
{ |
390 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
391 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
392 |
} |
} |
393 |
else |
else |
394 |
{ |
{ |
395 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
396 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
397 |
} |
} |
398 |
} |
} |
399 |
|
|
402 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
403 |
{ |
{ |
404 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
405 |
DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n"); |
uint16 new_remote_state = 0; |
406 |
|
|
407 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
408 |
{ |
{ |
409 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
410 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
new_remote_state |= KBD_FLAG_NUMLOCK; |
|
SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
411 |
} |
} |
412 |
else |
else |
413 |
{ |
{ |
414 |
/* Should not use this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
415 |
} |
} |
416 |
|
|
417 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
418 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
419 |
} |
} |
420 |
|
} |
421 |
|
|
422 |
|
|
423 |
|
void |
424 |
|
reset_modifier_keys() |
425 |
|
{ |
426 |
|
/* reset keys */ |
427 |
|
uint32 ev_time; |
428 |
|
ev_time = time(NULL); |
429 |
|
|
430 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
431 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
432 |
|
|
433 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
434 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
435 |
|
|
436 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
437 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
438 |
|
|
439 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
440 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
441 |
|
|
442 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) |
443 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
444 |
|
|
445 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
446 |
|
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
447 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
448 |
} |
} |
449 |
|
|
450 |
|
|
451 |
static void |
static void |
452 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
453 |
{ |
{ |
454 |
|
#ifdef WITH_DEBUG_KBD |
455 |
|
uint16 old_modifier_state; |
456 |
|
|
457 |
|
old_modifier_state = remote_modifier_state; |
458 |
|
#endif |
459 |
|
|
|
DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed); |
|
460 |
switch (modifiers) |
switch (modifiers) |
461 |
{ |
{ |
462 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
463 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
|
MapLeftShiftMask, pressed); |
|
464 |
break; |
break; |
465 |
case SCANCODE_CHAR_RSHIFT: |
case SCANCODE_CHAR_RSHIFT: |
466 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed); |
|
MapRightShiftMask, pressed); |
|
467 |
break; |
break; |
468 |
case SCANCODE_CHAR_LCTRL: |
case SCANCODE_CHAR_LCTRL: |
469 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed); |
|
MapLeftCtrlMask, pressed); |
|
470 |
break; |
break; |
471 |
case SCANCODE_CHAR_RCTRL: |
case SCANCODE_CHAR_RCTRL: |
472 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed); |
|
MapRightCtrlMask, pressed); |
|
473 |
break; |
break; |
474 |
case SCANCODE_CHAR_LALT: |
case SCANCODE_CHAR_LALT: |
475 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed); |
|
pressed); |
|
476 |
break; |
break; |
477 |
case SCANCODE_CHAR_RALT: |
case SCANCODE_CHAR_RALT: |
478 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed); |
|
MapRightAltMask, pressed); |
|
479 |
break; |
break; |
480 |
case SCANCODE_CHAR_LWIN: |
case SCANCODE_CHAR_LWIN: |
481 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed); |
|
pressed); |
|
482 |
break; |
break; |
483 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
484 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
|
MapRightWinMask, pressed); |
|
485 |
break; |
break; |
486 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
487 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
491 |
BOOL newNumLockState; |
BOOL newNumLockState; |
492 |
newNumLockState = |
newNumLockState = |
493 |
(MASK_HAS_BITS |
(MASK_HAS_BITS |
494 |
(remote_modifier_state, |
(remote_modifier_state, MapNumLockMask) == False); |
|
MapNumLockMask) == False); |
|
495 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
496 |
MapNumLockMask, |
MapNumLockMask, newNumLockState); |
|
newNumLockState); |
|
497 |
} |
} |
498 |
break; |
break; |
499 |
} |
} |
500 |
DEBUG_KBD("After updating modifier_state:0x%x\n", |
|
501 |
remote_modifier_state); |
#ifdef WITH_DEBUG_KBD |
502 |
|
if (old_modifier_state != remote_modifier_state) |
503 |
|
{ |
504 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
505 |
|
old_modifier_state, pressed)); |
506 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
507 |
|
} |
508 |
|
#endif |
509 |
|
|
510 |
} |
} |
511 |
|
|
517 |
|
|
518 |
if (scancode & SCANCODE_EXTENDED) |
if (scancode & SCANCODE_EXTENDED) |
519 |
{ |
{ |
520 |
DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n", |
DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n", |
521 |
scancode & ~SCANCODE_EXTENDED, flags); |
scancode & ~SCANCODE_EXTENDED, flags)); |
522 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
523 |
scancode & ~SCANCODE_EXTENDED, 0); |
scancode & ~SCANCODE_EXTENDED, 0); |
524 |
} |
} |
525 |
else |
else |
526 |
{ |
{ |
527 |
DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode, |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
|
flags); |
|
528 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
529 |
} |
} |
530 |
} |
} |