Zebediah Figura : winex11: Update the state of all keys on KeymapNotify.

Alexandre Julliard julliard at winehq.org
Tue Jun 18 17:21:48 CDT 2019


Module: wine
Branch: master
Commit: 1bc9c4fdb2e6c2762105c14cdafb7d4ea3370625
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=1bc9c4fdb2e6c2762105c14cdafb7d4ea3370625

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Jun 17 14:46:20 2019 -0500

winex11: Update the state of all keys on KeymapNotify.

The Binding of Isaac transitions in and out of fullscreen when the "F" key is
pressed. Specifically, it will swap states when receiving WM_KEYDOWN,
provided that the previous key state was not pressed (i.e. bit 30 is 0).
However, as part of the process of transitioning, it hides and shows its
window, causing it to temporarily lose focus. If the F key is released while
the window does not have focus, Wine misses this fact, and thinks that the
key was already pressed the next time it is pressed, causing the game to
refuse to change focus. Windows will not deliver WM_KEYUP messages to a
window that does not have focus, but it will always report the true previous
state of any key on the keyboard when requested.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winex11.drv/keyboard.c | 55 +++++++++------------------------------------
 1 file changed, 11 insertions(+), 44 deletions(-)

diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c
index b063491..131c5f5 100644
--- a/dlls/winex11.drv/keyboard.c
+++ b/dlls/winex11.drv/keyboard.c
@@ -1212,13 +1212,12 @@ BOOL X11DRV_KeymapNotify( HWND hwnd, XEvent *event )
     BOOL changed = FALSE;
     struct {
         WORD vkey;
-        BOOL pressed;
-    } modifiers[6]; /* VK_LSHIFT through VK_RMENU are contiguous */
-    BOOL lwin_pressed = FALSE, rwin_pressed = FALSE;
+        WORD pressed;
+    } keys[256];
 
     if (!get_async_key_state( keystate )) return FALSE;
 
-    memset(modifiers, 0, sizeof(modifiers));
+    memset(keys, 0, sizeof(keys));
 
     EnterCriticalSection( &kbd_section );
 
@@ -1229,59 +1228,27 @@ BOOL X11DRV_KeymapNotify( HWND hwnd, XEvent *event )
     {
         for (j = 0; j < 8; j++)
         {
-            int m;
-
             vkey = keyc2vkey[(i * 8) + j];
 
-            switch(vkey & 0xff)
-            {
-            case VK_LMENU:
-            case VK_RMENU:
-            case VK_LCONTROL:
-            case VK_RCONTROL:
-            case VK_LSHIFT:
-            case VK_RSHIFT:
-                m = (vkey & 0xff) - VK_LSHIFT;
-                /* Take the vkey from the first keycode we encounter for this modifier */
-                if (!modifiers[m].vkey) modifiers[m].vkey = vkey;
-                if (event->xkeymap.key_vector[i] & (1<<j)) modifiers[m].pressed = TRUE;
-                break;
-            case VK_LWIN:
-                if (event->xkeymap.key_vector[i] & (1<<j)) lwin_pressed = TRUE;
-                break;
-            case VK_RWIN:
-                if (event->xkeymap.key_vector[i] & (1<<j)) rwin_pressed = TRUE;
-                break;
-            }
+            /* If multiple keys map to the same vkey, we want to report it as
+             * pressed iff any of them are pressed. */
+            if (!keys[vkey & 0xff].vkey) keys[vkey & 0xff].vkey = vkey;
+            if (event->xkeymap.key_vector[i] & (1<<j)) keys[vkey & 0xff].pressed = TRUE;
         }
     }
 
-    for (vkey = VK_LSHIFT; vkey <= VK_RMENU; vkey++)
+    for (vkey = 1; vkey <= 0xff; vkey++)
     {
-        int m = vkey - VK_LSHIFT;
-        if (modifiers[m].vkey && !(keystate[vkey] & 0x80) != !modifiers[m].pressed)
+        if (keys[vkey].vkey && !(keystate[vkey] & 0x80) != !keys[vkey].pressed)
         {
             TRACE( "Adjusting state for vkey %#.2x. State before %#.2x\n",
-                   modifiers[m].vkey, keystate[vkey]);
+                   keys[vkey].vkey, keystate[vkey]);
 
-            update_key_state( keystate, vkey, modifiers[m].pressed );
+            update_key_state( keystate, vkey, keys[vkey].pressed );
             changed = TRUE;
         }
     }
 
-    if (!(keystate[VK_LWIN] & 0x80) != !lwin_pressed)
-    {
-        TRACE( "Adjusting state for VK_LWIN. State before %#.2x\n", keystate[VK_LWIN]);
-        update_key_state( keystate, VK_LWIN, lwin_pressed );
-        changed = TRUE;
-    }
-    if (!(keystate[VK_RWIN] & 0x80) != !rwin_pressed)
-    {
-        TRACE( "Adjusting state for VK_RWIN. State before %#.2x\n", keystate[VK_RWIN]);
-        update_key_state( keystate, VK_RWIN, rwin_pressed );
-        changed = TRUE;
-    }
-
     LeaveCriticalSection( &kbd_section );
     if (!changed) return FALSE;
 




More information about the wine-cvs mailing list