Skip to contentSkip to conversation

SDL2 usability fixes

PATCH Superseded Bernhard Beschow 3 participants 14 messages Apr 12, 2023 – Apr 17, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

 ui/sdl2-input.c | 13 +++++++++++++
 ui/sdl2.c       |  2 ++
 2 files changed, 15 insertions(+)
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/3 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+F4 in fullscreen mode, always causing tasks to be switched in the VM.

---
 ui/sdl2.c | 1 +
 1 file changed, 1 insertion(+)
ui/sdl2.c +1 -0
index b12dec4caf..91705e4bce 100644
@@ -856,6 +856,7 @@ 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");
+    SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
     memset(&info, 0, sizeof(info));
     SDL_VERSION(&info.version);
 
Signature · 1 line
2.40.0
#2 lore raw

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

Am 12. April 2023 20:34:23 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 4 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+F4 in fullscreen mode, always causing tasks to be switched in

Typo: s/Alt+F4/Alt+Tab/

Quoted 19 lines

the VM.

---
ui/sdl2.c | 1 +

1 file changed, 1 insertion(+)
ui/sdl2.c +1 -0
index b12dec4caf..91705e4bce 100644
@@ -856,6 +856,7 @@ 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");
+    SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
    memset(&info, 0, sizeof(info));
    SDL_VERSION(&info.version);
 
#3 lore raw

PATCH 2/3 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 91705e4bce..0031f9bca2 100644
@@ -857,6 +857,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
 #endif
     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
     SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
+    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
#4 lore raw

PATCH 3/3 ui/sdl2-input: Fix AltGr modifier on Windows hosts

In reply to Bernhard Beschow

Windows generates Ctrl + Alt_R for AltGr. By removing the Ctrl modifier Linux guests see AltGr. This fixes e.g. the '~' key on german keyboards.

---
 ui/sdl2-input.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
ui/sdl2-input.c +13 -0
index f068382209..a6538b56d2 100644
@@ -39,6 +39,19 @@ void sdl2_process_key(struct sdl2_console *scon,
         return;
     }
     qcode = qemu_input_map_usb_to_qcode[ev->keysym.scancode];
+
+#ifdef CONFIG_WIN32
+    if (qcode == Q_KEY_CODE_ALT_R &&
+        qkbd_state_modifier_get(scon->kbd, QKBD_MOD_CTRL)) {
+        /*
+         * Windows generates Ctrl + Alt_R for AltGr. By removing the Ctrl
+         * modifier (Linux) guests see AltGr.
+         */
+        trace_sdl2_process_key(ev->keysym.scancode, Q_KEY_CODE_CTRL, "up");
+        qkbd_state_key_event(scon->kbd, Q_KEY_CODE_CTRL, false);
+    }
+#endif
+
     trace_sdl2_process_key(ev->keysym.scancode, qcode,
                            ev->type == SDL_KEYDOWN ? "down" : "up");
     qkbd_state_key_event(scon->kbd, qcode, ev->type == SDL_KEYDOWN);
Signature · 1 line
2.40.0
#5 lore raw
In reply to Bernhard Beschow
Quoted 11 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Quoted 9 lines

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

  ui/sdl2-input.c | 13 +++++++++++++
  ui/sdl2.c       |  2 ++
  2 files changed, 15 insertions(+)

Hi Bernhard,

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts. I'll try to find the commit that caused this regression.

With best regards,
Volker

#6 lore raw

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 16 lines
Quoted 16 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

Quoted 6 lines
Quoted 4 lines
  ui/sdl2-input.c | 13 +++++++++++++
  ui/sdl2.c       |  2 ++
  2 files changed, 15 insertions(+)

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with -accel whpx -vga none -device virtio-vga-gl -display sdl,gl=on and I even get decent OpenGL accelleration when the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 3 lines

With best regards,
Volker

#7 lore raw

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 22 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 20 lines
Quoted 20 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++
   2 files changed, 15 insertions(+)
Quoted 7 lines
Quoted 1 line

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Hi Bernhard,

the keyboard behavior on Windows and Linux is identical. With the QEMU window activated and keyboard not grabbed, those key combos like Alt-Tab or Alt-F4 are sent to the host. With the QEMU window activated and keyboard grabbed they are sent to the guest. I'm not so sure if this should be changed only for SDL on Windows.

With best regards,
Volker

Quoted 11 lines
Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with -accel whpx -vga none -device virtio-vga-gl -display sdl,gl=on and I even get decent OpenGL accelleration when the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 2 lines

With best regards,
Volker

#8 lore raw

