diff mbox series

ui/sdl2: disable SDL_HINT_GRAB_KEYBOARD on Windows

Message ID 20230418062823.5683-1-vr_qemu@t-online.de
State New
Headers show
Series ui/sdl2: disable SDL_HINT_GRAB_KEYBOARD on Windows | expand

Commit Message

Volker Rümelin April 18, 2023, 6:28 a.m. UTC
Windows sends an extra left control key up/down input event for
every right alt key up/down input event for keyboards with
international layout. Since commit 830473455f ("ui/sdl2: fix
handling of AltGr key on Windows") QEMU uses a Windows low level
keyboard hook procedure to reliably filter out the special left
control key and to grab the keyboard on Windows.

The SDL2 version 2.0.16 introduced its own Windows low level
keyboard hook procedure to grab the keyboard. Windows calls this
callback before the QEMU keyboard hook procedure. This disables
the special left control key filter when the keyboard is grabbed.

To fix the problem, disable the SDL2 Windows low level keyboard
hook procedure.

Reported-by: Bernhard Beschow <shentey@gmail.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 ui/sdl2.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Thomas Huth April 18, 2023, 7:36 a.m. UTC | #1
On 18/04/2023 08.28, Volker Rümelin wrote:
> Windows sends an extra left control key up/down input event for
> every right alt key up/down input event for keyboards with
> international layout. Since commit 830473455f ("ui/sdl2: fix
> handling of AltGr key on Windows") QEMU uses a Windows low level
> keyboard hook procedure to reliably filter out the special left
> control key and to grab the keyboard on Windows.
> 
> The SDL2 version 2.0.16 introduced its own Windows low level
> keyboard hook procedure to grab the keyboard. Windows calls this
> callback before the QEMU keyboard hook procedure. This disables
> the special left control key filter when the keyboard is grabbed.
> 
> To fix the problem, disable the SDL2 Windows low level keyboard
> hook procedure.
> 
> Reported-by: Bernhard Beschow <shentey@gmail.com>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> ---
>   ui/sdl2.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index 00aadfae37..9d703200bf 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -855,7 +855,10 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
>   #ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR /* only available since SDL 2.0.8 */
>       SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
>   #endif
> +#ifndef CONFIG_WIN32
> +    /* QEMU uses its own low level keyboard hook procecure on Windows */
>       SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
> +#endif
>   #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
>       SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
>   #endif

Reviewed-by: Thomas Huth <thuth@redhat.com>
Bernhard Beschow April 18, 2023, 6:09 p.m. UTC | #2
Am 18. April 2023 06:28:23 UTC schrieb "Volker Rümelin" <vr_qemu@t-online.de>:
>Windows sends an extra left control key up/down input event for
>every right alt key up/down input event for keyboards with
>international layout. Since commit 830473455f ("ui/sdl2: fix
>handling of AltGr key on Windows") QEMU uses a Windows low level
>keyboard hook procedure to reliably filter out the special left
>control key and to grab the keyboard on Windows.
>
>The SDL2 version 2.0.16 introduced its own Windows low level
>keyboard hook procedure to grab the keyboard. Windows calls this
>callback before the QEMU keyboard hook procedure. This disables
>the special left control key filter when the keyboard is grabbed.
>
>To fix the problem, disable the SDL2 Windows low level keyboard
>hook procedure.
>
>Reported-by: Bernhard Beschow <shentey@gmail.com>
>Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>

Tested-by: Bernhard Beschow <shentey@gmail.com>

>---
> ui/sdl2.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/ui/sdl2.c b/ui/sdl2.c
>index 00aadfae37..9d703200bf 100644
>--- a/ui/sdl2.c
>+++ b/ui/sdl2.c
>@@ -855,7 +855,10 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
> #ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR /* only available since SDL 2.0.8 */
>     SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
> #endif
>+#ifndef CONFIG_WIN32
>+    /* QEMU uses its own low level keyboard hook procecure on Windows */
>     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
>+#endif
> #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
>     SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
> #endif
diff mbox series

Patch

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 00aadfae37..9d703200bf 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -855,7 +855,10 @@  static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
 #ifdef SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR /* only available since SDL 2.0.8 */
     SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
 #endif
+#ifndef CONFIG_WIN32
+    /* QEMU uses its own low level keyboard hook procecure on Windows */
     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+#endif
 #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
     SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
 #endif