Skip to contentSkip to conversation

sdl2: Work around SDL2 SDL_ShowWindow() bug

PATCH In review Max Reitz 2 participants 4 messages Dec 12, 2014

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover sdl2: Work around SDL2 SDL_ShowWindow() bug

For the bug (it at least seems to me like one), see:
https://bugzilla.libsdl.org/show_bug.cgi?id=2818

To reproduce it in qemu, try pressing ctrl-alt-2 five times (or whichever your key combination for showing/hiding the monitor window is).

Normally, the window should be shown, hidden, shown, hidden and shown again. However, it will instead be shown, hidden, stay hidden, stay hidden and then be shown. This series fixes this.

This series depends on Gerd's series
"sdl2: fixes, cleanups and opengl preparation."

Max Reitz (2):
sdl2: Use correct sdl2_console for window events
sdl2: Work around SDL2 SDL_ShowWindow() bug

 ui/sdl2.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH 1/2 sdl2: Use correct sdl2_console for window events

SDL_PollEvent() polls events for all windows; therefore, sdl2_poll_events() will poll the events for all windows and not only for the one identified by the given sdl2_console.

This should be considered in handle_windowevent(): The window affected by the event is not necessarily the one identified by the sdl2_console object given to sdl2_poll_events(), but the one identified by ev->window.windowID.

---
 ui/sdl2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ui/sdl2.c +4 -2
index a1def81..fdc762f 100644
@@ -507,8 +507,10 @@ static void handle_mousewheel(SDL_Event *ev)
     qemu_input_event_sync();
 }
 
-static void handle_windowevent(struct sdl2_console *scon, SDL_Event *ev)
+static void handle_windowevent(SDL_Event *ev)
 {
+    struct sdl2_console *scon = get_scon_from_window(ev->window.windowID);
+
     switch (ev->window.event) {
     case SDL_WINDOWEVENT_RESIZED:
         {
@@ -586,7 +588,7 @@ void sdl2_poll_events(struct sdl2_console *scon)
             handle_mousewheel(ev);
             break;
         case SDL_WINDOWEVENT:
-            handle_windowevent(scon, ev);
+            handle_windowevent(ev);
             break;
         default:
             break;
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH 2/2 sdl2: Work around SDL2 SDL_ShowWindow() bug

In reply to Max Reitz

Apparently it is possible for X to send an event to a hidden SDL2 window, leading to SDL2 believing it is now shown. SDL2 will pass the SDL_WINDOWEVENT_SHOWN message to the application without actually showing the window; the problem is that the next SDL_ShowWindow() will be a no-op because SDL2 assumes the window is already shown.

The correct way to react to SDL_WINDOWEVENT_SHOWN would be to clear scon->hidden (analogous for SDL_WINDOWEVENT_HIDDEN). However, due to the window not actually being shown, this will somehow not be correct after all.

Therefore, just hide the window on SDL_WINDOWEVENT_SHOWN if it is supposed to be hidden (and analogous for SDL_WINDOWEVENT_HIDDEN).

---
 ui/sdl2.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
ui/sdl2.c +10 -0
index fdc762f..7297c02 100644
@@ -548,6 +548,16 @@ static void handle_windowevent(SDL_Event *ev)
             qemu_system_shutdown_request();
         }
         break;
+    case SDL_WINDOWEVENT_SHOWN:
+        if (scon->hidden) {
+            SDL_HideWindow(scon->real_window);
+        }
+        break;
+    case SDL_WINDOWEVENT_HIDDEN:
+        if (!scon->hidden) {
+            SDL_ShowWindow(scon->real_window);
+        }
+        break;
     }
 }
 
Signature · 1 line
1.9.3
#3 lore raw
In reply to Max Reitz
Quoted 7 lines · Max Reitz

For the bug (it at least seems to me like one), see:
https://bugzilla.libsdl.org/show_bug.cgi?id=2818

To reproduce it in qemu, try pressing ctrl-alt-2 five times (or whichever your key combination for showing/hiding the monitor window is).

Quoted 6 lines

Normally, the window should be shown, hidden, shown, hidden and shown again. However, it will instead be shown, hidden, stay hidden, stay hidden and then be shown. This series fixes this.

This series depends on Gerd's series
"sdl2: fixes, cleanups and opengl preparation."

Added to sdl queue.

thanks,
Gerd