From 510ba8e46dc3a5fc980e31ec9621de6dc423c806 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Wed, 22 Mar 2023 20:29:23 +0100 Subject: Fix test/demo for X11 on macOS (e.g. XQuartz) This modification became necessary since "__APPLE__" is no longer undefined by the build system when X11 is used on macOS. --- test/demo.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/demo.cxx b/test/demo.cxx index 2204b1cba..d24fd92a2 100644 --- a/test/demo.cxx +++ b/test/demo.cxx @@ -69,10 +69,6 @@ #include #include -#if defined __APPLE__ -#include -#endif - #include #include #include @@ -85,6 +81,14 @@ #include // fl_alert() #include // fl_getcwd() +// Define USE_MAC_OS for convenience (below). We use macOS specific features (bundles +// and paths) if USE_MAC_OS is defined, otherwise we're using X11 (XQuartz) on macOS + +#if defined __APPLE__ && !defined(FLTK_USE_X11) +#define USE_MAC_OS +#include +#endif + #define FORM_W 350 #define FORM_H 440 #define TTY_W 700 @@ -122,7 +126,7 @@ char command [2 * FL_PATH_MAX + 40]; // command to be executed #ifdef _WIN32 const char *suffix = ".exe"; -#elif defined __APPLE__ +#elif defined USE_MAC_OS const char *suffix = ".app"; #else const char *suffix = ""; @@ -393,7 +397,7 @@ void dobut(Fl_Widget *, long arg) { // format commandline with optional parameters -#if defined(__APPLE__) // macOS +#if defined(USE_MAC_OS) // macOS if (params[0]) { // we assume that we have only one argument which is a filename in 'data_path' @@ -431,13 +435,13 @@ void dobut(Fl_Widget *, long arg) { fl_alert("Error starting process, error #%lu\n'%s'", err, command); } -#elif defined __APPLE__ +#elif defined USE_MAC_OS debug_var("Command", command); system(command); -#else // other platforms (Unix, Linux) +#else // other platforms (Unix, Linux, X11, and XQuartz on macOS) strcat(command, " &"); // run in background @@ -534,7 +538,7 @@ int main(int argc, char **argv) { // construct app_path for all executable files fl_filename_absolute(app_path, sizeof(app_path), argv[0]); -#ifdef __APPLE__ +#if defined(USE_MAC_OS) char *q = strstr(app_path, "/Contents/MacOS/"); if (q) *q = 0; #endif -- cgit v1.2.3