diff options
author | marha <marha@users.sourceforge.net> | 2012-03-26 14:23:28 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-03-26 14:23:28 +0200 |
commit | 76bcc36ed305418a3ddc5752d287ede894243e1b (patch) | |
tree | bacb320c825768471ce56f058f17ce863d592376 /xorg-server/hw/xwin/winkeybd.c | |
parent | 7d894e32566b710952c44cbc71939ad1d9e2fa8d (diff) | |
parent | 0f834b91a4768673833ab4917e87d86c237bb1a6 (diff) | |
download | vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.gz vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.tar.bz2 vcxsrv-76bcc36ed305418a3ddc5752d287ede894243e1b.zip |
Merge remote-tracking branch 'origin/released'
Conflicts:
pixman/pixman/pixman-mmx.c
xorg-server/Xext/shm.c
xorg-server/Xext/syncsrv.h
xorg-server/Xext/xvmain.c
xorg-server/Xi/exevents.c
xorg-server/Xi/opendev.c
xorg-server/composite/compalloc.c
xorg-server/composite/compoverlay.c
xorg-server/dix/colormap.c
xorg-server/dix/devices.c
xorg-server/dix/dispatch.c
xorg-server/dix/dixfonts.c
xorg-server/dix/eventconvert.c
xorg-server/dix/events.c
xorg-server/dix/gc.c
xorg-server/dix/getevents.c
xorg-server/dix/main.c
xorg-server/dix/privates.c
xorg-server/dix/registry.c
xorg-server/dix/resource.c
xorg-server/exa/exa_accel.c
xorg-server/exa/exa_migration_classic.c
xorg-server/exa/exa_unaccel.c
xorg-server/fb/fb.h
xorg-server/fb/fbcopy.c
xorg-server/fb/fbpixmap.c
xorg-server/glx/dispatch.h
xorg-server/glx/glapi.h
xorg-server/glx/glapi_gentable.c
xorg-server/glx/glapitable.h
xorg-server/glx/glprocs.h
xorg-server/glx/glxcmds.c
xorg-server/glx/glxcmdsswap.c
xorg-server/glx/glxdricommon.c
xorg-server/glx/glxdriswrast.c
xorg-server/glx/glxext.c
xorg-server/glx/indirect_dispatch.c
xorg-server/glx/indirect_dispatch.h
xorg-server/glx/indirect_dispatch_swap.c
xorg-server/glx/indirect_size.h
xorg-server/glx/indirect_size_get.h
xorg-server/glx/indirect_table.c
xorg-server/glx/indirect_util.c
xorg-server/glx/rensize.c
xorg-server/glx/single2swap.c
xorg-server/glx/singlepix.c
xorg-server/glx/singlepixswap.c
xorg-server/glx/singlesize.c
xorg-server/hw/dmx/dmxinit.c
xorg-server/hw/kdrive/ephyr/ephyr.c
xorg-server/hw/kdrive/ephyr/hostx.c
xorg-server/hw/kdrive/ephyr/hostx.h
xorg-server/hw/kdrive/src/kinput.c
xorg-server/hw/xfree86/common/compiler.h
xorg-server/hw/xwin/InitInput.c
xorg-server/hw/xwin/InitOutput.c
xorg-server/hw/xwin/ddraw.h
xorg-server/hw/xwin/glx/glwrap.c
xorg-server/hw/xwin/glx/indirect.c
xorg-server/hw/xwin/glx/wgl_ext_api.h
xorg-server/hw/xwin/glx/winpriv.c
xorg-server/hw/xwin/win.h
xorg-server/hw/xwin/winallpriv.c
xorg-server/hw/xwin/winauth.c
xorg-server/hw/xwin/winclipboard.h
xorg-server/hw/xwin/winclipboardinit.c
xorg-server/hw/xwin/winclipboardthread.c
xorg-server/hw/xwin/winclipboardunicode.c
xorg-server/hw/xwin/winclipboardwndproc.c
xorg-server/hw/xwin/winclipboardwrappers.c
xorg-server/hw/xwin/winclipboardxevents.c
xorg-server/hw/xwin/wincmap.c
xorg-server/hw/xwin/winconfig.c
xorg-server/hw/xwin/wincreatewnd.c
xorg-server/hw/xwin/wincursor.c
xorg-server/hw/xwin/windialogs.c
xorg-server/hw/xwin/winengine.c
xorg-server/hw/xwin/winerror.c
xorg-server/hw/xwin/wingc.c
xorg-server/hw/xwin/wingetsp.c
xorg-server/hw/xwin/winkeybd.c
xorg-server/hw/xwin/winkeybd.h
xorg-server/hw/xwin/winlayouts.h
xorg-server/hw/xwin/winmisc.c
xorg-server/hw/xwin/winmonitors.c
xorg-server/hw/xwin/winmouse.c
xorg-server/hw/xwin/winmsg.c
xorg-server/hw/xwin/winmsg.h
xorg-server/hw/xwin/winmultiwindowclass.c
xorg-server/hw/xwin/winmultiwindowicons.c
xorg-server/hw/xwin/winmultiwindowshape.c
xorg-server/hw/xwin/winmultiwindowwindow.c
xorg-server/hw/xwin/winmultiwindowwm.c
xorg-server/hw/xwin/winmultiwindowwndproc.c
xorg-server/hw/xwin/winnativegdi.c
xorg-server/hw/xwin/winpfbdd.c
xorg-server/hw/xwin/winpixmap.c
xorg-server/hw/xwin/winpolyline.c
xorg-server/hw/xwin/winprefs.c
xorg-server/hw/xwin/winprocarg.c
xorg-server/hw/xwin/winregistry.c
xorg-server/hw/xwin/winscrinit.c
xorg-server/hw/xwin/winsetsp.c
xorg-server/hw/xwin/winshaddd.c
xorg-server/hw/xwin/winshadddnl.c
xorg-server/hw/xwin/winshadgdi.c
xorg-server/hw/xwin/wintrayicon.c
xorg-server/hw/xwin/winwin32rootless.c
xorg-server/hw/xwin/winwin32rootlesswindow.c
xorg-server/hw/xwin/winwin32rootlesswndproc.c
xorg-server/hw/xwin/winwindow.c
xorg-server/hw/xwin/winwindow.h
xorg-server/hw/xwin/winwindowswm.c
xorg-server/hw/xwin/winwndproc.c
xorg-server/include/callback.h
xorg-server/include/dixstruct.h
xorg-server/include/misc.h
xorg-server/include/os.h
xorg-server/include/scrnintstr.h
xorg-server/mi/micmap.c
xorg-server/mi/miinitext.c
xorg-server/mi/mioverlay.c
xorg-server/mi/misprite.c
xorg-server/mi/mivaltree.c
xorg-server/mi/miwindow.c
xorg-server/miext/damage/damage.c
xorg-server/miext/rootless/rootlessGC.c
xorg-server/miext/rootless/rootlessWindow.c
xorg-server/os/WaitFor.c
xorg-server/os/access.c
xorg-server/os/connection.c
xorg-server/os/io.c
xorg-server/os/log.c
xorg-server/os/osinit.c
xorg-server/os/utils.c
xorg-server/os/xdmcp.c
xorg-server/os/xprintf.c
xorg-server/os/xstrans.c
xorg-server/render/mipict.c
xorg-server/xkb/xkbActions.c
xorg-server/xkb/xkbInit.c
xorg-server/xkeyboard-config/compat/default.in
Diffstat (limited to 'xorg-server/hw/xwin/winkeybd.c')
-rw-r--r-- | xorg-server/hw/xwin/winkeybd.c | 638 |
1 files changed, 300 insertions, 338 deletions
diff --git a/xorg-server/hw/xwin/winkeybd.c b/xorg-server/hw/xwin/winkeybd.c index e11a71248..5da959cae 100644 --- a/xorg-server/hw/xwin/winkeybd.c +++ b/xorg-server/hw/xwin/winkeybd.c @@ -31,7 +31,6 @@ * Harold L Hunt II */ - #ifdef HAVE_XWIN_CONFIG_H #include <xwin-config.h> #endif @@ -49,12 +48,10 @@ static Bool g_winKeyState[NUM_KEYCODES]; */ static void -winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, - pointer pCtrl, int iClass); + winKeybdBell(int iPercent, DeviceIntPtr pDeviceInt, pointer pCtrl, int iClass); static void -winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); - + winKeybdCtrl(DeviceIntPtr pDevice, KeybdCtrl * pCtrl); /* * Translate a Windows WM_[SYS]KEY(UP/DOWN) message @@ -66,14 +63,14 @@ winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); */ void -winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode) +winTranslateKey(WPARAM wParam, LPARAM lParam, int *piScanCode) { - int iKeyFixup = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 1]; - int iKeyFixupEx = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 2]; - int iParam = HIWORD (lParam); - int iParamScanCode = LOBYTE (iParam); + int iKeyFixup = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 1]; + int iKeyFixupEx = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 2]; + int iParam = HIWORD(lParam); + int iParamScanCode = LOBYTE(iParam); - winDebug("winTranslateKey: wParam %08x lParam %08x\n", wParam, lParam); + winDebug("winTranslateKey: wParam %08x lParam %08x\n", wParam, lParam); /* WM_ key messages faked by Vista speech recognition (WSR) don't have a * scan code. @@ -82,129 +79,117 @@ winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode) * System.Windows.Forms.SendKeys.SendWait(), which appears always to give a * scan code of 1 */ - if (iParamScanCode <= 1) - { - if (VK_PRIOR <= wParam && wParam <= VK_DOWN) - /* Trigger special case table to translate to extended - * keycode, otherwise if num_lock is on, we can get keypad - * numbers instead of navigation keys. */ - iParam |= KF_EXTENDED; - else - iParamScanCode = MapVirtualKeyEx(wParam, - /*MAPVK_VK_TO_VSC*/0, - GetKeyboardLayout(0)); + if (iParamScanCode <= 1) { + if (VK_PRIOR <= wParam && wParam <= VK_DOWN) + /* Trigger special case table to translate to extended + * keycode, otherwise if num_lock is on, we can get keypad + * numbers instead of navigation keys. */ + iParam |= KF_EXTENDED; + else + iParamScanCode = MapVirtualKeyEx(wParam, + /*MAPVK_VK_TO_VSC */ 0, + GetKeyboardLayout(0)); } - /* Branch on special extended, special non-extended, or normal key */ - if ((iParam & KF_EXTENDED) && iKeyFixupEx) - *piScanCode = iKeyFixupEx; - else if (iKeyFixup) - *piScanCode = iKeyFixup; - else if (wParam == 0 && iParamScanCode == 0x70) - *piScanCode = KEY_HKTG; - else - switch (iParamScanCode) - { - case 0x70: + /* Branch on special extended, special non-extended, or normal key */ + if ((iParam & KF_EXTENDED) && iKeyFixupEx) + *piScanCode = iKeyFixupEx; + else if (iKeyFixup) + *piScanCode = iKeyFixup; + else if (wParam == 0 && iParamScanCode == 0x70) *piScanCode = KEY_HKTG; - break; - case 0x73: - *piScanCode = KEY_BSlash2; - break; - default: - *piScanCode = iParamScanCode; - break; - } + else + switch (iParamScanCode) { + case 0x70: + *piScanCode = KEY_HKTG; + break; + case 0x73: + *piScanCode = KEY_BSlash2; + break; + default: + *piScanCode = iParamScanCode; + break; + } } - /* Ring the keyboard bell (system speaker on PCs) */ static void -winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, - pointer pCtrl, int iClass) +winKeybdBell(int iPercent, DeviceIntPtr pDeviceInt, pointer pCtrl, int iClass) { - /* - * We can't use Beep () here because it uses the PC speaker - * on NT/2000. MessageBeep (MB_OK) will play the default system - * sound on systems with a sound card or it will beep the PC speaker - * on systems that do not have a sound card. - */ - MessageBeep (MB_OK); + /* + * We can't use Beep () here because it uses the PC speaker + * on NT/2000. MessageBeep (MB_OK) will play the default system + * sound on systems with a sound card or it will beep the PC speaker + * on systems that do not have a sound card. + */ + MessageBeep(MB_OK); } - /* Change some keyboard configuration parameters */ static void -winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl) +winKeybdCtrl(DeviceIntPtr pDevice, KeybdCtrl * pCtrl) { } - /* * See Porting Layer Definition - p. 18 * winKeybdProc is known as a DeviceProc. */ int -winKeybdProc (DeviceIntPtr pDeviceInt, int iState) +winKeybdProc(DeviceIntPtr pDeviceInt, int iState) { - DevicePtr pDevice = (DevicePtr) pDeviceInt; - XkbSrvInfoPtr xkbi; - XkbControlsPtr ctrl; + DevicePtr pDevice = (DevicePtr) pDeviceInt; + XkbSrvInfoPtr xkbi; + XkbControlsPtr ctrl; - switch (iState) - { + switch (iState) { case DEVICE_INIT: - winConfigKeyboard (pDeviceInt); - - /* FIXME: Maybe we should use winGetKbdLeds () here? */ - defaultKeyboardControl.leds = g_winInfo.keyboard.leds; - - winDebug("Rules = \"%s\" Model = \"%s\" Layout = \"%s\"" - " Variant = \"%s\" Options = \"%s\"\n", - g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none", - g_winInfo.xkb.model ? g_winInfo.xkb.model : "none", - g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none", - g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none", - g_winInfo.xkb.options ? g_winInfo.xkb.options : "none"); - - InitKeyboardDeviceStruct (pDeviceInt, - &g_winInfo.xkb, - winKeybdBell, - winKeybdCtrl); - - xkbi = pDeviceInt->key->xkbInfo; - if ((xkbi != NULL) && (xkbi->desc != NULL)) - { - ctrl = xkbi->desc->ctrls; - ctrl->repeat_delay = g_winInfo.keyboard.delay; - ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate; + winConfigKeyboard(pDeviceInt); + + /* FIXME: Maybe we should use winGetKbdLeds () here? */ + defaultKeyboardControl.leds = g_winInfo.keyboard.leds; + + winDebug("Rules = \"%s\" Model = \"%s\" Layout = \"%s\"" + " Variant = \"%s\" Options = \"%s\"\n", + g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none", + g_winInfo.xkb.model ? g_winInfo.xkb.model : "none", + g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none", + g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none", + g_winInfo.xkb.options ? g_winInfo.xkb.options : "none"); + + InitKeyboardDeviceStruct(pDeviceInt, + &g_winInfo.xkb, winKeybdBell, winKeybdCtrl); + + xkbi = pDeviceInt->key->xkbInfo; + if ((xkbi != NULL) && (xkbi->desc != NULL)) { + ctrl = xkbi->desc->ctrls; + ctrl->repeat_delay = g_winInfo.keyboard.delay; + ctrl->repeat_interval = 1000 / g_winInfo.keyboard.rate; } - else - { - winDebug ("winKeybdProc - Error initializing keyboard AutoRepeat\n"); + else { + winDebug ("winKeybdProc - Error initializing keyboard AutoRepeat\n"); } - break; - - case DEVICE_ON: - pDevice->on = TRUE; + break; - // immediately copy the state of this keyboard device to the VCK - // (which otherwise happens lazily after the first keypress) - CopyKeyClass(pDeviceInt, inputInfo.keyboard); - break; + case DEVICE_ON: + pDevice->on = TRUE; + + // immediately copy the state of this keyboard device to the VCK + // (which otherwise happens lazily after the first keypress) + CopyKeyClass(pDeviceInt, inputInfo.keyboard); + break; case DEVICE_CLOSE: - case DEVICE_OFF: - pDevice->on = FALSE; - break; + case DEVICE_OFF: + pDevice->on = FALSE; + break; } - return Success; + return Success; } - /* * Detect current mode key states upon server startup. * @@ -213,38 +198,33 @@ winKeybdProc (DeviceIntPtr pDeviceInt, int iState) */ void -winInitializeModeKeyStates (void) +winInitializeModeKeyStates(void) { - /* Restore NumLock */ - if (GetKeyState (VK_NUMLOCK) & 0x0001) - { - winSendKeyEvent (KEY_NumLock, TRUE); - winSendKeyEvent (KEY_NumLock, FALSE); + /* Restore NumLock */ + if (GetKeyState(VK_NUMLOCK) & 0x0001) { + winSendKeyEvent(KEY_NumLock, TRUE); + winSendKeyEvent(KEY_NumLock, FALSE); } - /* Restore CapsLock */ - if (GetKeyState (VK_CAPITAL) & 0x0001) - { - winSendKeyEvent (KEY_CapsLock, TRUE); - winSendKeyEvent (KEY_CapsLock, FALSE); + /* Restore CapsLock */ + if (GetKeyState(VK_CAPITAL) & 0x0001) { + winSendKeyEvent(KEY_CapsLock, TRUE); + winSendKeyEvent(KEY_CapsLock, FALSE); } - /* Restore ScrollLock */ - if (GetKeyState (VK_SCROLL) & 0x0001) - { - winSendKeyEvent (KEY_ScrollLock, TRUE); - winSendKeyEvent (KEY_ScrollLock, FALSE); + /* Restore ScrollLock */ + if (GetKeyState(VK_SCROLL) & 0x0001) { + winSendKeyEvent(KEY_ScrollLock, TRUE); + winSendKeyEvent(KEY_ScrollLock, FALSE); } - /* Restore KanaLock */ - if (GetKeyState (VK_KANA) & 0x0001) - { - winSendKeyEvent (KEY_HKTG, TRUE); - winSendKeyEvent (KEY_HKTG, FALSE); + /* Restore KanaLock */ + if (GetKeyState(VK_KANA) & 0x0001) { + winSendKeyEvent(KEY_HKTG, TRUE); + winSendKeyEvent(KEY_HKTG, FALSE); } } - /* * Upon regaining the keyboard focus we must * resynchronize our internal mode key states @@ -252,29 +232,31 @@ winInitializeModeKeyStates (void) */ void -winRestoreModeKeyStates (void) +winRestoreModeKeyStates(void) { - DWORD dwKeyState; - BOOL processEvents = TRUE; - unsigned short internalKeyStates; - - /* X server is being initialized */ - if (!inputInfo.keyboard) - return; - - /* Only process events if the rootwindow is mapped. The keyboard events - * will cause segfaults otherwise */ - if (screenInfo.screens[0]->root && screenInfo.screens[0]->root->mapped == FALSE) - processEvents = FALSE; - - /* Force to process all pending events in the mi event queue */ - if (processEvents) - mieqProcessInputEvents (); - - /* Read the mode key states of our X server */ - /* (stored in the virtual core keyboard) */ - internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); - winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); + DWORD dwKeyState; + BOOL processEvents = TRUE; + unsigned short internalKeyStates; + + /* X server is being initialized */ + if (!inputInfo.keyboard) + return; + + /* Only process events if the rootwindow is mapped. The keyboard events + * will cause segfaults otherwise */ + if (screenInfo.screens[0]->root && + screenInfo.screens[0]->root->mapped == FALSE) + processEvents = FALSE; + + /* Force to process all pending events in the mi event queue */ + if (processEvents) + mieqProcessInputEvents(); + + /* Read the mode key states of our X server */ + /* (stored in the virtual core keyboard) */ + internalKeyStates = + XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); + winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); { /* Make sure the message queue is empty, otherwise the GetKeyState will not always @@ -291,11 +273,11 @@ winRestoreModeKeyStates (void) } } - /* - * NOTE: The C XOR operator, ^, will not work here because it is - * a bitwise operator, not a logical operator. C does not - * have a logical XOR operator, so we use a macro instead. - */ + /* + * NOTE: The C XOR operator, ^, will not work here because it is + * a bitwise operator, not a logical operator. C does not + * have a logical XOR operator, so we use a macro instead. + */ { /* consider modifer keys */ @@ -320,204 +302,182 @@ winRestoreModeKeyStates (void) winSendKeyEvent (KEY_AltLang, altgr); } - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001; - if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState)) - { - winSendKeyEvent (KEY_NumLock, TRUE); - winSendKeyEvent (KEY_NumLock, FALSE); + /* Has the key state changed? */ + dwKeyState = GetKeyState(VK_NUMLOCK) & 0x0001; + if (WIN_XOR(internalKeyStates & NumLockMask, dwKeyState)) { + winSendKeyEvent(KEY_NumLock, TRUE); + winSendKeyEvent(KEY_NumLock, FALSE); } - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_CAPITAL) & 0x0001; - if (WIN_XOR (internalKeyStates & LockMask, dwKeyState)) - { - winSendKeyEvent (KEY_CapsLock, TRUE); - winSendKeyEvent (KEY_CapsLock, FALSE); + /* Has the key state changed? */ + dwKeyState = GetKeyState(VK_CAPITAL) & 0x0001; + if (WIN_XOR(internalKeyStates & LockMask, dwKeyState)) { + winSendKeyEvent(KEY_CapsLock, TRUE); + winSendKeyEvent(KEY_CapsLock, FALSE); } - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_SCROLL) & 0x0001; - if (WIN_XOR (internalKeyStates & ScrollLockMask, dwKeyState)) - { - winSendKeyEvent (KEY_ScrollLock, TRUE); - winSendKeyEvent (KEY_ScrollLock, FALSE); + /* Has the key state changed? */ + dwKeyState = GetKeyState(VK_SCROLL) & 0x0001; + if (WIN_XOR(internalKeyStates & ScrollLockMask, dwKeyState)) { + winSendKeyEvent(KEY_ScrollLock, TRUE); + winSendKeyEvent(KEY_ScrollLock, FALSE); } - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_KANA) & 0x0001; - if (WIN_XOR (internalKeyStates & KanaMask, dwKeyState)) - { - winSendKeyEvent (KEY_HKTG, TRUE); - winSendKeyEvent (KEY_HKTG, FALSE); + /* Has the key state changed? */ + dwKeyState = GetKeyState(VK_KANA) & 0x0001; + if (WIN_XOR(internalKeyStates & KanaMask, dwKeyState)) { + winSendKeyEvent(KEY_HKTG, TRUE); + winSendKeyEvent(KEY_HKTG, FALSE); } } - /* * Look for the lovely fake Control_L press/release generated by Windows * when AltGr is pressed/released on a non-U.S. keyboard. */ Bool -winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) +winIsFakeCtrl_L(UINT message, WPARAM wParam, LPARAM lParam) { - MSG msgNext; - LONG lTime; - Bool fReturn; - - static Bool lastWasControlL = FALSE; - static UINT lastMessage; - static LONG lastTime; - - /* - * Fake Ctrl_L presses will be followed by an Alt_R press - * with the same timestamp as the Ctrl_L press. - */ - if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN) - && wParam == VK_CONTROL - && (HIWORD (lParam) & KF_EXTENDED) == 0) - { - /* Got a Ctrl_L press */ - - /* Get time of current message */ - lTime = GetMessageTime (); - - /* Look for next press message */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYDOWN, WM_SYSKEYDOWN, - PM_NOREMOVE); - - if (fReturn && msgNext.message != WM_KEYDOWN && msgNext.message != WM_SYSKEYDOWN) - fReturn = 0; - - if (!fReturn) - { - lastWasControlL = TRUE; - lastMessage = message; - lastTime = lTime; + MSG msgNext; + LONG lTime; + Bool fReturn; + + static Bool lastWasControlL = FALSE; + static UINT lastMessage; + static LONG lastTime; + + /* + * Fake Ctrl_L presses will be followed by an Alt_R press + * with the same timestamp as the Ctrl_L press. + */ + if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN) + && wParam == VK_CONTROL && (HIWORD(lParam) & KF_EXTENDED) == 0) { + /* Got a Ctrl_L press */ + + /* Get time of current message */ + lTime = GetMessageTime(); + + /* Look for next press message */ + fReturn = PeekMessage(&msgNext, NULL, + WM_KEYDOWN, WM_SYSKEYDOWN, PM_NOREMOVE); + + if (fReturn && msgNext.message != WM_KEYDOWN && + msgNext.message != WM_SYSKEYDOWN) + fReturn = 0; + + if (!fReturn) { + lastWasControlL = TRUE; + lastMessage = message; + lastTime = lTime; } - else - { - lastWasControlL = FALSE; + else { + lastWasControlL = FALSE; } - /* Is next press an Alt_R with the same timestamp? */ - if (fReturn && msgNext.wParam == VK_MENU - && msgNext.time == lTime - && (HIWORD (msgNext.lParam) & KF_EXTENDED)) - { - /* - * Next key press is Alt_R with same timestamp as current - * Ctrl_L message. Therefore, this Ctrl_L press is a fake - * event, so discard it. - */ - return TRUE; - } + /* Is next press an Alt_R with the same timestamp? */ + if (fReturn && msgNext.wParam == VK_MENU + && msgNext.time == lTime + && (HIWORD(msgNext.lParam) & KF_EXTENDED)) { + /* + * Next key press is Alt_R with same timestamp as current + * Ctrl_L message. Therefore, this Ctrl_L press is a fake + * event, so discard it. + */ + return TRUE; + } } - /* - * Sometimes, the Alt_R press message is not yet posted when the - * fake Ctrl_L press message arrives (even though it has the - * same timestamp), so check for an Alt_R press message that has - * arrived since the last Ctrl_L message. - */ - else if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN) - && wParam == VK_MENU - && (HIWORD (lParam) & KF_EXTENDED)) - { - /* Got a Alt_R press */ - - if (lastWasControlL) - { - lTime = GetMessageTime (); - - if (lastTime == lTime) - { + /* + * Sometimes, the Alt_R press message is not yet posted when the + * fake Ctrl_L press message arrives (even though it has the + * same timestamp), so check for an Alt_R press message that has + * arrived since the last Ctrl_L message. + */ + else if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN) + && wParam == VK_MENU && (HIWORD(lParam) & KF_EXTENDED)) { + /* Got a Alt_R press */ + + if (lastWasControlL) { + lTime = GetMessageTime(); + + if (lastTime == lTime) { /* Undo the fake Ctrl_L press by sending a fake Ctrl_L release */ - winSendKeyEvent (KEY_LCtrl, FALSE); + winSendKeyEvent(KEY_LCtrl, FALSE); } - lastWasControlL = FALSE; + lastWasControlL = FALSE; } } - /* - * Fake Ctrl_L releases will be followed by an Alt_R release - * with the same timestamp as the Ctrl_L release. - */ - else if ((message == WM_KEYUP || message == WM_SYSKEYUP) - && wParam == VK_CONTROL - && (HIWORD (lParam) & KF_EXTENDED) == 0) - { - /* Got a Ctrl_L release */ - - /* Get time of current message */ - lTime = GetMessageTime (); - - /* Look for next release message */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYUP, WM_SYSKEYUP, - PM_NOREMOVE); - - if (fReturn && msgNext.message != WM_KEYUP && msgNext.message != WM_SYSKEYUP) - fReturn = 0; - - lastWasControlL = FALSE; - - /* Is next press an Alt_R with the same timestamp? */ - if (fReturn - && (msgNext.message == WM_KEYUP - || msgNext.message == WM_SYSKEYUP) - && msgNext.wParam == VK_MENU - && msgNext.time == lTime - && (HIWORD (msgNext.lParam) & KF_EXTENDED)) - { - /* - * Next key release is Alt_R with same timestamp as current - * Ctrl_L message. Therefore, this Ctrl_L release is a fake - * event, so discard it. - */ - return TRUE; - } + /* + * Fake Ctrl_L releases will be followed by an Alt_R release + * with the same timestamp as the Ctrl_L release. + */ + else if ((message == WM_KEYUP || message == WM_SYSKEYUP) + && wParam == VK_CONTROL && (HIWORD(lParam) & KF_EXTENDED) == 0) { + /* Got a Ctrl_L release */ + + /* Get time of current message */ + lTime = GetMessageTime(); + + /* Look for next release message */ + fReturn = PeekMessage(&msgNext, NULL, + WM_KEYUP, WM_SYSKEYUP, PM_NOREMOVE); + + if (fReturn && msgNext.message != WM_KEYUP && + msgNext.message != WM_SYSKEYUP) + fReturn = 0; + + lastWasControlL = FALSE; + + /* Is next press an Alt_R with the same timestamp? */ + if (fReturn + && (msgNext.message == WM_KEYUP || msgNext.message == WM_SYSKEYUP) + && msgNext.wParam == VK_MENU + && msgNext.time == lTime + && (HIWORD(msgNext.lParam) & KF_EXTENDED)) { + /* + * Next key release is Alt_R with same timestamp as current + * Ctrl_L message. Therefore, this Ctrl_L release is a fake + * event, so discard it. + */ + return TRUE; + } } - else - { - /* On any other press or release message, we don't have a - potentially fake Ctrl_L to worry about anymore... */ - lastWasControlL = FALSE; + else { + /* On any other press or release message, we don't have a + potentially fake Ctrl_L to worry about anymore... */ + lastWasControlL = FALSE; } - /* Not a fake control left press/release */ - return FALSE; + /* Not a fake control left press/release */ + return FALSE; } - /* * Lift any modifier keys that are pressed */ void -winKeybdReleaseKeys (void) +winKeybdReleaseKeys(void) { - int i; + int i; #ifdef HAS_DEVWINDOWS - /* Verify that the mi input system has been initialized */ - if (g_fdMessageQueue == WIN_FD_INVALID) - return; + /* Verify that the mi input system has been initialized */ + if (g_fdMessageQueue == WIN_FD_INVALID) + return; #endif - /* Loop through all keys */ - for (i = 0; i < NUM_KEYCODES; ++i) - { - /* Pop key if pressed */ - if (g_winKeyState[i]) - winSendKeyEvent (i, FALSE); + /* Loop through all keys */ + for (i = 0; i < NUM_KEYCODES; ++i) { + /* Pop key if pressed */ + if (g_winKeyState[i]) + winSendKeyEvent(i, FALSE); - /* Reset pressed flag for keys */ - g_winKeyState[i] = FALSE; + /* Reset pressed flag for keys */ + g_winKeyState[i] = FALSE; } } - /* * Take a raw X key code and send an up or down event for it. * @@ -525,55 +485,57 @@ winKeybdReleaseKeys (void) */ void -winSendKeyEvent (DWORD dwKey, Bool fDown) +winSendKeyEvent(DWORD dwKey, Bool fDown) { - /* - * When alt-tabing between screens we can get phantom key up messages - * Here we only pass them through it we think we should! - */ - if (g_winKeyState[dwKey] == FALSE && fDown == FALSE) return; + /* + * When alt-tabing between screens we can get phantom key up messages + * Here we only pass them through it we think we should! + */ + if (g_winKeyState[dwKey] == FALSE && fDown == FALSE) + return; - /* Update the keyState map */ - g_winKeyState[dwKey] = fDown; + /* Update the keyState map */ + g_winKeyState[dwKey] = fDown; - QueueKeyboardEvents(g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE, NULL); + QueueKeyboardEvents(g_pwinKeyboard, fDown ? KeyPress : KeyRelease, + dwKey + MIN_KEYCODE, NULL); - winDebug("winSendKeyEvent: dwKey: %d, fDown: %d\n", - dwKey, fDown); + winDebug("winSendKeyEvent: dwKey: %d, fDown: %d\n", dwKey, fDown); } -BOOL winCheckKeyPressed(WPARAM wParam, LPARAM lParam) +BOOL +winCheckKeyPressed(WPARAM wParam, LPARAM lParam) { - switch (wParam) - { + switch (wParam) { case VK_CONTROL: - if ((lParam & 0x1ff0000) == 0x11d0000 && g_winKeyState[KEY_RCtrl]) - return TRUE; - if ((lParam & 0x1ff0000) == 0x01d0000 && g_winKeyState[KEY_LCtrl]) - return TRUE; - break; + if ((lParam & 0x1ff0000) == 0x11d0000 && g_winKeyState[KEY_RCtrl]) + return TRUE; + if ((lParam & 0x1ff0000) == 0x01d0000 && g_winKeyState[KEY_LCtrl]) + return TRUE; + break; case VK_SHIFT: - if ((lParam & 0x1ff0000) == 0x0360000 && g_winKeyState[KEY_ShiftR]) - return TRUE; - if ((lParam & 0x1ff0000) == 0x02a0000 && g_winKeyState[KEY_ShiftL]) - return TRUE; - break; + if ((lParam & 0x1ff0000) == 0x0360000 && g_winKeyState[KEY_ShiftR]) + return TRUE; + if ((lParam & 0x1ff0000) == 0x02a0000 && g_winKeyState[KEY_ShiftL]) + return TRUE; + break; default: - return TRUE; - } - return FALSE; + return TRUE; + } + return FALSE; } /* Only on shift release message is sent even if both are pressed. * Fix this here */ -void winFixShiftKeys (int iScanCode) +void +winFixShiftKeys(int iScanCode) { - if (GetKeyState (VK_SHIFT) & 0x8000) - return; + if (GetKeyState(VK_SHIFT) & 0x8000) + return; - if (iScanCode == KEY_ShiftL && g_winKeyState[KEY_ShiftR]) - winSendKeyEvent (KEY_ShiftR, FALSE); - if (iScanCode == KEY_ShiftR && g_winKeyState[KEY_ShiftL]) - winSendKeyEvent (KEY_ShiftL, FALSE); + if (iScanCode == KEY_ShiftL && g_winKeyState[KEY_ShiftR]) + winSendKeyEvent(KEY_ShiftR, FALSE); + if (iScanCode == KEY_ShiftR && g_winKeyState[KEY_ShiftL]) + winSendKeyEvent(KEY_ShiftL, FALSE); } |