Am 13. April 2023 21:40:29 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 24 lines

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 23 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 21 lines
Quoted 11 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Quoted 9 lines

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++
   2 files changed, 15 insertions(+)

Hi Bernhard,

Quoted 8 lines
Quoted 6 lines

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Hi Bernhard,

Hi Volker,

Quoted 2 lines

the keyboard behavior on Windows and Linux is identical. With the QEMU window activated and keyboard not grabbed, those key combos like Alt-Tab or Alt-F4 are sent to the host. With the QEMU window activated and keyboard grabbed they are sent to the guest.

That's the behavior I'd expect. I've confirmed today with 8.0rc4 that patches 1 and 2 are needed to achieve this. I'm using a Windows 11 host and I'm compiling under msys2 on the same Windows host.

Best regards,
Bernhard

Quoted 17 lines

I'm not so sure if this should be changed only for SDL on Windows.

With best regards,
Volker

Quoted 11 lines
Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with -accel whpx -vga none -device virtio-vga-gl -display sdl,gl=on and I even get decent OpenGL accelleration when the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 2 lines

With best regards,
Volker

#9 lore raw
In reply to Bernhard Beschow

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 22 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 20 lines
Quoted 20 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++
   2 files changed, 15 insertions(+)
Quoted 5 lines
Quoted 1 line

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

Hi Bernhard,

the AltGr behavior depends on the keyboard grab. The AltGr key works without keyboard grabbed and it doesn't with keyboard grabbed. That's a bug.

Quoted 7 lines

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with -accel whpx -vga none -device virtio-vga-gl -display sdl,gl=on and I even get decent OpenGL accelleration when the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

I tested with QEMU 7.1 and sometimes it also locks up. This indicates that the QEMU code doesn't have an issue.

With best regards,
Volker

Quoted 7 lines

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 2 lines

With best regards,
Volker

#10 lore raw

Am 14. April 2023 06:53:18 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 23 lines

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 22 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 20 lines
Quoted 20 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++
   2 files changed, 15 insertions(+)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

Hi Bernhard,

Hi Volker,

Quoted 2 lines

the AltGr behavior depends on the keyboard grab. The AltGr key works without keyboard grabbed and it doesn't with keyboard grabbed. That's a bug.

Interesting. The keyboard is grabbed automatically for some reason when the guest enters graphics mode. Together with what you describe this could explain the difference in behavior I'm seeing.

Best regards,
Bernhard

Quoted 22 lines
Quoted 8 lines

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with -accel whpx -vga none -device virtio-vga-gl -display sdl,gl=on and I even get decent OpenGL accelleration when the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

I tested with QEMU 7.1 and sometimes it also locks up. This indicates that the QEMU code doesn't have an issue.

With best regards,
Volker

Quoted 7 lines

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 2 lines

With best regards,
Volker

#11 lore raw
Quoted 29 lines · Bernhard Beschow

Am 14. April 2023 06:53:18 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 28 lines

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 26 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 16 lines
Quoted 16 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

Quoted 5 lines
Quoted 4 lines
   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++
   2 files changed, 15 insertions(+)

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

Quoted 8 lines
Quoted 1 line

Hi Bernhard,

Hi Volker,

Quoted 2 lines

the AltGr behavior depends on the keyboard grab. The AltGr key works without keyboard grabbed and it doesn't with keyboard grabbed. That's a bug.

Interesting. The keyboard is grabbed automatically for some reason when the guest enters graphics mode. Together with what you describe this could explain the difference in behavior I'm seeing.

Not sure how it works on Windows but keyboard grab may depend on the drivers or devices in the guest. I think using a usb-tablet may auto-grab mouse while using a mouse needs to click in the window to grab. Also not sure how this relates to keyboard at all so maybe this is not relevant here in which case sorry for the noise. I guess what I wanted to say is also check what command line you use (what input devices you VM has) and what guest side drivers you use that may have an effect (such as some vmware drivers could or maybe some other drivers). In any case first you should sync to make sure you're on the same page and testing the same thing to avoid some confusion. Sorry if this is not really helpful.

Regrads,
BALATON Zoltan

#12 lore raw
In reply to Volker Rümelin
Quoted 24 lines

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 23 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 21 lines
Quoted 11 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Quoted 9 lines

Bernhard Beschow (3):
    ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++

   2 files changed, 15 insertions(+)

Hi Bernhard,

Quoted 8 lines
Quoted 4 lines

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

Hi Bernhard,

the AltGr behavior depends on the keyboard grab. The AltGr key works without keyboard grabbed and it doesn't with keyboard grabbed. That's a bug.

