--- sourceforge.net/trunk/rdesktop/xkeymap.c 2006/03/27 08:17:34 1199 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2007/01/08 04:47:06 1372 @@ -2,14 +2,14 @@ rdesktop: A Remote Desktop Protocol client. User interface services - X keyboard mapping - Copyright (C) Matthew Chapman 1999-2005 - Copyright (C) Peter Astrand 2003 - + Copyright (C) Matthew Chapman 1999-2007 + Copyright (C) Peter Astrand 2003-2007 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -46,17 +46,17 @@ extern int g_keyboard_subtype; extern int g_keyboard_functionkeys; extern int g_win_button_size; -extern BOOL g_enable_compose; -extern BOOL g_use_rdp5; -extern BOOL g_numlock_sync; +extern RD_BOOL g_enable_compose; +extern RD_BOOL g_use_rdp5; +extern RD_BOOL g_numlock_sync; -static BOOL keymap_loaded; +static RD_BOOL keymap_loaded; static key_translation *keymap[KEYMAP_SIZE]; static int min_keycode; static uint16 remote_modifier_state = 0; static uint16 saved_remote_modifier_state = 0; -static void update_modifier_state(uint8 scancode, BOOL pressed); +static void update_modifier_state(uint8 scancode, RD_BOOL pressed); /* Free key_translation structure, including linked list */ static void @@ -159,7 +159,7 @@ DEBUG_KBD(("\n")); } -BOOL +RD_BOOL xkeymap_from_locale(const char *locale) { char *str, *ptr; @@ -206,9 +206,11 @@ { fclose(fp); STRNCPY(g_keymapname, str, sizeof(g_keymapname)); + xfree(str); return True; } + xfree(str); return False; } @@ -273,7 +275,7 @@ return NULL; } -static BOOL +static RD_BOOL xkeymap_read(char *mapname) { FILE *fp; @@ -453,7 +455,7 @@ } static void -send_winkey(uint32 ev_time, BOOL pressed, BOOL leftkey) +send_winkey(uint32 ev_time, RD_BOOL pressed, RD_BOOL leftkey) { uint8 winkey; @@ -502,8 +504,8 @@ } /* Handle special key combinations */ -BOOL -handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed) +RD_BOOL +handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, RD_BOOL pressed) { switch (keysym) { @@ -612,30 +614,35 @@ tr = *ptr; if (tr.seq_keysym == 0) /* Normal scancode translation */ { - if (tr.modifiers & MapInhibitMask) + if (MASK_HAS_BITS(tr.modifiers, MapInhibitMask)) { DEBUG_KBD(("Inhibiting key\n")); tr.scancode = 0; return tr; } - if (tr.modifiers & MapLocalStateMask) + if (MASK_HAS_BITS(tr.modifiers, MapLocalStateMask)) { /* The modifiers to send for this key should be obtained from the local state. Currently, only shift is implemented. */ - if (state & ShiftMask) + if (MASK_HAS_BITS(state, ShiftMask)) { tr.modifiers = MapLeftShiftMask; } } - if ((tr.modifiers & MapLeftShiftMask) - && ((remote_modifier_state & MapLeftCtrlMask) - || (remote_modifier_state & MapRightCtrlMask)) - && get_key_state(state, XK_Caps_Lock)) + /* Windows interprets CapsLock+Ctrl+key + differently from Shift+Ctrl+key. Since we + are simulating CapsLock with Shifts, things + like Ctrl+f with CapsLock on breaks. To + solve this, we are releasing Shift if Ctrl + is on, but only if Shift isn't physically pressed. */ + if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) + && MASK_HAS_BITS(remote_modifier_state, MapCtrlMask) + && !MASK_HAS_BITS(state, ShiftMask)) { - DEBUG_KBD(("CapsLock + Ctrl pressed, releasing LeftShift\n")); - tr.modifiers ^= MapLeftShiftMask; + DEBUG_KBD(("Non-physical Shift + Ctrl pressed, releasing Shift\n")); + MASK_REMOVE_BITS(tr.modifiers, MapShiftMask); } DEBUG_KBD(("Found scancode translation, scancode=0x%x, modifiers=0x%x\n", @@ -656,7 +663,7 @@ /* The modifiers to send for this key should be obtained from the local state. Currently, only shift is implemented. */ - if (state & ShiftMask) + if (MASK_HAS_BITS(state, ShiftMask)) { tr.modifiers = MapLeftShiftMask; } @@ -674,7 +681,7 @@ void xkeymap_send_keys(uint32 keysym, unsigned int keycode, unsigned int state, uint32 ev_time, - BOOL pressed, uint8 nesting) + RD_BOOL pressed, uint8 nesting) { key_translation tr, *ptr; tr = xkeymap_translate_key(keysym, keycode, state); @@ -755,7 +762,7 @@ return ksname; } -static BOOL +static RD_BOOL is_modifier(uint8 scancode) { switch (scancode) @@ -949,7 +956,7 @@ static void -update_modifier_state(uint8 scancode, BOOL pressed) +update_modifier_state(uint8 scancode, RD_BOOL pressed) { #ifdef WITH_DEBUG_KBD uint16 old_modifier_state; @@ -988,7 +995,7 @@ modifier state only on Keypress */ if (pressed && !g_numlock_sync) { - BOOL newNumLockState; + RD_BOOL newNumLockState; newNumLockState = (MASK_HAS_BITS (remote_modifier_state, MapNumLockMask) == False);