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-03-10 13:26:27 +0000 |
commit | 4f61b9ec0531bad2c3d17ac8f53797556cbd3413 (patch) | |
tree | b2fb44d1aea49ad7794e0ef516ed70fb5fde4538 | |
parent | bc0f28848d9b80b1b7bd12f90b6e6b2b7a644a90 (diff) |
hw/xwin: Restore 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 mode switch key 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: Jon TURNEY <jon.turney@dronecode.org.uk>
-rw-r--r-- | hw/xwin/winkeybd.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c index 278342f72..f1add8912 100644 --- a/hw/xwin/winkeybd.c +++ b/hw/xwin/winkeybd.c @@ -283,6 +283,29 @@ winRestoreModeKeyStates (void) * have a logical XOR operator, so we use a macro instead. */ + { + /* consider modifer keys */ + + 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 (WIN_XOR (internalKeyStates & ControlMask, ctrl)) + winSendKeyEvent (KEY_LCtrl, ctrl); + + if (WIN_XOR (internalKeyStates & ShiftMask, shift)) + winSendKeyEvent (KEY_ShiftL, shift); + + if (WIN_XOR (internalKeyStates & Mod1Mask, alt)) + winSendKeyEvent (KEY_Alt, alt); + + if (WIN_XOR (internalKeyStates & Mod5Mask, altgr)) + winSendKeyEvent (KEY_AltLang, altgr); + } + /* Has the key state changed? */ dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001; if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState)) |