diff options
author | Oliver Schmidt <oschmidt-mailinglists@gmx.de> | 2012-01-08 20:30:02 +0000 |
---|---|---|
committer | Jon TURNEY <jon.turney@dronecode.org.uk> | 2012-11-27 16:09:08 +0000 |
commit | 11bb32e561b3f1c657a99b3902f9beea786babbb (patch) | |
tree | f08be730f1eeed1fb978216b2b00f6c651855c33 | |
parent | 47291d0b7d7bfee74156f83badae15a0818c68ad (diff) |
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 <oschmidt-mailinglists@gmx.de>
Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
-rw-r--r-- | hw/xwin/winkeybd.c | 22 |
1 files changed, 22 insertions, 0 deletions
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, |