Skip to content

Commit

Permalink
x11: Don't wait for events when the connection errored out (libsdl-or…
Browse files Browse the repository at this point in the history
…g#8392)

Calling `X11_XIfEvent` after the X11 connection errored out can result in hangs.
  • Loading branch information
Guldoman authored Feb 8, 2025
1 parent 864bb65 commit a0b6c0f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/video/x11/SDL_x11window.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ static bool X11_IsWindowMapped(SDL_VideoDevice *_this, SDL_Window *window)
}
}

static bool X11_IsDisplayOk(Display *display)
{
if (display->flags & XlibDisplayIOError) {
return false;
}
return true;
}

#if 0
static bool X11_IsActionAllowed(SDL_Window *window, Atom action)
{
Expand Down Expand Up @@ -1453,7 +1461,7 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
/* Blocking wait for "MapNotify" event.
* We use X11_XIfEvent because pXWindowEvent takes a mask rather than a type,
* and XCheckTypedWindowEvent doesn't block */
if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
if (!(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
}
X11_XFlush(display);
Expand Down Expand Up @@ -1507,7 +1515,7 @@ void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
if (X11_IsWindowMapped(_this, window)) {
X11_XWithdrawWindow(display, data->xwindow, screen);
// Blocking wait for "UnmapNotify" event
if (!(window->flags & SDL_WINDOW_EXTERNAL)) {
if (!(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
}
X11_XFlush(display);
Expand Down

0 comments on commit a0b6c0f

Please sign in to comment.