From 538e01b1e5e7620eae9df5f20b829a59ad2e68cd Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 5 Dec 2025 15:54:05 +0100 Subject: [PATCH] consider location of system bar when placing notification window Signed-off-by: Armin Schrenk --- .../cryptomator/ui/common/SystemBarUtil.java | 30 +++++++++++++++++ .../ui/notification/NotificationModule.java | 33 +++++++++++-------- 2 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/cryptomator/ui/common/SystemBarUtil.java diff --git a/src/main/java/org/cryptomator/ui/common/SystemBarUtil.java b/src/main/java/org/cryptomator/ui/common/SystemBarUtil.java new file mode 100644 index 000000000..86e0adeed --- /dev/null +++ b/src/main/java/org/cryptomator/ui/common/SystemBarUtil.java @@ -0,0 +1,30 @@ +package org.cryptomator.ui.common; + +import ch.qos.logback.classic.filter.LevelFilter; + +import javafx.stage.Screen; + +public class SystemBarUtil { + + public enum Placement { + LEFT, + TOP, + RIGHT, + BOTTOM; + } + + public static Placement getPlacementOfSystembar(Screen screen) { + var bounds = screen.getBounds(); + var vBounds = screen.getVisualBounds(); + //assumption: the system bar fills a whole screen side + if(bounds.getMinX() != vBounds.getMinX()){ + return Placement.LEFT; + } else if (bounds.getMinY() != vBounds.getMinY()) { + return Placement.TOP; + } else if (bounds.getMaxX() != vBounds.getMaxX()) { + return Placement.RIGHT; + } else { + return Placement.BOTTOM; + } + } +} diff --git a/src/main/java/org/cryptomator/ui/notification/NotificationModule.java b/src/main/java/org/cryptomator/ui/notification/NotificationModule.java index a8664a0ba..d9beb076c 100644 --- a/src/main/java/org/cryptomator/ui/notification/NotificationModule.java +++ b/src/main/java/org/cryptomator/ui/notification/NotificationModule.java @@ -12,6 +12,7 @@ import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlLoaderFactory; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.StageInitializer; +import org.cryptomator.ui.common.SystemBarUtil; import javax.inject.Provider; import javafx.scene.Scene; @@ -35,24 +36,28 @@ abstract class NotificationModule { stage.initModality(Modality.NONE); stage.setAlwaysOnTop(true); initializer.accept(stage); - stage.setOnShown(_ -> placeWindow(stage) ); + stage.setOnShown(_ -> placeWindow(stage)); return stage; } + //TODO: TEST static void placeWindow(Stage window) { - if(SystemUtils.IS_OS_WINDOWS) { //place to right bottom - var screenBounds = Screen.getPrimary().getVisualBounds(); - window.setX(screenBounds.getMaxX() - window.getWidth()); - window.setY(screenBounds.getMaxY() - window.getHeight()); - } else if(SystemUtils.IS_OS_MAC) { //place to right top - var screenBounds = Screen.getPrimary().getVisualBounds(); //TODO: TEST - window.setX(screenBounds.getMaxX() - window.getWidth()); - window.setY(screenBounds.getMinY()); - } else { //place to middle top - //GNOME; KDE; etc... - var screenBounds = Screen.getPrimary().getVisualBounds(); //TODO: TEST - window.setX(screenBounds.getMinX() + (screenBounds.getWidth() - window.getWidth()) / 2.0); - window.setY(screenBounds.getMinY()); + var screen = Screen.getPrimary(); + var vBounds = screen.getVisualBounds(); + if (SystemUtils.IS_OS_MAC) { //place to right top + window.setX(vBounds.getMaxX() - window.getWidth()); + window.setY(vBounds.getMinY()); + } else { + switch (SystemBarUtil.getPlacementOfSystembar(screen)) { + case TOP -> { + window.setX(vBounds.getMaxX() - window.getWidth()); + window.setY(vBounds.getMaxY() - window.getHeight()); + } + default -> { + window.setX(vBounds.getMinX() + (vBounds.getWidth() - window.getWidth()) / 2.0); + window.setY(vBounds.getMinY()); + } + } } }