Linux: use X11 window manager events to resize window, if FlatLaf window decorations are enabled (issue #866)

also made drag border slightly wider (from 5 to 6 pixels) and changed drag corner width from 16 to 32 to match native windows
This commit is contained in:
Karl Tauber
2025-03-06 17:47:55 +01:00
parent 9b1ae5c74a
commit d612b9f4b8
9 changed files with 48 additions and 18 deletions

View File

@@ -49,8 +49,17 @@ class FlatNativeLinuxLibrary
}
// direction for _NET_WM_MOVERESIZE message
// see https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html
static final int MOVE = 8;
// see https://specifications.freedesktop.org/wm-spec/latest/ar01s04.html
static final int
SIZE_TOPLEFT = 0,
SIZE_TOP = 1,
SIZE_TOPRIGHT = 2,
SIZE_RIGHT = 3,
SIZE_BOTTOMRIGHT = 4,
SIZE_BOTTOM = 5,
SIZE_BOTTOMLEFT = 6,
SIZE_LEFT = 7,
MOVE = 8;
private static Boolean isXWindowSystem;

View File

@@ -188,7 +188,7 @@ public abstract class FlatWindowResizer
protected abstract Dimension getWindowMinimumSize();
protected abstract Dimension getWindowMaximumSize();
protected void beginResizing( int resizeDir ) {}
protected void beginResizing( int resizeDir, MouseEvent e ) {}
protected void endResizing() {}
//---- interface PropertyChangeListener ----
@@ -370,7 +370,25 @@ public abstract class FlatWindowResizer
}
@Override
protected void beginResizing( int resizeDir ) {
protected void beginResizing( int resizeDir, MouseEvent e ) {
// on Linux, resize window using window manager
if( SystemInfo.isLinux && window != null && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) {
int direction = -1;
switch( resizeDir ) {
case N_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_TOP; break;
case S_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_BOTTOM; break;
case W_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_LEFT; break;
case E_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_RIGHT; break;
case NW_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_TOPLEFT; break;
case NE_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_TOPRIGHT; break;
case SW_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_BOTTOMLEFT; break;
case SE_RESIZE_CURSOR: direction = FlatNativeLinuxLibrary.SIZE_BOTTOMRIGHT; break;
}
if( direction >= 0 && FlatNativeLinuxLibrary.moveOrResizeWindow( window, e, direction ) )
return;
}
centerComp.setBounds( 0, 0, resizeComp.getWidth(), resizeComp.getHeight() );
centerComp.setCursor( getPredefinedCursor( resizeDir ) );
centerComp.setVisible( true );
@@ -462,7 +480,7 @@ public abstract class FlatWindowResizer
}
@Override
protected void beginResizing( int resizeDir ) {
protected void beginResizing( int resizeDir, MouseEvent e ) {
int direction = 0;
switch( resizeDir ) {
case N_RESIZE_CURSOR: direction = NORTH; break;
@@ -581,7 +599,7 @@ debug*/
dragRightOffset = windowBounds.x + windowBounds.width - xOnScreen;
dragBottomOffset = windowBounds.y + windowBounds.height - yOnScreen;
beginResizing( resizeDir );
beginResizing( resizeDir, e );
}
@Override

View File

@@ -564,8 +564,8 @@ RadioButtonMenuItem.background = @menuBackground
#---- RootPane ----
RootPane.border = com.formdev.flatlaf.ui.FlatRootPaneUI$FlatWindowBorder
RootPane.borderDragThickness = 5
RootPane.cornerDragWidth = 16
RootPane.borderDragThickness = 6
RootPane.cornerDragWidth = 32
RootPane.honorFrameMinimumSizeOnResize = false
RootPane.honorDialogMinimumSizeOnResize = true