macOS native: added FlatNativeMacLibrary.windowToggleFullScreen() for easier testing

This commit is contained in:
Karl Tauber
2023-12-16 11:58:27 +01:00
parent a1adde0888
commit 93d424cfe1
6 changed files with 35 additions and 0 deletions

View File

@@ -63,4 +63,5 @@ public class FlatNativeMacLibrary
public native static int getWindowButtonAreaWidth( Window window );
public native static int getWindowTitleBarHeight( Window window );
public native static boolean isWindowFullScreen( Window window );
public native static boolean windowToggleFullScreen( Window window );
}

View File

@@ -46,6 +46,7 @@ import com.formdev.flatlaf.icons.FlatAbstractIcon;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import com.formdev.flatlaf.themes.FlatMacLightLaf;
import com.formdev.flatlaf.extras.FlatSVGUtils;
import com.formdev.flatlaf.ui.FlatNativeMacLibrary;
import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.FontUtils;
import com.formdev.flatlaf.util.LoggingFacade;
@@ -960,6 +961,11 @@ class DemoFrame
System.out.println( "m drag" );
}
} );
if( SystemInfo.isMacOS && FlatNativeMacLibrary.isLoaded() ) {
showToggleButton.addActionListener( e -> {
FlatNativeMacLibrary.windowToggleFullScreen( this );
} );
}
// add "Users" button to menubar
FlatButton usersButton = new FlatButton();

View File

@@ -53,6 +53,14 @@ JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_getWindo
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_isWindowFullScreen
(JNIEnv *, jclass, jobject);
/*
* Class: com_formdev_flatlaf_ui_FlatNativeMacLibrary
* Method: windowToggleFullScreen
* Signature: (Ljava/awt/Window;)Z
*/
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_windowToggleFullScreen
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}
#endif

View File

@@ -328,3 +328,23 @@ JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_isWi
bool isWindowFullScreen( NSWindow* nsWindow ) {
return ((nsWindow.styleMask & NSWindowStyleMaskFullScreen) != 0);
}
extern "C"
JNIEXPORT jboolean JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_windowToggleFullScreen
( JNIEnv* env, jclass cls, jobject window )
{
JNI_COCOA_ENTER()
NSWindow* nsWindow = getNSWindow( env, cls, window );
if( nsWindow == NULL )
return FALSE;
[FlatJNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
[nsWindow toggleFullScreen:nil];
}];
return TRUE;
JNI_COCOA_EXIT()
return FALSE;
}