Native lib fixes

This commit is contained in:
crschnick 2024-07-17 10:00:29 +00:00
parent 6d1d8770a2
commit 940480918e
3 changed files with 21 additions and 15 deletions

View file

@ -67,9 +67,9 @@ public class ModifiedStage extends Stage {
case OsType.MacOs macOs -> {
var ctrl = new NativeMacOsWindowControl(stage);
var seamlessFrame = !AppPrefs.get().performanceMode().get() && mergeFrame();
ctrl.setAppearance(seamlessFrame, AppPrefs.get().theme.getValue().isDark());
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrame);
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrame);
var seamlessFrameApplied = ctrl.setAppearance(seamlessFrame, AppPrefs.get().theme.getValue().isDark()) && seamlessFrame;
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("seamless-frame"), seamlessFrameApplied);
stage.getScene().getRoot().pseudoClassStateChanged(PseudoClass.getPseudoClass("separate-frame"), !seamlessFrameApplied);
}
case OsType.Windows windows -> {
var ctrl = new NativeWinWindowControl(stage);

View file

@ -28,11 +28,17 @@ public class NativeMacOsWindowControl {
this.nsWindow = (long) nativeHandle;
}
public void setAppearance(boolean seamlessFrame, boolean darkMode) {
public boolean setAppearance(boolean seamlessFrame, boolean darkMode) {
if (!ModuleHelper.isImage()) {
return;
return false;
}
NativeBridge.getMacOsLibrary().setAppearance(new NativeLong(nsWindow), seamlessFrame, darkMode);
var lib = NativeBridge.getMacOsLibrary();
if (lib.isEmpty()) {
return false;
}
lib.get().setAppearance(new NativeLong(nsWindow), seamlessFrame, darkMode);
return true;
}
}

View file

@ -4,29 +4,29 @@ import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.core.util.XPipeInstallation;
import java.util.Map;
import java.util.Optional;
public class NativeBridge {
private static MacOsLibrary macOsLibrary;
private static boolean loadingFailed;
public static MacOsLibrary getMacOsLibrary() {
if (macOsLibrary == null) {
public static Optional<MacOsLibrary> getMacOsLibrary() {
if (macOsLibrary == null && !loadingFailed) {
try {
System.setProperty("jna.library.path", XPipeInstallation.getCurrentInstallationBasePath()
.resolve("Contents").resolve("runtime").resolve("Home").resolve("lib").toString());
var l = Native.load("xpipe_bridge", MacOsLibrary.class, Map.of());
macOsLibrary = l;
} catch (Throwable t) {
ErrorEvent.fromThrowable(t).handle();
macOsLibrary = new MacOsLibrary() {
@Override
public void setAppearance(NativeLong window, boolean seamlessFrame, boolean dark) {
}
};
loadingFailed = true;
}
}
return macOsLibrary;
return Optional.ofNullable(macOsLibrary);
}
public static interface MacOsLibrary extends Library {