2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X keyboard mapping |
User interface services - X keyboard mapping |
4 |
|
|
5 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2005 |
6 |
Copyright (C) Peter Astrand <peter@cendio.se> 2003 |
Copyright (C) Peter Astrand <peter@cendio.se> 2003 |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
38 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
39 |
|
|
40 |
extern Display *g_display; |
extern Display *g_display; |
41 |
|
extern Window g_wnd; |
42 |
extern char keymapname[16]; |
extern char keymapname[16]; |
43 |
extern int keylayout; |
extern int g_keylayout; |
44 |
extern int g_win_button_size; |
extern int g_win_button_size; |
45 |
extern BOOL g_enable_compose; |
extern BOOL g_enable_compose; |
46 |
extern BOOL g_use_rdp5; |
extern BOOL g_use_rdp5; |
47 |
|
extern BOOL g_numlock_sync; |
48 |
|
|
49 |
static BOOL keymap_loaded; |
static BOOL keymap_loaded; |
50 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
137 |
/* map */ |
/* map */ |
138 |
if (strncmp(line, "map ", 4) == 0) |
if (strncmp(line, "map ", 4) == 0) |
139 |
{ |
{ |
140 |
keylayout = strtol(line + 4, NULL, 16); |
g_keylayout = strtol(line + 4, NULL, 16); |
141 |
DEBUG_KBD(("Keylayout 0x%x\n", keylayout)); |
DEBUG_KBD(("Keylayout 0x%x\n", g_keylayout)); |
142 |
continue; |
continue; |
143 |
} |
} |
144 |
|
|
282 |
} |
} |
283 |
} |
} |
284 |
|
|
285 |
|
static void |
286 |
|
reset_winkey(uint32 ev_time) |
287 |
|
{ |
288 |
|
if (g_use_rdp5) |
289 |
|
{ |
290 |
|
/* For some reason, it seems to suffice to release |
291 |
|
*either* the left or right winkey. */ |
292 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LWIN); |
293 |
|
} |
294 |
|
} |
295 |
|
|
296 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
297 |
possible via keymap-files) */ |
possible via keymap-files) */ |
298 |
BOOL |
BOOL |
323 |
} |
} |
324 |
/* No release sequence */ |
/* No release sequence */ |
325 |
return True; |
return True; |
326 |
|
break; |
327 |
|
|
328 |
case XK_Pause: |
case XK_Pause: |
329 |
/* According to MS Keyboard Scan Code |
/* According to MS Keyboard Scan Code |
350 |
0x1d, 0); |
0x1d, 0); |
351 |
} |
} |
352 |
return True; |
return True; |
353 |
|
break; |
354 |
|
|
355 |
case XK_Meta_L: /* Windows keys */ |
case XK_Meta_L: /* Windows keys */ |
356 |
case XK_Super_L: |
case XK_Super_L: |
357 |
case XK_Hyper_L: |
case XK_Hyper_L: |
358 |
send_winkey(ev_time, pressed, True); |
send_winkey(ev_time, pressed, True); |
359 |
return True; |
return True; |
360 |
|
break; |
361 |
|
|
362 |
case XK_Meta_R: |
case XK_Meta_R: |
363 |
case XK_Super_R: |
case XK_Super_R: |
364 |
case XK_Hyper_R: |
case XK_Hyper_R: |
365 |
send_winkey(ev_time, pressed, False); |
send_winkey(ev_time, pressed, False); |
366 |
return True; |
return True; |
367 |
|
break; |
368 |
|
|
369 |
case XK_space: |
case XK_space: |
370 |
/* Prevent access to the Windows system menu in single app mode */ |
/* Prevent access to the Windows system menu in single app mode */ |
371 |
if (g_win_button_size |
if (g_win_button_size |
372 |
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
373 |
return True; |
return True; |
374 |
|
break; |
375 |
|
|
376 |
|
case XK_Num_Lock: |
377 |
|
/* Synchronize on key release */ |
378 |
|
if (g_numlock_sync && !pressed) |
379 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, |
380 |
|
ui_get_numlock_state(read_keyboard_state()), 0); |
381 |
|
|
382 |
|
/* Inhibit */ |
383 |
|
return True; |
384 |
|
break; |
385 |
|
|
386 |
} |
} |
387 |
return False; |
return False; |
412 |
} |
} |
413 |
} |
} |
414 |
|
|
415 |
|
if ((tr.modifiers & MapLeftShiftMask) && ((remote_modifier_state & MapLeftCtrlMask) |
416 |
|
|| (remote_modifier_state & MapRightCtrlMask)) |
417 |
|
&& get_key_state(state, XK_Caps_Lock)) |
418 |
|
{ |
419 |
|
DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n")); |
420 |
|
tr.modifiers ^= MapLeftShiftMask; |
421 |
|
} |
422 |
|
|
423 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
424 |
{ |
{ |
425 |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
536 |
if (is_modifier(tr.scancode)) |
if (is_modifier(tr.scancode)) |
537 |
return; |
return; |
538 |
|
|
539 |
/* NumLock */ |
if (!g_numlock_sync) |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
540 |
{ |
{ |
541 |
/* The remote modifier state is not correct */ |
/* NumLock */ |
542 |
uint16 new_remote_state; |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
543 |
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
|
544 |
{ |
{ |
545 |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
/* The remote modifier state is not correct */ |
546 |
new_remote_state = KBD_FLAG_NUMLOCK; |
uint16 new_remote_state; |
|
remote_modifier_state = MapNumLockMask; |
|
|
} |
|
|
else |
|
|
{ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
|
|
new_remote_state = 0; |
|
|
remote_modifier_state = 0; |
|
|
} |
|
547 |
|
|
548 |
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
549 |
|
{ |
550 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
551 |
|
new_remote_state = KBD_FLAG_NUMLOCK; |
552 |
|
remote_modifier_state = MapNumLockMask; |
553 |
|
} |
554 |
|
else |
555 |
|
{ |
556 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
557 |
|
new_remote_state = 0; |
558 |
|
remote_modifier_state = 0; |
559 |
|
} |
560 |
|
|
561 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
562 |
|
} |
563 |
} |
} |
564 |
|
|
565 |
|
|
566 |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
567 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
568 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
611 |
} |
} |
612 |
|
|
613 |
|
|
614 |
|
unsigned int |
615 |
|
read_keyboard_state() |
616 |
|
{ |
617 |
|
#ifdef RDP2VNC |
618 |
|
return 0; |
619 |
|
#else |
620 |
|
unsigned int state; |
621 |
|
Window wdummy; |
622 |
|
int dummy; |
623 |
|
|
624 |
|
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
625 |
|
return state; |
626 |
|
#endif |
627 |
|
} |
628 |
|
|
629 |
|
|
630 |
|
uint16 |
631 |
|
ui_get_numlock_state(unsigned int state) |
632 |
|
{ |
633 |
|
uint16 numlock_state = 0; |
634 |
|
|
635 |
|
if (get_key_state(state, XK_Num_Lock)) |
636 |
|
numlock_state = KBD_FLAG_NUMLOCK; |
637 |
|
|
638 |
|
return numlock_state; |
639 |
|
} |
640 |
|
|
641 |
|
|
642 |
void |
void |
643 |
reset_modifier_keys(unsigned int state) |
reset_modifier_keys() |
644 |
{ |
{ |
645 |
|
unsigned int state = read_keyboard_state(); |
646 |
|
|
647 |
/* reset keys */ |
/* reset keys */ |
648 |
uint32 ev_time; |
uint32 ev_time; |
649 |
ev_time = time(NULL); |
ev_time = time(NULL); |
668 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
669 |
|
|
670 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
671 |
!get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch)) |
!get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch) |
672 |
|
&& !get_key_state(state, XK_ISO_Level3_Shift)) |
673 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
674 |
|
|
675 |
|
reset_winkey(ev_time); |
676 |
|
|
677 |
|
if (g_numlock_sync) |
678 |
|
rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0); |
679 |
} |
} |
680 |
|
|
681 |
|
|
717 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
718 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
719 |
modifier state only on Keypress */ |
modifier state only on Keypress */ |
720 |
if (pressed) |
if (pressed && !g_numlock_sync) |
721 |
{ |
{ |
722 |
BOOL newNumLockState; |
BOOL newNumLockState; |
723 |
newNumLockState = |
newNumLockState = |
726 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
727 |
MapNumLockMask, newNumLockState); |
MapNumLockMask, newNumLockState); |
728 |
} |
} |
|
break; |
|
729 |
} |
} |
730 |
|
|
731 |
#ifdef WITH_DEBUG_KBD |
#ifdef WITH_DEBUG_KBD |