[PATCH v2 2/2] ui/sdl2: Grab Alt+F4 also under Windows

Bernhard Beschow posted 2 patches 2 years, 9 months ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH v2 2/2] ui/sdl2: Grab Alt+F4 also under Windows
Posted by Bernhard Beschow 2 years, 9 months ago
SDL doesn't grab Alt+F4 under Windows by default. Pressing Alt+F4 thus closes
the VM immediately without confirmation, possibly leading to data loss. Fix
this by always grabbing Alt+F4 on Windows hosts, too.

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 ui/sdl2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 8af8b89f1d..00aadfae37 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -859,6 +859,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
 #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
     SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
 #endif
+    SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
     memset(&info, 0, sizeof(info));
     SDL_VERSION(&info.version);
 
-- 
2.40.0
Re: [PATCH v2 2/2] ui/sdl2: Grab Alt+F4 also under Windows
Posted by Volker Rümelin 2 years, 9 months ago
> SDL doesn't grab Alt+F4 under Windows by default. Pressing Alt+F4 thus closes
> the VM immediately without confirmation, possibly leading to data loss. Fix
> this by always grabbing Alt+F4 on Windows hosts, too.
>
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
>   ui/sdl2.c | 1 +
>   1 file changed, 1 insertion(+)

Reviewed-by: Volker Rümelin <vr_qemu@t-online.de>

> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index 8af8b89f1d..00aadfae37 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -859,6 +859,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
>   #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
>       SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
>   #endif
> +    SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
>       memset(&info, 0, sizeof(info));
>       SDL_VERSION(&info.version);
>