summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-03-22 20:29:23 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-03-22 20:29:23 +0100
commit510ba8e46dc3a5fc980e31ec9621de6dc423c806 (patch)
treed164e077172d5121fd60e8f74e877f78635b7918
parent2c039595110ec3b5804cb6f12615ba9e77f25c0d (diff)
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.
-rw-r--r--test/demo.cxx22
1 files changed, 13 insertions, 9 deletions
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 <stdlib.h>
#include <errno.h>
-#if defined __APPLE__
-#include <ApplicationServices/ApplicationServices.h>
-#endif
-
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
@@ -85,6 +81,14 @@
#include <FL/fl_ask.H> // fl_alert()
#include <FL/fl_utf8.h> // 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 <ApplicationServices/ApplicationServices.h>
+#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