diff --git a/CMakeLists.txt b/CMakeLists.txt index d107105473..157f53bdb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3384,6 +3384,10 @@ if (SDL_DIALOG) set(HAVE_SDL_DIALOG TRUE) endif() endif() +if(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) + sdl_sources(${SDL3_SOURCE_DIR}/src/dialog/unix/SDL_zenitymessagebox.h) + sdl_sources(${SDL3_SOURCE_DIR}/src/dialog/unix/SDL_zenitymessagebox.c) +endif() sdl_sources("${SDL3_SOURCE_DIR}/src/process/SDL_process.c") if(WINDOWS) diff --git a/src/video/wayland/SDL_waylandmessagebox.c b/src/dialog/unix/SDL_zenitymessagebox.c similarity index 92% rename from src/video/wayland/SDL_waylandmessagebox.c rename to src/dialog/unix/SDL_zenitymessagebox.c index 3d6f1f87d1..01ca673d3c 100644 --- a/src/video/wayland/SDL_waylandmessagebox.c +++ b/src/dialog/unix/SDL_zenitymessagebox.c @@ -21,9 +21,7 @@ #include "SDL_internal.h" -#ifdef SDL_VIDEO_DRIVER_WAYLAND - -#include "SDL_waylandmessagebox.h" +#include "SDL_zenitymessagebox.h" #define ZENITY_VERSION_LEN 32 // Number of bytes to read from zenity --version (including NUL) @@ -75,7 +73,7 @@ static bool get_zenity_version(int *major, int *minor) return result; } -bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { int zenity_major = 0, zenity_minor = 0, output_len = 0; int argc = 5, i; @@ -84,14 +82,6 @@ bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *butto }; SDL_Process *process; - // Are we trying to connect to or are currently in a Wayland session? - if (!SDL_getenv("WAYLAND_DISPLAY")) { - const char *session = SDL_getenv("XDG_SESSION_TYPE"); - if (session && SDL_strcasecmp(session, "wayland") != 0) { - return SDL_SetError("Not on a wayland display"); - } - } - if (messageboxdata->numbuttons > MAX_BUTTONS) { return SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS); } @@ -193,4 +183,3 @@ bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *butto return true; } -#endif // SDL_VIDEO_DRIVER_WAYLAND diff --git a/src/video/wayland/SDL_waylandmessagebox.h b/src/dialog/unix/SDL_zenitymessagebox.h similarity index 81% rename from src/video/wayland/SDL_waylandmessagebox.h rename to src/dialog/unix/SDL_zenitymessagebox.h index af3012fb92..52ee6a5cc1 100644 --- a/src/video/wayland/SDL_waylandmessagebox.h +++ b/src/dialog/unix/SDL_zenitymessagebox.h @@ -19,13 +19,9 @@ 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SDL_waylandmessagebox_h_ -#define SDL_waylandmessagebox_h_ +#ifndef SDL_zenitymessagebox_h_ +#define SDL_zenitymessagebox_h_ -#ifdef SDL_VIDEO_DRIVER_WAYLAND - -extern bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); - -#endif // SDL_VIDEO_DRIVER_WAYLAND +extern bool SDL_Zenity_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_waylandmessagebox_h_ diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 23fa606ce5..d2cf3962a8 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -25,13 +25,13 @@ #include "../../core/linux/SDL_system_theme.h" #include "../../core/linux/SDL_progressbar.h" +#include "../../dialog/unix/SDL_zenitymessagebox.h" #include "../../events/SDL_events_c.h" #include "SDL_waylandclipboard.h" #include "SDL_waylandcolor.h" #include "SDL_waylandevents_c.h" #include "SDL_waylandkeyboard.h" -#include "SDL_waylandmessagebox.h" #include "SDL_waylandmouse.h" #include "SDL_waylandopengles.h" #include "SDL_waylandvideo.h" @@ -708,14 +708,14 @@ static SDL_VideoDevice *Wayland_Fallback_CreateDevice(void) VideoBootStrap Wayland_preferred_bootstrap = { WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver", Wayland_Preferred_CreateDevice, - Wayland_ShowMessageBox, + SDL_Zenity_ShowMessageBox, true }; VideoBootStrap Wayland_bootstrap = { WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver", Wayland_Fallback_CreateDevice, - Wayland_ShowMessageBox, + SDL_Zenity_ShowMessageBox, false }; diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index f1b6fd4a02..94d386f50a 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -23,6 +23,7 @@ #ifdef SDL_VIDEO_DRIVER_X11 +#include "../../dialog/unix/SDL_zenitymessagebox.h" #include "SDL_x11messagebox.h" #include "SDL_x11toolkit.h" @@ -234,6 +235,10 @@ static bool X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int // Display an x11 message box. bool X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { + if (SDL_Zenity_ShowMessageBox(messageboxdata, buttonID)) { + return true; + } + #if SDL_FORK_MESSAGEBOX // Use a child process to protect against setlocale(). Annoying. pid_t pid;