Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Make sure a window is valid for a subsystem before using it in a mess…
Browse files Browse the repository at this point in the history
…agebox
  • Loading branch information
slouken committed Jul 14, 2013
1 parent 90655b5 commit acbe73f
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions src/video/SDL_video.c
Expand Up @@ -3052,6 +3052,20 @@ SDL_IsScreenKeyboardShown(SDL_Window *window)
#include "x11/SDL_x11messagebox.h"
#endif

static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
{
SDL_SysWMinfo info;
SDL_Window *window = messageboxdata->window;

if (!window) {
return SDL_TRUE;
}

SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window, &info);
return (info.subsystem == drivertype);
}

int
SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
Expand All @@ -3071,35 +3085,42 @@ SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
if (!buttonid) {
buttonid = &dummybutton;
}

if (_this && _this->ShowMessageBox) {
retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
} else {
/* It's completely fine to call this function before video is initialized */
if (messageboxdata->window == NULL) {
}

/* It's completely fine to call this function before video is initialized */
#if SDL_VIDEO_DRIVER_WINDOWS
if ((retval == -1) && (WIN_ShowMessageBox(messageboxdata, buttonid) == 0)) {
retval = 0;
}
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_COCOA
if ((retval == -1) && (Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0)) {
retval = 0;
}
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_UIKIT
if ((retval == -1) && (UIKit_ShowMessageBox(messageboxdata, buttonid) == 0)) {
retval = 0;
}
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_X11
if ((retval == -1) && (X11_ShowMessageBox(messageboxdata, buttonid) == 0)) {
retval = 0;
}
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
}
if (retval == -1) {
SDL_SetError("No message system available");
}
if (retval == -1) {
SDL_SetError("No message system available");
}

SDL_ShowCursor(show_cursor_prev);
Expand Down

0 comments on commit acbe73f

Please sign in to comment.