--- sourceforge.net/trunk/rdesktop/xkeymap.c 2002/09/11 11:11:27 116 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2002/09/17 08:18:41 170 @@ -202,30 +202,52 @@ /* Before connecting and creating UI */ void -xkeymap_init1(void) +xkeymap_init(void) { + unsigned int max_keycode; int i; - /* Zeroing keymap */ - for (i = 0; i < KEYMAP_SIZE; i++) - { - keymap[i].scancode = 0; - keymap[i].modifiers = 0; - } - if (strcmp(keymapname, "none")) - { xkeymap_read(keymapname); - } + XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); } -/* After connecting and creating UI */ -void -xkeymap_init2(void) -{ - unsigned int max_keycode; - XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); +/* Handles, for example, multi-scancode keypresses (which is not + possible via keymap-files) */ +BOOL +handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) +{ + switch (keysym) + { + case XK_Break: /* toggle full screen */ + if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) + { + xwin_toggle_fullscreen(); + return True; + } + break; + + case XK_Meta_L: /* Windows keys */ + case XK_Super_L: + case XK_Hyper_L: + case XK_Meta_R: + case XK_Super_R: + case XK_Hyper_R: + if (pressed) + { + rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); + rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); + } + else + { + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); + } + return True; + break; + } + return False; } @@ -267,6 +289,15 @@ if ((keycode >= min_keycode) && (keycode <= 0x60)) { tr.scancode = keycode - min_keycode; + + /* The modifiers to send for this key should be + obtained from the local state. Currently, only + shift is implemented. */ + if (state & ShiftMask) + { + tr.modifiers = MapLeftShiftMask; + } + fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); } else @@ -345,6 +376,7 @@ { /* Should not use this modifier. Send up. */ rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); } } @@ -388,6 +420,34 @@ } +void +reset_modifier_keys() +{ + /* reset keys */ + uint32 ev_time; + ev_time = time(NULL); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_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(XK_Shift_R)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_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(XK_Control_R)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); + + if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); + + if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && + !get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) + rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); +} + + static void update_modifier_state(uint16 modifiers, BOOL pressed) {