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.
This commit is contained in:
Frank Praznik
2026-07-14 14:40:55 -04:00
parent 8408a664e2
commit e442a9a5e1

View File

@@ -1642,14 +1642,16 @@ void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
Display *display = data->videodata->display;
XEvent event;
if (X11_IsWindowMapped(_this, window)) {
X11_XWithdrawWindow(display, data->xwindow, screen);
// Blocking wait for "UnmapNotify" event
if (!(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
}
X11_XFlush(display);
/* Some window managers will mark minimized or offscreen windows as unmapped, so we
* must not block while waiting for an UnmapNotify event that will never arrive.
*/
const bool is_mapped = X11_IsWindowMapped(_this, window);
X11_XWithdrawWindow(display, data->xwindow, screen);
if (is_mapped && !(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
// Blocking wait for "UnmapNotify" event.
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
}
X11_XFlush(display);
// Transfer keyboard focus back to the parent
if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {