Skip to content

Commit bad5dce

Browse files
committed
x11: Ensure that parent windows for a dialog are from the X11 driver
If the system doesn't have Zenity installed, message boxes can fall back to the X11 toolkit while the Wayland driver is in use, in which case, a Wayland window may be set as a parent to an X11 dialog. Ensure that the parent window for an X11 dialog is actually an X11 window.
1 parent ac29b02 commit bad5dce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/video/x11/SDL_x11messagebox.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ static void X11_OnMessageBoxScaleChange(SDL_ToolkitWindowX11 *window, void *data
288288

289289
static bool X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID)
290290
{
291+
SDL_VideoDevice *video = SDL_GetVideoDevice();
292+
SDL_Window *parent_window = NULL;
291293
SDL_MessageBoxControlsX11 controls;
292294
SDL_MessageBoxCallbackDataX11 data;
293295
const SDL_MessageBoxColor *colorhints;
@@ -305,10 +307,14 @@ static bool X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int
305307
}
306308

307309
/* Create window */
310+
if (messageboxdata->window && SDL_strcmp(video->name, "x11") == 0) {
311+
// Only use the window as a parent if it is from the X11 driver.
312+
parent_window = messageboxdata->window;
313+
}
308314
#if SDL_FORK_MESSAGEBOX
309-
controls.window = X11Toolkit_CreateWindowStruct(messageboxdata->window, NULL, SDL_TOOLKIT_WINDOW_MODE_X11_DIALOG, colorhints, true);
315+
controls.window = X11Toolkit_CreateWindowStruct(parent_window, NULL, SDL_TOOLKIT_WINDOW_MODE_X11_DIALOG, colorhints, true);
310316
#else
311-
controls.window = X11Toolkit_CreateWindowStruct(messageboxdata->window, NULL, SDL_TOOLKIT_WINDOW_MODE_X11_DIALOG, colorhints, false);
317+
controls.window = X11Toolkit_CreateWindowStruct(parent_window, NULL, SDL_TOOLKIT_WINDOW_MODE_X11_DIALOG, colorhints, false);
312318
#endif
313319
controls.window->cb_data = &controls;
314320
controls.window->cb_on_scale_change = X11_OnMessageBoxScaleChange;

0 commit comments

Comments
 (0)