Skip to content

Commit ad89eb2

Browse files
committed
macOS: fixed missing close/iconify/maximize buttons on inactive window, if system appearance is dark, but application appearance is light (issue #1032)
1 parent 8339a60 commit ad89eb2

6 files changed

Lines changed: 61 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
FlatLaf Change Log
22
==================
33

4+
## 3.7.2-SNAPSHOT
5+
6+
- macOS: Fixed missing close/iconify/maximize buttons on inactive window, if
7+
system appearance is dark, but application appearance is light. (issue #1032)
8+
9+
410
## 3.7.1
511

612
- System File Chooser:

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeMacLibrary.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public class FlatNativeMacLibrary
4747
{
48-
private static int API_VERSION_MACOS = 2003;
48+
private static int API_VERSION_MACOS = 2004;
4949

5050
/**
5151
* Checks whether native library is loaded/available.
@@ -57,6 +57,7 @@ public static boolean isLoaded() {
5757
return SystemInfo.isMacOS && FlatNativeLibrary.isLoaded( API_VERSION_MACOS );
5858
}
5959

60+
/** @since 3.7.2 */ public native static boolean setWindowAppearance( Window window, String appearance );
6061
public native static boolean setWindowRoundedBorder( Window window, float radius, float borderWidth, int borderColor );
6162

6263
/** @since 3.4 */

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ protected void installDefaults( JRootPane c ) {
178178
}
179179
}
180180

181+
macSetWindowAppearance( c );
181182
macClearBackgroundForTranslucentWindow( c );
182183
}
183184

@@ -369,6 +370,17 @@ private boolean isMacButtonsSpacingSupported() {
369370
return SystemInfo.isMacOS && SystemInfo.isJava_17_orLater && FlatNativeMacLibrary.isLoaded();
370371
}
371372

373+
private void macSetWindowAppearance( JRootPane c ) {
374+
if( !SystemInfo.isMacOS )
375+
return;
376+
377+
Window window = getParentWindow( c );
378+
if( window != null && FlatNativeMacLibrary.isLoaded() ) {
379+
FlatNativeMacLibrary.setWindowAppearance( window, FlatLaf.isLafDark()
380+
? "NSAppearanceNameDarkAqua" : "NSAppearanceNameAqua" );
381+
}
382+
}
383+
372384
private void macInstallWindowBackgroundListener( JRootPane c ) {
373385
if( !SystemInfo.isMacOS )
374386
return;
@@ -511,6 +523,7 @@ public void propertyChange( PropertyChangeEvent e ) {
511523
if( titlePane != null && !Objects.equals( titlePane.windowStyle, FlatTitlePane.getWindowStyle( rootPane ) ) )
512524
setTitlePane( createTitlePane() );
513525

526+
macSetWindowAppearance( rootPane );
514527
macClearBackgroundForTranslucentWindow( rootPane );
515528
}
516529

flatlaf-natives/flatlaf-natives-macos/src/main/headers/com_formdev_flatlaf_ui_FlatNativeMacLibrary.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/ApiVersion.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// increase this version if changing API or functionality of native library
2626
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeMacLibrary
27-
#define API_VERSION_MACOS 2003
27+
#define API_VERSION_MACOS 2004
2828

2929

3030
//---- JNI methods ------------------------------------------------------------

flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/MacWindow.mm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,37 @@ @implementation WindowData
9191
return windowData;
9292
}
9393

94+
extern "C"
95+
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_setWindowAppearance
96+
( JNIEnv* env, jclass cls, jobject window, jstring appearance )
97+
{
98+
JNI_COCOA_ENTER()
99+
100+
NSWindow* nsWindow = getNSWindow( env, cls, window );
101+
if( nsWindow == NULL )
102+
return FALSE;
103+
104+
// convert Java strings to NSString (on Java thread)
105+
NSString* nsAppearance = JavaToNSString( env, appearance );
106+
107+
[FlatJNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
108+
JNI_COCOA_TRY()
109+
110+
NSAppearance *appearance = [NSAppearance appearanceNamed:nsAppearance];
111+
if( appearance != NULL )
112+
nsWindow.appearance = appearance;
113+
else
114+
NSLog( @"FlatLaf: unknown window appearance '%@'", nsAppearance );
115+
116+
JNI_COCOA_CATCH()
117+
}];
118+
119+
return TRUE;
120+
121+
JNI_COCOA_EXIT()
122+
return FALSE;
123+
}
124+
94125
extern "C"
95126
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_setWindowRoundedBorder
96127
( JNIEnv* env, jclass cls, jobject window, jfloat radius, jfloat borderWidth, jint borderColor )

0 commit comments

Comments
 (0)