Use zenity messageboxes by default on X11

This makes messageboxes consistent between X11 and Wayland.
This commit is contained in:
Sam Lantinga
2025-09-20 08:05:45 -07:00
parent 9cefbab766
commit 597ef58966
5 changed files with 17 additions and 23 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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_

View File

@@ -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
};

View File

@@ -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;