--- sourceforge.net/trunk/rdesktop/xkeymap.c 2002/07/30 07:18:48 82 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2002/09/11 09:52:30 115 @@ -41,6 +41,8 @@ static int min_keycode; static uint16 remote_modifier_state = 0; +static void update_modifier_state(uint16 modifiers, BOOL pressed); + static void add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) { @@ -53,8 +55,8 @@ return; } - DEBUG_KBD("Adding translation, keysym=0x%x, scancode=0x%x, " - "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers); + DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " + "modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); keymap[keysym & KEYMAP_MASK].scancode = scancode; keymap[keysym & KEYMAP_MASK].modifiers = modifiers; @@ -116,14 +118,14 @@ if (strncmp(line, "map ", 4) == 0) { keylayout = strtol(line + 4, NULL, 16); - DEBUG_KBD("Keylayout 0x%x\n", keylayout); + DEBUG_KBD(("Keylayout 0x%x\n", keylayout)); continue; } /* compose */ if (strncmp(line, "enable_compose", 15) == 0) { - DEBUG_KBD("Enabling compose handling\n"); + DEBUG_KBD(("Enabling compose handling\n")); enable_compose = True; continue; } @@ -242,22 +244,22 @@ if (tr.scancode != 0) { DEBUG_KBD - ("Found key translation, scancode=0x%x, modifiers=0x%x\n", - tr.scancode, tr.modifiers); + (("Found key translation, scancode=0x%x, modifiers=0x%x\n", + tr.scancode, tr.modifiers)); return tr; } - printf("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); + fprintf(stderr, "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)) { tr.scancode = keycode - min_keycode; - printf("Sending guessed scancode 0x%x\n", tr.scancode); + fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); } else { - printf("No good guess for keycode 0x%x found\n", keycode); + fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); } return tr; @@ -307,6 +309,9 @@ case XK_Multi_key: return True; break; + case XK_Num_Lock: + return True; + break; default: break; } @@ -372,30 +377,33 @@ != MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) { /* The remote modifier state is not correct */ - DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n"); + uint16 new_remote_state = 0; + if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) { - /* Needs this modifier. Toggle */ - rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); - rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); + DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); + new_remote_state |= KBD_FLAG_NUMLOCK; } else { - /* Should not use this modifier. Toggle */ - rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); - rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); + 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); + } } static void update_modifier_state(uint16 modifiers, BOOL pressed) { +#ifdef WITH_DEBUG_KBD + uint16 old_modifier_state; + + old_modifier_state = remote_modifier_state; +#endif - DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n", - remote_modifier_state, pressed); switch (modifiers) { case SCANCODE_CHAR_LSHIFT: @@ -436,7 +444,15 @@ } break; } - DEBUG_KBD("After updating modifier_state:0x%x\n", remote_modifier_state); + +#ifdef WITH_DEBUG_KBD + if (old_modifier_state != remote_modifier_state) + { + DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", + old_modifier_state, pressed)); + DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); + } +#endif } @@ -448,14 +464,14 @@ if (scancode & SCANCODE_EXTENDED) { - DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n", - scancode & ~SCANCODE_EXTENDED, flags); + DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n", + scancode & ~SCANCODE_EXTENDED, flags)); rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, scancode & ~SCANCODE_EXTENDED, 0); } else { - DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode, flags); + DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); } }