Skip to content

Commit 7cf05b9

Browse files
committed
macOS: register with window server via TransformProcessType for subprocess window display
1 parent af50607 commit 7cf05b9

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

mode/CppMode.jar

-554 Bytes
Binary file not shown.

src/Processing.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,20 @@ void PApplet::run(){
33643364
initPerlin(0); // initialize noise table with default seed
33653365

33663366
#if defined(__APPLE__)
3367+
// Register with macOS window server -- required when launched as a subprocess
3368+
// (e.g. from Processing IDE). Without this, GLFW cannot create windows.
3369+
{
3370+
void* handle = dlopen("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices", RTLD_LAZY);
3371+
if (handle) {
3372+
typedef int (*TFunc)(void*);
3373+
TFunc f = (TFunc)dlsym(handle, "TransformProcessType");
3374+
if (f) {
3375+
// kProcessTransformToForegroundApplication = 1
3376+
unsigned int psn[2] = {0, 1}; // kCurrentProcess
3377+
f(psn);
3378+
}
3379+
}
3380+
}
33673381
glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE);
33683382
#endif
33693383
if(!glfwInit()){

src/java/CppRunner.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,10 @@ public void launch() {
3535
}
3636
ProcessBuilder pb;
3737
if (System.getProperty("os.name","").toLowerCase().contains("mac")) {
38-
// macOS: wrap in minimal .app bundle so the process gets window server access
39-
java.io.File appBundle = new java.io.File(sketchFolder, exeToRun.getName() + ".app");
40-
java.io.File macosDir = new java.io.File(appBundle, "Contents/MacOS");
41-
macosDir.mkdirs();
42-
java.io.File bundledBin = new java.io.File(macosDir, exeToRun.getName());
43-
java.nio.file.Files.copy(exeToRun.toPath(), bundledBin.toPath(),
44-
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
45-
bundledBin.setExecutable(true);
46-
// Write minimal Info.plist
47-
java.io.File plist = new java.io.File(appBundle, "Contents/Info.plist");
48-
java.nio.file.Files.writeString(plist.toPath(),
49-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
50-
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
51-
+ "<plist version=\"1.0\"><dict>\n"
52-
+ "<key>CFBundleExecutable</key><string>" + exeToRun.getName() + "</string>\n"
53-
+ "<key>CFBundleIdentifier</key><string>processing.cpp." + exeToRun.getName() + "</string>\n"
54-
+ "<key>CFBundleName</key><string>" + exeToRun.getName() + "</string>\n"
55-
+ "<key>NSHighResolutionCapable</key><true/>\n"
56-
+ "<key>NSPrincipalClass</key><string>NSApplication</string>\n"
57-
+ "</dict></plist>\n");
58-
pb = new ProcessBuilder("open", "-W", "-n", appBundle.getAbsolutePath());
38+
// macOS: launch directly -- the .app bundle approach breaks stdio piping
39+
// Just run the binary directly; modern macOS allows subprocess windows
40+
// as long as the parent process has screen access (Processing does).
41+
pb = new ProcessBuilder(exeToRun.getAbsolutePath());
5942
} else {
6043
pb = new ProcessBuilder(exeToRun.getAbsolutePath());
6144
}

0 commit comments

Comments
 (0)