From 11bb32e561b3f1c657a99b3902f9beea786babbb Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 8 Jan 2012 20:30:02 +0000 Subject: [PATCH] hw/xwin: Restore non-latching modifier key state when an X window gains focus In multiwindow mode, the state of the modifier keys was lost when a window is created (or raised) and focus moved to that window. For example: In window A Ctrl + some key opens a window B, then in window B Ctrl + some other key triggers the next action. However after the opening of window B the Ctrl key has to be released and pressed again. If the user keeps the Ctrl key held down when the window B is opened, the next key press X will be interpreted as X and not as Ctrl+X. Extended the function winRestoreModeKeyStates in winkeybd.c to consider not only the latching modifier keys but also the modifiers Ctrl, Shift, Alt/AltGr by using the Windows function GetAsyncKeyState. A combined Ctrl+AltGr modifier state cannot be restored correctly, as Windows always fakes a Ctrl-L when AltGr is pressed. Signed-off-by: Oliver Schmidt Reviewed-by: Jon TURNEY Reviewed-by: Colin Harrison --- hw/xwin/winkeybd.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c index 104ca589a..a70cdcd16 100644 --- a/hw/xwin/winkeybd.c +++ b/hw/xwin/winkeybd.c @@ -262,6 +262,28 @@ winRestoreModeKeyStates(void) XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); + /* Check if modifier keys are pressed, and if so, fake a press */ + { + BOOL ctrl = (GetAsyncKeyState(VK_CONTROL) < 0); + BOOL shift = (GetAsyncKeyState(VK_SHIFT) < 0); + BOOL alt = (GetAsyncKeyState(VK_LMENU) < 0); + BOOL altgr = (GetAsyncKeyState(VK_RMENU) < 0); + + if (ctrl && altgr) + ctrl = FALSE; + + if (LOGICAL_XOR(internalKeyStates & ControlMask, ctrl)) + winSendKeyEvent(KEY_LCtrl, ctrl); + + if (LOGICAL_XOR(internalKeyStates & ShiftMask, shift)) + winSendKeyEvent(KEY_ShiftL, shift); + + if (LOGICAL_XOR(internalKeyStates & Mod1Mask, alt)) + winSendKeyEvent(KEY_Alt, alt); + + if (LOGICAL_XOR(internalKeyStates & Mod5Mask, altgr)) + winSendKeyEvent(KEY_AltLang, altgr); + } /* Check if latching modifier key states have changed, and if so,