Skip to content

Commit 342a6eb

Browse files
authored
Merge pull request #912 from hx2A/thinkdifferent-activate
New `ThinkDifferent` method `activateSketchWindow()`
2 parents 7b2a490 + 6dc5369 commit 342a6eb

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

core/different/different.m

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import <AppKit/AppKit.h>
22
#import <Cocoa/Cocoa.h>
3-
#import <JavaNativeFoundation/JavaNativeFoundation.h>
4-
// #include <jni.h>
3+
// #import <JavaNativeFoundation/JavaNativeFoundation.h>
4+
#include <jni.h>
55

66
JNIEXPORT void JNICALL Java_processing_core_ThinkDifferent_hideMenuBar
77
(JNIEnv *env, jclass clazz, jboolean visible, jboolean kioskMode)
@@ -24,3 +24,10 @@
2424
{
2525
[NSApp activateIgnoringOtherApps:true];
2626
}
27+
28+
29+
JNIEXPORT void JNICALL Java_processing_core_ThinkDifferent_activate
30+
(JNIEnv *env, jclass klass)
31+
{
32+
[NSApp activate];
33+
}

core/different/libDifferent_aarch64

135 Bytes
Binary file not shown.

core/different/libDifferent_x86_64

-23.9 KB
Binary file not shown.

core/src/processing/core/ThinkDifferent.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,33 @@ static private Desktop getDesktop() {
124124

125125
static native public void showMenuBar();
126126

127-
// Used by Python (Jython) Mode to bring windows to the front
127+
// deprecated
128+
// https://developer.apple.com/documentation/appkit/nsapplication/activate(ignoringotherapps:)
128129
static native public void activateIgnoringOtherApps();
129130

131+
// added in macOS 14 (Sonoma)
132+
// https://developer.apple.com/documentation/appkit/nsapplication/activate()
133+
static native public void activate();
134+
135+
// Used by py5 to bring Sketch to the front
136+
static public boolean activateSketchWindow() {
137+
try {
138+
String osVersion = System.getProperty("os.version");
139+
int versionNumber = Integer.parseInt(osVersion.split("\\.")[0]);
140+
141+
if (versionNumber >= 14) {
142+
activate();
143+
return true;
144+
} else if (versionNumber >= 10) {
145+
activateIgnoringOtherApps();
146+
return true;
147+
}
148+
} catch (Exception e) {
149+
return false;
150+
}
151+
152+
return false;
153+
}
130154

131155
static {
132156
final String NATIVE_FILENAME = "libDifferent.jnilib";
-47.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)