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 |
|
case XK_Num_Lock: |
376 |
|
/* FIXME: We might want to do RDP_INPUT_SYNCHRONIZE here, if g_numlock_sync */ |
377 |
|
if (!g_numlock_sync) |
378 |
|
/* Inhibit */ |
379 |
|
return True; |
380 |
|
break; |
381 |
|
|
382 |
} |
} |
383 |
return False; |
return False; |
408 |
} |
} |
409 |
} |
} |
410 |
|
|
411 |
|
#if 0 |
412 |
|
if (((remote_modifier_state & MapLeftCtrlMask) |
413 |
|
|| (remote_modifier_state & MapRightCtrlMask)) && get_key_state(state, XK_Caps_Lock)) |
414 |
|
{ |
415 |
|
DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n")); |
416 |
|
tr.modifiers ^= MapLeftShiftMask; |
417 |
|
} |
418 |
|
#endif |
419 |
|
|
420 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
421 |
{ |
{ |
422 |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
533 |
if (is_modifier(tr.scancode)) |
if (is_modifier(tr.scancode)) |
534 |
return; |
return; |
535 |
|
|
536 |
/* NumLock */ |
if (!g_numlock_sync) |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
537 |
{ |
{ |
538 |
/* The remote modifier state is not correct */ |
/* NumLock */ |
539 |
uint16 new_remote_state; |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
540 |
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
|
541 |
{ |
{ |
542 |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
/* The remote modifier state is not correct */ |
543 |
new_remote_state = KBD_FLAG_NUMLOCK; |
uint16 new_remote_state; |
544 |
remote_modifier_state = MapNumLockMask; |
|
545 |
} |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
546 |
else |
{ |
547 |
{ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
548 |
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
new_remote_state = KBD_FLAG_NUMLOCK; |
549 |
new_remote_state = 0; |
remote_modifier_state = MapNumLockMask; |
550 |
remote_modifier_state = 0; |
} |
551 |
} |
else |
552 |
|
{ |
553 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
554 |
|
new_remote_state = 0; |
555 |
|
remote_modifier_state = 0; |
556 |
|
} |
557 |
|
|
558 |
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
559 |
|
} |
560 |
} |
} |
561 |
|
|
562 |
|
|
563 |
/* 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. */ |
564 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
565 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
608 |
} |
} |
609 |
|
|
610 |
|
|
611 |
|
unsigned int |
612 |
|
read_keyboard_state() |
613 |
|
{ |
614 |
|
#ifdef RDP2VNC |
615 |
|
return 0; |
616 |
|
#else |
617 |
|
unsigned int state; |
618 |
|
Window wdummy; |
619 |
|
int dummy; |
620 |
|
|
621 |
|
XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
622 |
|
return state; |
623 |
|
#endif |
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
|
uint16 |
628 |
|
ui_get_numlock_state(unsigned int state) |
629 |
|
{ |
630 |
|
uint16 numlock_state = 0; |
631 |
|
|
632 |
|
if (get_key_state(state, XK_Num_Lock)) |
633 |
|
numlock_state = KBD_FLAG_NUMLOCK; |
634 |
|
|
635 |
|
return numlock_state; |
636 |
|
} |
637 |
|
|
638 |
|
|
639 |
void |
void |
640 |
reset_modifier_keys(unsigned int state) |
reset_modifier_keys() |
641 |
{ |
{ |
642 |
|
unsigned int state = read_keyboard_state(); |
643 |
|
|
644 |
/* reset keys */ |
/* reset keys */ |
645 |
uint32 ev_time; |
uint32 ev_time; |
646 |
ev_time = time(NULL); |
ev_time = time(NULL); |
665 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
666 |
|
|
667 |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
668 |
!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) |
669 |
|
&& !get_key_state(state, XK_ISO_Level3_Shift)) |
670 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
671 |
|
|
672 |
|
reset_winkey(ev_time); |
673 |
|
|
674 |
|
if (g_numlock_sync) |
675 |
|
rdp_send_input(ev_time, RDP_INPUT_SYNCHRONIZE, 0, ui_get_numlock_state(state), 0); |
676 |
} |
} |
677 |
|
|
678 |
|
|
714 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
715 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
716 |
modifier state only on Keypress */ |
modifier state only on Keypress */ |
717 |
if (pressed) |
if (pressed && !g_numlock_sync) |
718 |
{ |
{ |
719 |
BOOL newNumLockState; |
BOOL newNumLockState; |
720 |
newNumLockState = |
newNumLockState = |
723 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
724 |
MapNumLockMask, newNumLockState); |
MapNumLockMask, newNumLockState); |
725 |
} |
} |
|
break; |
|
726 |
} |
} |
727 |
|
|
728 |
#ifdef WITH_DEBUG_KBD |
#ifdef WITH_DEBUG_KBD |