Skip to contentSkip to conversation

SDL2 usability fixes

PATCH In review Bernhard Beschow 2 participants 6 messages Apr 17, 2023 – May 10, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover SDL2 usability fixes

I'm trying to use QEMU on Windows hosts for fun and for profit. While the GTK GUI doesn't seem to support OpenGL under Windows the SDL2 GUI does. Hence I used the SDL2 GUI where I ran into several issues of which two are fixed in this series, which are:

* Alt+Tab switches tasks on the host rather than in the guest in fullscreen mode
* Alt+F4 closes QEMU rather than a graphical task in the guest

More information about each issue is provided in the patches.

v2:
* Omit AltGr patch since Voker is taking care of it
* Protect Alt+Tab hint with #ifdef (Volker)

Bernhard Beschow (2):
ui/sdl2: Grab Alt+Tab also in fullscreen mode
ui/sdl2: Grab Alt+F4 also under Windows

 ui/sdl2.c | 4 ++++
 1 file changed, 4 insertions(+)
Signature · 1 line
2.40.0
#1 lore raw

PATCH v2 1/2 ui/sdl2: Grab Alt+Tab also in fullscreen mode

By default, SDL grabs Alt+Tab only in non-fullscreen mode. This causes Alt+Tab to switch tasks on the host rather than in the VM in fullscreen mode while it switches tasks in non-fullscreen mode in the VM. Fix this confusing behavior by grabbing Alt+Tab in fullscreen mode, always causing tasks to be switched in the VM.

---
 ui/sdl2.c | 3 +++
 1 file changed, 3 insertions(+)
ui/sdl2.c +3 -0
index b12dec4caf..8af8b89f1d 100644
@@ -856,6 +856,9 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
     SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
 #endif
     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+#ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
+    SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
+#endif
     memset(&info, 0, sizeof(info));
     SDL_VERSION(&info.version);
 
Signature · 1 line
2.40.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] ui/sdl2: Grab Alt+Tab also in fullscreen mode

Quoted 10 lines

By default, SDL grabs Alt+Tab only in non-fullscreen mode. This causes Alt+Tab to switch tasks on the host rather than in the VM in fullscreen mode while it switches tasks in non-fullscreen mode in the VM. Fix this confusing behavior by grabbing Alt+Tab in fullscreen mode, always causing tasks to be switched in the VM.

---
  ui/sdl2.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 14 lines
ui/sdl2.c +3 -0
index b12dec4caf..8af8b89f1d 100644
@@ -856,6 +856,9 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
      SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
  #endif
      SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+#ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
+    SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
+#endif
      memset(&info, 0, sizeof(info));
      SDL_VERSION(&info.version);
 
#3 lore raw

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

In reply to Bernhard Beschow

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.

---
 ui/sdl2.c | 1 +
 1 file changed, 1 insertion(+)
ui/sdl2.c +1 -0
index 8af8b89f1d..00aadfae37 100644
@@ -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);
 
Signature · 1 line
2.40.0
Reviewed-by on v2 2/2
#4 lore raw

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

Quoted 8 lines

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.

---
  ui/sdl2.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 12 lines
ui/sdl2.c +1 -0
index 8af8b89f1d..00aadfae37 100644
@@ -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);
 
#5 lore raw
In reply to Bernhard Beschow

Am 17. April 2023 19:21:37 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 28 lines

I'm trying to use QEMU on Windows hosts for fun and for profit. While the GTK

GUI doesn't seem to support OpenGL under Windows the SDL2 GUI does. Hence I

used the SDL2 GUI where I ran into several issues of which two are fixed in

this series, which are:

* Alt+Tab switches tasks on the host rather than in the guest in fullscreen mode

* Alt+F4 closes QEMU rather than a graphical task in the guest

More information about each issue is provided in the patches.

v2:

* Omit AltGr patch since Voker is taking care of it

* Protect Alt+Tab hint with #ifdef (Volker)

Quoted 5 lines

Bernhard Beschow (2):

ui/sdl2: Grab Alt+Tab also in fullscreen mode

ui/sdl2: Grab Alt+F4 also under Windows

Ping

All patches reviewed

Quoted 14 lines

ui/sdl2.c | 4 ++++

1 file changed, 4 insertions(+)

-- >
2.40.0