Skip to content

Commit

Permalink
Linux: fixed double-click on title bar to maximize/restore on Ubuntu …
Browse files Browse the repository at this point in the history
…22.04 (issue #482)
  • Loading branch information
DevCharly committed Aug 21, 2022
1 parent 9f0554c commit bf4d4cc
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -1175,8 +1175,14 @@ 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 thru for some reason
if( SystemInfo.isLinux && FlatNativeLinuxLibrary.isWMUtilsSupported( window ) )
if( 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( e.getSource() == iconLabel ) {
Expand Down Expand Up @@ -1211,9 +1217,16 @@ public void mousePressed( MouseEvent e ) {

// 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 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() )
if( clickCount == 1 && lastSingleClickWhen != 0 && (e.getWhen() - lastSingleClickWhen) <= getMultiClickInterval() )
clickCount = 2;

switch( clickCount ) {
Expand All @@ -1227,6 +1240,7 @@ public void mousePressed( MouseEvent e ) {
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;
}
Expand All @@ -1235,7 +1249,7 @@ public void mousePressed( MouseEvent e ) {

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

@Override public void mouseReleased( MouseEvent e ) {}
Expand Down

0 comments on commit bf4d4cc

Please sign in to comment.