From 35f97368fa51ab81f0ea314b2e0371ea7c15d19f Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 18 May 2021 18:00:53 +0200 Subject: [PATCH] Native window decorations: double-click at upper-left corner of maximized frame did not close window (issue #326) --- CHANGELOG.md | 2 ++ .../com/formdev/flatlaf/ui/FlatTitlePane.java | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0089a4..5676cbc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ FlatLaf Change Log height)` (instead of `getResolutionVariants()`) to allow creation of requested size on demand. This also avoids creation of all resolution variants. + - Double-click at upper-left corner of maximized frame did not close window. + (issue #326) - Linux: Fixed/improved detection of user font settings. (issue #309) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java index 9ff1ba3d..207b05b2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java @@ -521,13 +521,13 @@ public class FlatTitlePane g.drawLine( 0, debugTitleBarHeight, getWidth(), debugTitleBarHeight ); } if( debugHitTestSpots != null ) { - g.setColor( Color.blue ); + g.setColor( Color.red ); Point offset = SwingUtilities.convertPoint( this, 0, 0, window ); for( Rectangle r : debugHitTestSpots ) g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 ); } if( debugAppIconBounds != null ) { - g.setColor( Color.red ); + g.setColor( Color.blue); Point offset = SwingUtilities.convertPoint( this, 0, 0, window ); Rectangle r = debugAppIconBounds; g.drawRect( r.x - offset.x, r.y - offset.y, r.width - 1, r.height - 1 ); @@ -723,14 +723,29 @@ debug*/ List hitTestSpots = new ArrayList<>(); Rectangle appIconBounds = null; if( iconLabel.isVisible() ) { - // compute real icon size (without insets) + // compute real icon size (without insets; 1px wider for easier hitting) Point location = SwingUtilities.convertPoint( iconLabel, 0, 0, window ); Insets iconInsets = iconLabel.getInsets(); Rectangle iconBounds = new Rectangle( - location.x + iconInsets.left, - location.y + iconInsets.top, - iconLabel.getWidth() - iconInsets.left - iconInsets.right, - iconLabel.getHeight() - iconInsets.top - iconInsets.bottom ); + location.x + iconInsets.left - 1, + location.y + iconInsets.top - 1, + iconLabel.getWidth() - iconInsets.left - iconInsets.right + 2, + iconLabel.getHeight() - iconInsets.top - iconInsets.bottom + 2 ); + + // if frame is maximized, increase icon bounds to upper-left corner + // of window to allow closing window via double-click in upper-left corner + if( window instanceof Frame && + (((Frame)window).getExtendedState() & Frame.MAXIMIZED_BOTH) != 0 ) + { + iconBounds.height += iconBounds.y; + iconBounds.y = 0; + + if( window.getComponentOrientation().isLeftToRight() ) { + iconBounds.width += iconBounds.x; + iconBounds.x = 0; + } else + iconBounds.width += iconInsets.right; + } if( hasJBRCustomDecoration() ) hitTestSpots.add( iconBounds );