diff --git a/CHANGELOG.md b/CHANGELOG.md index db86cd40..9c70688d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,9 +27,11 @@ FlatLaf Change Log - PopupFactory: Fixed NPE on Windows 10 when `owner` is `null`. (issue #952) - Popup: On Windows 10, drop shadow of heavy-weight popup was not updated if popup moved/resized. (issue #942) -- FlatLaf window decorations: Minimize and maximize icons were not shown for - custom scale factors less than 100% (e.g. `-Dflatlaf.uiScale=75%`). (issue - #951) +- FlatLaf window decorations: + - Minimize and maximize icons were not shown for custom scale factors less + than 100% (e.g. `-Dflatlaf.uiScale=75%`). (issue #951) + - Linux: Fixed occasional maximizing of window when single-clicking the + window's title bar. (issue #637) - Linux: Popups (menus and combobox lists) were not hidden when window is moved, resized, maximized, restored, iconified or switched to another window. (issue #962) 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 21c2a800..de7217d7 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 @@ -33,7 +33,6 @@ import java.awt.Image; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; -import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -1417,22 +1416,9 @@ debug*/ private Point dragOffset; private boolean linuxNativeMove; - private long lastSingleClickWhen; @Override public void mouseClicked( MouseEvent e ) { - // on Linux, when using native library, the mouse clicked event - // is usually not sent and maximize/restore is done in mouse pressed event - // this check is here for the case that a mouse clicked event comes through for some reason - if( linuxNativeMove && SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) { - // see comment in mousePressed() - if( lastSingleClickWhen != 0 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() ) { - lastSingleClickWhen = 0; - maximizeOrRestore(); - } - return; - } - if( e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton( e ) ) { if( SwingUtilities.getDeepestComponentAt( FlatTitlePane.this, e.getX(), e.getY() ) == iconLabel ) { // double-click on icon closes window @@ -1463,42 +1449,6 @@ debug*/ dragOffset = SwingUtilities.convertPoint( mouseLayer, e.getPoint(), window ); linuxNativeMove = false; - - // on Linux, move or maximize/restore window - if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) { - // The fired Java mouse events, when doing a double-click and the first click - // sends a _NET_WM_MOVERESIZE message, are different for various Linux distributions: - // CentOS 7 (GNOME 3.28.2, X11): PRESSED(clickCount=1) PRESSED(clickCount=2) RELEASED(clickCount=2) - // Ubuntu 20.04 (GNOME 3.36.1, X11): PRESSED(clickCount=1) PRESSED(clickCount=2) RELEASED(clickCount=2) - // Ubuntu 22.04 (GNOME 42.2, Wayland): PRESSED(clickCount=1) RELEASED(clickCount=1) CLICKED(clickCount=1) - // Kubuntu 22.04 (KDE 5.24.4, X11): PRESSED(clickCount=1) PRESSED(clickCount=1) RELEASED(clickCount=1) - - // double-click is not always recognized in Java when using _NET_WM_MOVERESIZE message - int clickCount = e.getClickCount(); - if( clickCount == 1 && lastSingleClickWhen != 0 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() ) - clickCount = 2; - - switch( clickCount ) { - case 1: - // move window via _NET_WM_MOVERESIZE message - e.consume(); - linuxNativeMove = FlatNativeLinuxLibrary.moveOrResizeWindow( window, e, FlatNativeLinuxLibrary.MOVE ); - lastSingleClickWhen = e.getWhen(); - break; - - case 2: - // maximize/restore on double-click - // also done here because no mouse clicked event is sent when using _NET_WM_MOVERESIZE message - lastSingleClickWhen = 0; - maximizeOrRestore(); - break; - } - } - } - - private int getMultiClickInterval() { - Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "awt.multiClickInterval" ); - return (value instanceof Integer) ? (Integer) value : 500; } @Override public void mouseReleased( MouseEvent e ) {} @@ -1521,6 +1471,13 @@ debug*/ if( hasNativeCustomDecoration() ) return; // do nothing if having native window border + // on Linux, move window using window manager + if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) { + linuxNativeMove = FlatNativeLinuxLibrary.moveOrResizeWindow( window, e, FlatNativeLinuxLibrary.MOVE ); + if( linuxNativeMove ) + return; + } + // restore window if it is maximized if( window instanceof Frame ) { Frame frame = (Frame) window;