diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeMacLibrary.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeMacLibrary.java index 2a1b24c3..3799bfd9 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeMacLibrary.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeMacLibrary.java @@ -23,6 +23,20 @@ import java.awt.Window; *
* Note: This is private API. Do not use! * + *
{@code
+ * if( !window.isDisplayable() )
+ * window.addNotify();
+ * }
+ * or invoke the method after packing the window. E.g.
+ * {@code
+ * window.pack();
+ * }
+ *
* @author Karl Tauber
* @since 3.3
*/
@@ -38,22 +52,5 @@ public class FlatNativeMacLibrary
return FlatNativeLibrary.isLoaded();
}
- /**
- * Gets the macOS window pointer (NSWindow) for the given Swing window.
- * - * Note that the underlying macOS window must be already created, - * otherwise this method returns zero. Use following to ensure this: - *
{@code
- * if( !window.isDisplayable() )
- * window.addNotify();
- * }
- * or invoke this method after packing the window. E.g.
- * {@code
- * window.pack();
- * long windowPtr = getWindowPtr( window );
- * }
- */
- public native static long getWindowPtr( Window window );
-
- public native static void setWindowRoundedBorder( long windowPtr, float radius, float borderWidth, int borderColor );
+ public native static boolean setWindowRoundedBorder( Window window, float radius, float borderWidth, int borderColor );
}
diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java
index 8aa636f0..9039c28d 100644
--- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java
+++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java
@@ -324,13 +324,6 @@ public class FlatPopupFactory
if( !popupWindow.isDisplayable() )
popupWindow.addNotify();
- // get native window handle/pointer
- long hwnd = SystemInfo.isWindows
- ? FlatNativeWindowsLibrary.getHWND( popupWindow )
- : FlatNativeMacLibrary.getWindowPtr( popupWindow );
- if( hwnd == 0 )
- return;
-
int borderCornerRadius = getBorderCornerRadius( owner, contents );
float borderWidth = getRoundedBorderWidth( owner, contents );
@@ -353,6 +346,9 @@ public class FlatPopupFactory
}
if( SystemInfo.isWindows ) {
+ // get native window handle
+ long hwnd = FlatNativeWindowsLibrary.getHWND( popupWindow );
+
// set corner preference
int cornerPreference = (borderCornerRadius <= 4)
? FlatNativeWindowsLibrary.DWMWCP_ROUNDSMALL // 4px
@@ -366,7 +362,7 @@ public class FlatPopupFactory
borderWidth = 0;
// set corner radius, border width and color
- FlatNativeMacLibrary.setWindowRoundedBorder( hwnd, borderCornerRadius,
+ FlatNativeMacLibrary.setWindowRoundedBorder( popupWindow, borderCornerRadius,
borderWidth, (borderColor != null) ? borderColor.getRGB() : 0 );
}
}
diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-arm64.dylib b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-arm64.dylib
old mode 100644
new mode 100755
index 6094c831..e29df3b1
Binary files a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-arm64.dylib and b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-arm64.dylib differ
diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-x86_64.dylib b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-x86_64.dylib
old mode 100644
new mode 100755
index a15d4876..bb1c221c
Binary files a/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-x86_64.dylib and b/flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-x86_64.dylib differ
diff --git a/flatlaf-natives/flatlaf-natives-macos/build.gradle.kts b/flatlaf-natives/flatlaf-natives-macos/build.gradle.kts
index b6b24745..322b1998 100644
--- a/flatlaf-natives/flatlaf-natives-macos/build.gradle.kts
+++ b/flatlaf-natives/flatlaf-natives-macos/build.gradle.kts
@@ -81,7 +81,7 @@ tasks {
val nativesDir = project( ":flatlaf-core" ).projectDir.resolve( "src/main/resources/com/formdev/flatlaf/natives" )
val isARM64 = name.contains( "Arm64" )
val minOs = if( isARM64 ) minOsARM64 else minOsX86_64
- val libraryName = if( isARM64 ) "flatlaf-macos-arm64.dylib" else "flatlaf-macos-x86_64.dylib"
+ val libraryName = if( isARM64 ) "libflatlaf-macos-arm64.dylib" else "libflatlaf-macos-x86_64.dylib"
linkerArgs.addAll( toolChain.map {
when( it ) {
@@ -91,14 +91,17 @@ tasks {
} )
doLast {
+ // sign shared library
+// exec { commandLine( "codesign", "-s", "FormDev Software GmbH", "--timestamp", "${linkedFile.asFile.get()}" ) }
+
// copy shared library to flatlaf-core resources
copy {
from( linkedFile )
into( nativesDir )
- rename( "flatlaf-natives-macos.dylib", libraryName )
+ rename( "libflatlaf-natives-macos.dylib", libraryName )
}
-///*dump
+/*dump
val dylib = linkedFile.asFile.get()
val dylibDir = dylib.parent
exec { commandLine( "size", dylib ) }
@@ -123,7 +126,7 @@ tasks {
}
exec { commandLine( "objdump", "--disassemble-all", dylib ); standardOutput = FileOutputStream( "$dylibDir/disassemble.txt" ) }
exec { commandLine( "objdump", "--full-contents", dylib ); standardOutput = FileOutputStream( "$dylibDir/full-contents.txt" ) }
-//dump*/
+dump*/
}
}
}
diff --git a/flatlaf-natives/flatlaf-natives-macos/src/main/headers/JNIUtils.h b/flatlaf-natives/flatlaf-natives-macos/src/main/headers/JNIUtils.h
index 8e5be892..2de80956 100644
--- a/flatlaf-natives/flatlaf-natives-macos/src/main/headers/JNIUtils.h
+++ b/flatlaf-natives/flatlaf-natives-macos/src/main/headers/JNIUtils.h
@@ -23,9 +23,9 @@
*/
-// from JNFJNI.h
+// from jlong_md.h
#ifndef jlong_to_ptr
-#define jlong_to_ptr(a) ((void *)(uintptr_t)(a))
+ #define jlong_to_ptr(a) ((void*)(a))
#endif
@@ -39,3 +39,6 @@
[ex name], [ex reason], [ex userInfo], [ex callStackSymbols] ); \
} \
}
+
+
+jfieldID getFieldID( JNIEnv *env, const char* className, const char* fieldName, const char* fieldSignature );
diff --git a/flatlaf-natives/flatlaf-natives-macos/src/main/headers/com_formdev_flatlaf_ui_FlatNativeMacLibrary.h b/flatlaf-natives/flatlaf-natives-macos/src/main/headers/com_formdev_flatlaf_ui_FlatNativeMacLibrary.h
index f4d55eed..f5bcd35b 100644
--- a/flatlaf-natives/flatlaf-natives-macos/src/main/headers/com_formdev_flatlaf_ui_FlatNativeMacLibrary.h
+++ b/flatlaf-natives/flatlaf-natives-macos/src/main/headers/com_formdev_flatlaf_ui_FlatNativeMacLibrary.h
@@ -7,21 +7,13 @@
#ifdef __cplusplus
extern "C" {
#endif
-/*
- * Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
- * Method: getWindowPtr
- * Signature: (Ljava/awt/Window;)J
- */
-JNIEXPORT jlong JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_getWindowPtr
- (JNIEnv *, jclass, jobject);
-
/*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
* Method: setWindowRoundedBorder
- * Signature: (JFFI)V
+ * Signature: (Ljava/awt/Window;FFI)Z
*/
-JNIEXPORT void JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_setWindowRoundedBorder
- (JNIEnv *, jclass, jlong, jfloat, jfloat, jint);
+JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_setWindowRoundedBorder
+ (JNIEnv *, jclass, jobject, jfloat, jfloat, jint);
#ifdef __cplusplus
}
diff --git a/flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/JNIUtils.mm b/flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/JNIUtils.mm
new file mode 100644
index 00000000..7c4e798d
--- /dev/null
+++ b/flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/JNIUtils.mm
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2023 FormDev Software GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import