Skip to content

Commit e442a9a

Browse files
committed
x11: Don't block when withdrawing unmapped windows
Some window managers will mark minimized or offscreen windows as unmapped. When hiding a window, unconditionally call XWithdrawWindow, and don't wait for an UnmapNotify event if the window is already in the unmapped state, or it will block indefinitely waiting for an event that never arrives.
1 parent 8408a66 commit e442a9a

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/video/x11/SDL_x11window.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,14 +1642,16 @@ void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
16421642
Display *display = data->videodata->display;
16431643
XEvent event;
16441644

1645-
if (X11_IsWindowMapped(_this, window)) {
1646-
X11_XWithdrawWindow(display, data->xwindow, screen);
1647-
// Blocking wait for "UnmapNotify" event
1648-
if (!(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
1649-
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
1650-
}
1651-
X11_XFlush(display);
1645+
/* Some window managers will mark minimized or offscreen windows as unmapped, so we
1646+
* must not block while waiting for an UnmapNotify event that will never arrive.
1647+
*/
1648+
const bool is_mapped = X11_IsWindowMapped(_this, window);
1649+
X11_XWithdrawWindow(display, data->xwindow, screen);
1650+
if (is_mapped && !(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
1651+
// Blocking wait for "UnmapNotify" event.
1652+
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
16521653
}
1654+
X11_XFlush(display);
16531655

16541656
// Transfer keyboard focus back to the parent
16551657
if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {

0 commit comments

Comments
 (0)