On Fri May 24 10:33:28 2024 +0000, Alexandros Frantzis wrote:
So the concern (in this and other cases) is strictly about the key events, and you would prefer if we just updated the async keyboard state? Although that should work fine in many cases, one issue is autorepeat functionality, since it is handled (at the moment) in win32u based on key messages. We would like to:
- Stop autorepeat when a window loses focus.
- Start autorepeat of key if it is pressed when gaining focus.
(1) is critical to get right, but seems easy enough to achieve without key event involvement. If this matches Windows behavior, it would make sense to integrate a "has focus" check into the win32u repeat timer callback. At the moment it needs to happen from the driver too because we don't update window focus when handling the keyboard leave event (but also a special `NtUserSendHardwareInput` invocation with all scancodes up (see below) could deal with that in win32u). (2) seems less straightforward, since there isn't currently any feedback from the wineserver to hwnd when the async key state changes. But if we use a special `NtUserSendHardwareInput` invocation as you suggest below, perhaps wineserver can detect the scenario and do something sensible here.
Hmm... after looking a bit more into it seems like I'm maybe wrong, but the trick may actually be that Windows apparently handles key repeat on the driver or hardware level. (Still, it doesn't send KEYUP on focus loss)
So, the way I've implemented it, with a process timer that repeats WM_KEYDOWN message isn't correct, and in particular it won't trigger repetitions of rawinput messages (which could cause other input issues with winewayland).
Maybe it would be better to implement it the same way as we now have pointer input repeat (see `queue_pointer_message` in `server/queue.c`), repeating input for any key that is pressed.
Then, assuming input is dispatched correctly, and assuming wineserver is informed of focus loss so that the old window doesn't receive the repeated input, you could simply keep the repeating active until another window gains focus and can tell wineserver of the updated key state, clearing repeat timer or starting repeat again if any keys are still pressed.