This commit is contained in:
crschnick 2024-07-13 13:10:33 +00:00
parent 53c36cd4c2
commit d7055a435a
5 changed files with 98 additions and 13 deletions

View file

@ -20,7 +20,7 @@ import org.apache.commons.lang3.SystemUtils;
public class ModifiedStage extends Stage {
public static boolean mergeFrame() {
return SystemUtils.IS_OS_WINDOWS_11;
return SystemUtils.IS_OS_WINDOWS_11 || SystemUtils.IS_OS_MAC;
}
@SneakyThrows
@ -62,12 +62,23 @@ public class ModifiedStage extends Stage {
return;
}
if (OsType.getLocal() != OsType.WINDOWS || AppPrefs.get() == null || AppPrefs.get().theme.getValue() == null) {
if (OsType.getLocal() == OsType.LINUX || AppPrefs.get() == null || AppPrefs.get().theme.getValue() == null) {
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), false);
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), true);
return;
}
switch (OsType.getLocal()) {
case OsType.Linux linux -> {
}
case OsType.MacOs macOs -> {
var ctrl = new NativeMacOsWindowControl(stage);
ctrl.setWindowDarkMode(AppPrefs.get().theme.getValue().isDark());
var seamlessFrame = !AppPrefs.get().performanceMode().get() && mergeFrame();
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrame);
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrame);
}
case OsType.Windows windows -> {
var ctrl = new NativeWinWindowControl(stage);
ctrl.setWindowAttribute(
NativeWinWindowControl.DmwaWindowAttribute.DWMWA_USE_IMMERSIVE_DARK_MODE.get(),
@ -81,6 +92,8 @@ public class ModifiedStage extends Stage {
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrame);
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrame);
}
}
}
private static void updateStage(Stage stage) {
if (!stage.isShowing()) {

View file

@ -0,0 +1,38 @@
package io.xpipe.app.core.window;
import com.sun.jna.NativeLong;
import io.xpipe.app.util.NativeBridge;
import io.xpipe.core.util.ModuleHelper;
import javafx.stage.Window;
import lombok.Getter;
import lombok.SneakyThrows;
import java.lang.reflect.Method;
@Getter
public class NativeMacOsWindowControl {
private final long nsWindow;
@SneakyThrows
public NativeMacOsWindowControl(Window stage) {
Method tkStageGetter = Window.class.getDeclaredMethod("getPeer");
tkStageGetter.setAccessible(true);
Object tkStage = tkStageGetter.invoke(stage);
Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow");
getPlatformWindow.setAccessible(true);
Object platformWindow = getPlatformWindow.invoke(tkStage);
Method getNativeHandle = platformWindow.getClass().getMethod("getNativeHandle");
getNativeHandle.setAccessible(true);
Object nativeHandle = getNativeHandle.invoke(platformWindow);
this.nsWindow = (long) nativeHandle;
}
public void setWindowDarkMode(boolean darkMode) {
if (!ModuleHelper.isImage()) {
return;
}
NativeBridge.MacOsLibrary.INSTANCE.setAppearance(new NativeLong(nsWindow), darkMode);
}
}

View file

@ -0,0 +1,18 @@
package io.xpipe.app.util;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import io.xpipe.app.issue.ErrorEvent;
import java.util.Map;
public class NativeBridge {
public static interface MacOsLibrary extends Library {
public static MacOsLibrary INSTANCE = Native.load("xpipe_bridge", MacOsLibrary.class, Map.of());
public abstract void setAppearance(NativeLong window, boolean dark);
}
}

View file

@ -9,6 +9,10 @@
-fx-background-color: transparent;
}
.root:seamless-frame {
-fx-padding: 0 0 27 0;
}
.root:dark:separate-frame .background {
-fx-background-color: derive(-color-bg-default, 1%);
}

12
dist/base.gradle vendored
View file

@ -229,6 +229,18 @@ if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
commandLine "$projectDir/misc/mac/sign_and_notarize.sh", "$projectDir", rootProject.arch.toString(), rootProject.productName
}
}
if (fullVersion) {
def nativeLib = "$projectDir/native_lib/macos"
def proj = "$nativeLib/xpipe_bridge.xcodeproj"
exec {
commandLine 'xcodebuild', proj, '-scheme', 'xpipe_bridge', "CONFIGURATION_BUILD_DIR=${project.getLayout().getBuildDirectory().dir("native_lib")}", 'build'
}
copy {
from project.getLayout().getBuildDirectory().dir("native_lib").get().file('xpipe_bridge.dylib')
into "$distDir/$app/Contents/runtime/Contents/Home/bin/"
}
}
}
}
}