--- sourceforge.net/trunk/rdesktop/xkeymap.c 2002/10/06 13:25:30 212 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2003/02/20 12:14:13 333 @@ -18,22 +18,27 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef RDP2VNC +#include "vnc/x11stubs.h" +#else #include -#define XK_MISCELLANY -#include +#include +#endif + #include #include #include #include "rdesktop.h" #include "scancodes.h" -#define KEYMAP_SIZE 4096 -#define KEYMAP_MASK (KEYMAP_SIZE - 1) +#define KEYMAP_SIZE 0xffff+1 +#define KEYMAP_MASK 0xffff #define KEYMAP_MAX_LINE_LENGTH 80 extern Display *display; extern char keymapname[16]; extern int keylayout; +extern int win_button_size; extern BOOL enable_compose; static BOOL keymap_loaded; @@ -51,7 +56,7 @@ keysym = XStringToKeysym(keyname); if (keysym == NoSymbol) { - error("Bad keysym %s in keymap %s\n", keyname, mapname); + DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); return; } @@ -69,7 +74,8 @@ xkeymap_read(char *mapname) { FILE *fp; - char line[KEYMAP_MAX_LINE_LENGTH], path[PATH_MAX]; + char line[KEYMAP_MAX_LINE_LENGTH]; + char path[PATH_MAX], inplace_path[PATH_MAX]; unsigned int line_num = 0; unsigned int line_length = 0; char *keyname, *p; @@ -84,8 +90,16 @@ fp = fopen(path, "r"); if (fp == NULL) { - error("Failed to open keymap %s\n", path); - return False; + /* in case we are running from the source tree */ + strcpy(inplace_path, "keymaps/"); + strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/")); + + fp = fopen(inplace_path, "r"); + if (fp == NULL) + { + error("Failed to open keymap %s\n", path); + return False; + } } /* FIXME: More tolerant on white space */ @@ -189,7 +203,7 @@ /* Automatically add uppercase key, with same modifiers plus shift */ for (p = keyname; *p; p++) - *p = toupper(*p); + *p = toupper((int) *p); MASK_ADD_BITS(modifiers, MapLeftShiftMask); add_to_keymap(keyname, scancode, modifiers, mapname); } @@ -205,6 +219,15 @@ xkeymap_init(void) { unsigned int max_keycode; + char *mapname_ptr; + + /* Make keymapname lowercase */ + mapname_ptr = keymapname; + while (*mapname_ptr) + { + *mapname_ptr = tolower((int) *mapname_ptr); + mapname_ptr++; + } if (strcmp(keymapname, "none")) { @@ -222,53 +245,53 @@ { switch (keysym) { - case XK_Break: - case XK_Pause: + case XK_Return: if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)) - && (get_key_state(state, XK_Control_L) || get_key_state(state, XK_Control_R))) + && (get_key_state(state, XK_Control_L) + || get_key_state(state, XK_Control_R))) { - /* Ctrl-Alt-Break: toggle full screen */ + /* Ctrl-Alt-Enter: toggle full screen */ if (pressed) xwin_toggle_fullscreen(); + return True; + } + break; + case XK_Break: + /* Send Break sequence E0 46 E0 C6 */ + if (pressed) + { + rdp_send_scancode(ev_time, RDP_KEYPRESS, + (SCANCODE_EXTENDED | 0x46)); + rdp_send_scancode(ev_time, RDP_KEYPRESS, + (SCANCODE_EXTENDED | 0xc6)); } - else if (keysym == XK_Break) + /* No release sequence */ + return True; + + case XK_Pause: + /* According to MS Keyboard Scan Code + Specification, pressing Pause should result + in E1 1D 45 E1 9D C5. I'm not exactly sure + of how this is supposed to be sent via + RDP. The code below seems to work, but with + the side effect that Left Ctrl stays + down. Therefore, we release it when Pause + is released. */ + if (pressed) { - /* Send Break sequence E0 46 E0 C6 */ - if (pressed) - { - rdp_send_scancode(ev_time, RDP_KEYPRESS, - (SCANCODE_EXTENDED | 0x46)); - rdp_send_scancode(ev_time, RDP_KEYPRESS, - (SCANCODE_EXTENDED | 0xc6)); - } - /* No break sequence */ + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); } - else /* XK_Pause */ + else { - /* According to MS Keyboard Scan Code - Specification, pressing Pause should result - in E1 1D 45 E1 9D C5. I'm not exactly sure - of how this is supposed to be sent via - RDP. The code below seems to work, but with - the side effect that Left Ctrl stays - down. Therefore, we release it when Pause - is released. */ - if (pressed) - { - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); - } - else - { - /* Release Left Ctrl */ - rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, - 0); - } + /* Release Left Ctrl */ + rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, + 0x1d, 0); } return True; @@ -289,6 +312,13 @@ rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); } return True; + + case XK_space: + /* Prevent access to the Windows system menu in single app mode */ + if (win_button_size + && (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) + return True; + } return False; } @@ -326,7 +356,7 @@ } if (keymap_loaded) - error("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); + warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); /* not in keymap, try to interpret the raw scancode */ if ((keycode >= min_keycode) && (keycode <= 0x60)) @@ -405,6 +435,29 @@ break; } + /* NumLock */ + if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) + != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) + { + /* The remote modifier state is not correct */ + uint16 new_remote_state; + + if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) + { + DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); + new_remote_state = KBD_FLAG_NUMLOCK; + remote_modifier_state = MapNumLockMask; + } + else + { + DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); + new_remote_state = 0; + remote_modifier_state = 0; + } + + rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); + } + /* Shift. Left shift and right shift are treated as equal; either is fine. */ if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) != MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) @@ -449,26 +502,7 @@ } } - /* NumLock */ - if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) - != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) - { - /* The remote modifier state is not correct */ - uint16 new_remote_state = 0; - - if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) - { - DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); - new_remote_state |= KBD_FLAG_NUMLOCK; - } - else - { - DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); - } - rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); - update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); - } } @@ -479,16 +513,20 @@ uint32 ev_time; ev_time = time(NULL); - if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(state, XK_Shift_L)) + if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) + && !get_key_state(state, XK_Shift_L)) rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); - if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(state, XK_Shift_R)) + if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) + && !get_key_state(state, XK_Shift_R)) rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); - if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(state, XK_Control_L)) + if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) + && !get_key_state(state, XK_Control_L)) rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); - if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(state, XK_Control_R)) + if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) + && !get_key_state(state, XK_Control_R)) rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(state, XK_Alt_L))