From ce24e4e622e6fadb8534f3168825927ba86a6520 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 3 Sep 2025 15:34:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9E=E7=BB=AD=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=B8=A4=E6=AC=A1=E8=BF=94=E5=9B=9E=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E6=9C=80=E5=A4=A7=E5=8C=96=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#4384)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/decorator/DecoratorSkin.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java index e2047009c..a4a5be60f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java @@ -55,7 +55,9 @@ public class DecoratorSkin extends SkinBase { private final Stage primaryStage; private final TransitionPane navBarPane; + @SuppressWarnings("FieldCanBeLocal") private final InvalidationListener onWindowsStatusChange; + private final EventHandler onTitleBarDoubleClick; private double mouseInitX, mouseInitY, stageInitX, stageInitY, stageInitWidth, stageInitHeight; @@ -104,6 +106,12 @@ public class DecoratorSkin extends SkinBase { root.addEventFilter(MouseEvent.MOUSE_MOVED, onMouseMoved); } }; + onTitleBarDoubleClick = event -> { + if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { + primaryStage.setMaximized(!primaryStage.isMaximized()); + event.consume(); + } + }; WeakInvalidationListener weakOnWindowsStatusChange = new WeakInvalidationListener(onWindowsStatusChange); primaryStage.iconifiedProperty().addListener(weakOnWindowsStatusChange); primaryStage.maximizedProperty().addListener(weakOnWindowsStatusChange); @@ -111,6 +119,7 @@ public class DecoratorSkin extends SkinBase { onWindowsStatusChange.invalidated(null); } else { onWindowsStatusChange = null; + onTitleBarDoubleClick = null; root.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleased); root.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDragged); root.addEventFilter(MouseEvent.MOUSE_MOVED, onMouseMoved); @@ -188,16 +197,6 @@ public class DecoratorSkin extends SkinBase { BorderPane titleBar = new BorderPane(); titleContainer.getChildren().add(titleBar); - // https://github.com/HMCL-dev/HMCL/issues/4290 - if (OperatingSystem.CURRENT_OS != OperatingSystem.MACOS) { - titleBar.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { - if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { - primaryStage.setMaximized(!primaryStage.isMaximized()); - event.consume(); - } - }); - } - Rectangle buttonsContainerPlaceHolder = new Rectangle(); { navBarPane = new TransitionPane(); @@ -324,6 +323,8 @@ public class DecoratorSkin extends SkinBase { BorderPane.setAlignment(titleNode, Pos.CENTER_LEFT); BorderPane.setMargin(titleNode, new Insets(0, 0, 0, 8)); } + if (onTitleBarDoubleClick != null) + center.setOnMouseClicked(onTitleBarDoubleClick); navBar.setCenter(center); if (canRefresh) {