Skip to content

Commit

Permalink
Linux: fixed double-click on title bar to maximize/restore (issue #482)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Aug 21, 2022
1 parent 0baae7d commit 0881f83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Expand Up @@ -32,6 +32,7 @@
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.ComponentEvent;
Expand Down Expand Up @@ -1167,6 +1168,7 @@ public void windowStateChanged( WindowEvent e ) {

private Point dragOffset;
private boolean nativeMove;
private long lastSingleClickWhen;

@Override
public void mouseClicked( MouseEvent e ) {
Expand Down Expand Up @@ -1209,22 +1211,33 @@ public void mousePressed( MouseEvent e ) {

// on Linux, move or maximize/restore window
if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) ) {
switch( e.getClickCount() ) {
// double-click is not always recognized in Java when using _NET_WM_MOVERESIZE message
int clickCount = e.getClickCount();
if( clickCount == 1 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() )
clickCount = 2;

switch( clickCount ) {
case 1:
// move window via _NET_WM_MOVERESIZE event
// move window via _NET_WM_MOVERESIZE message
e.consume();
nativeMove = 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 event
// also done here because no mouse clicked event is sent when using _NET_WM_MOVERESIZE message
maximizeOrRestore();
break;
}
}
}

private int getMultiClickInterval() {
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "awt.multiClickInterval" );
return (value instanceof Integer) ? (Integer) value : 200;
}

@Override public void mouseReleased( MouseEvent e ) {}
@Override public void mouseEntered( MouseEvent e ) {}
@Override public void mouseExited( MouseEvent e ) {}
Expand Down
Binary file not shown.

0 comments on commit 0881f83

Please sign in to comment.