Hi Bernhard,

this used to work before SDL2-2.0.16. There was no code for Windows in SDL2 to handle keyboard grabs. Version 2.0.16 introduced a Windows low level keyboard hook procedure to grab the keyboard. Windows calls this callback before the QEMU keyboard hook procedure. This explains the observed behavior.

The fix is to disable SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); for Windows. This restores the QEMU keyboard grab for all Windows SDL2 versions. Your first two patches are also necessary. But I think you will need a #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED for older SDL2 versions.

I'll write a patch similar to this one after more tests.

ui/sdl2.c +2 -0
index b011e8d759..9f6b959464 100644
@@ -855,7 +855,9 @@ 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
     SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+#endif
 #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
     /* available since SDL 2.0.16 */
     SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
Signature · 4 lines
2.35.3

With best regards,
Volker
Quoted 24 lines
Quoted 10 lines

What about the other two issues? My other two patches override SDL2 defaults which aren't addressed yet in QEMU AFAICS. The Alt+Tab one isn't even Windows-specific.

Quoted 1 line

Something broke in the last few weeks. At the moment my Linux guest fails to start on Windows with -display sdl. QEMU locks up a short time after the Linux kernel starts.

This doesn't happen for me with 8.0rc4 and latest msys2 environment. I'm running with `-accel whpx -vga none -device virtio-vga-gl
-display sdl,gl=on` and I even get decent OpenGL accelleration when
the Linux guest is in graphics mode, with wobbly windows etc. Sometimes QEMU aborts when it can't map some OpenGL stuff when the guest enters graphics mode but once that succeeds it runs absolutely stable.

Quoted 1 line

I'll try to find the commit that caused this regression.

I tested with QEMU 7.1 and sometimes it also locks up. This indicates that the QEMU code doesn't have an issue.

With best regards,
Volker

Quoted 7 lines

Yes, this would be interesting.

Best regards,
Bernhard

Quoted 2 lines

With best regards,
Volker

#13 lore raw

Am 14. April 2023 19:09:47 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 31 lines
Quoted 31 lines

Am 13.04.23 um 22:43 schrieb Bernhard Beschow:

Quoted 22 lines

Am 13. April 2023 17:54:34 UTC schrieb "Volker Rümelin" <[email protected]>:

Quoted 20 lines
Quoted 20 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 three 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
* AltGr keyboard modifier isn't recognized by a Linux guest

More information about each issue is provided in the patches.

Bernhard Beschow (3):
    ui/sdl2: Grab Alt+Tab also in fullscreen mode ui/sdl2: Grab Alt+F4 also under Windows ui/sdl2-input: Fix AltGr modifier on Windows hosts

   ui/sdl2-input.c | 13 +++++++++++++
   ui/sdl2.c       |  2 ++

   2 files changed, 15 insertions(+)
Quoted 5 lines
Quoted 1 line

Hi Bernhard,

Hi Volker,

Quoted 1 line

I don't think these patches are necessary. The AltGr key and the keyboard grab was fixed in 2020 with commit 830473455f ("ui/sdl2: fix handling of AltGr key on Windows") and a few commits before.

Indeed, this patch addresses the AltGr issue. What I noticed in my case is that the AltGr behavior is different, depending on whether the *guest* is in graphics mode or not. Pressing AltGr in graphics mode issues two key modifiers while only one is issued when the guest is in text mode. I'll recheck tomorrow when I have access to a Windows host.

Hi Bernhard,

Quoted 7 lines
Quoted 1 line

the AltGr behavior depends on the keyboard grab. The AltGr key works without keyboard grabbed and it doesn't with keyboard grabbed. That's a bug.

Hi Bernhard,

this used to work before SDL2-2.0.16. There was no code for Windows in SDL2 to handle keyboard grabs. Version 2.0.16 introduced a Windows low level keyboard hook procedure to grab the keyboard. Windows calls this callback before the QEMU keyboard hook procedure. This explains the observed behavior.

The fix is to disable SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); for Windows. This restores the QEMU keyboard grab for all Windows SDL2 versions.

As you wrote below I'll let you take care of it. Thanks!

Quoted 1 line

Your first two patches are also necessary. But I think you will need a #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED for older SDL2 versions.

[x] Done

v2 is out!

Best regards,
Bernhard

Quoted 17 lines

I'll write a patch similar to this one after more tests.

ui/sdl2.c +2 -0
index b011e8d759..9f6b959464 100644
@@ -855,7 +855,9 @@ 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
    SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
+#endif
 #ifdef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED
    /* available since SDL 2.0.16 */
    SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");