Fixed bug 2500 - X11: SDL tries (and fails) to hide foreign windows

Alvin

I'm interested in this bug as well. I have experienced it when trying to embed an SDL_Window into a FLTK application. To do this, I create a FLTK window (window inside a window - think video player) and then use SDL_CreateWindowFrom() on the inner most window's Xlib Window*. After which, I create a renderer.

In my situation I am using the FLTK GUI toolkit.

What I have experienced is that the SDL_CreateRender() will recreate the window in order to properly setup OpenGL capability. As part of this process, the window is hidden and a call is executed that waits indefinitely for an acknowledgement that the window was indeed unmapped. This is where my program hangs.

Please correct me if I am wrong, but should SDL2 not make Xlib calls that effect the Xlib Window in this situation (e.g. When SDL_CreateWindowFrom() is used)? The toolkit being used typically assumes responsibility and, I presume, tracks all Xlib Windows it creates.

On line src/video/SDL_video.c:1372 the comment associated with setting SDL_WINDOW_FOREIGN reads:

  /* Can't destroy and re-create foreign windows, hrm */

Since I do not know the reason for hiding the window in the first place, the attached patch simply does not wait for a response when X11_XWithdrawWindow() and X11_XMapRaised() are issued by X11_HideWindow() and X11_ShowWindow(), respectively. I presume that the GUI toolkit (GTK, FLTK, etc.) has or will consume the acknowledging event as it is managing the Xlib Window (or it thinks it is).

I have tested the patch against hg 5c645d037de2 and I have successfully tested:
* Embedding the SDL_Window inside a FLTK application.
* Calling SDL_SetWindowSize() when FLTK resizes the window (e.g. dragging cursor on the edge of the window).
* Filling the renderer's default target blue and drawing a red fill square at the centre (exciting, I know!)
* Calling SDL_Quit() when the application terminates

I do not receive any Xlib erorr messages (BadWindow, etc.) in any of those situations.
This commit is contained in:
Sam Lantinga 2017-08-14 10:28:47 -07:00
parent c350d91a6a
commit 362d549690
1 changed files with 4 additions and 2 deletions

View File

@ -1041,7 +1041,8 @@ X11_ShowWindow(_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 */
X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
if(!(window->flags & SDL_WINDOW_FOREIGN))
X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
X11_XFlush(display);
}
@ -1063,7 +1064,8 @@ X11_HideWindow(_THIS, SDL_Window * window)
if (X11_IsWindowMapped(_this, window)) {
X11_XWithdrawWindow(display, data->xwindow, displaydata->screen);
/* Blocking wait for "UnmapNotify" event */
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
if(!(window->flags & SDL_WINDOW_FOREIGN))
X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
X11_XFlush(display);
}
}