Browse Source

Use zenity messageboxes by default on X11

This makes messageboxes consistent between X11 and Wayland.
Sam Lantinga 1 day ago
parent
commit
597ef58966

+ 4 - 0
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)

+ 2 - 13
src/video/wayland/SDL_waylandmessagebox.c → 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

+ 3 - 7
src/video/wayland/SDL_waylandmessagebox.h → 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_

+ 3 - 3
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
 };
 

+ 5 - 0
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;