JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.41k stars 272 forks source link

Window maximizes with single click (should be double click) #637

Open rkeen-siemens opened 1 year ago

rkeen-siemens commented 1 year ago

On Linux (at least CentOS with Gnome 3) single clicking the header of the main frame will maximize/restore the frame. This should only happen on a double click.

The problem seems to be that sometimes the click event is sent to the FlatTitlePane.Handler and sometimes it isn't. This only seems to be an issue when using a trackpad with tap to click on a single tap. Clicking the trackpad or using a mouse seem to work as expected. Here are the events passed to the handler's mousePressed and mouseClicked methods for the various input methods. In case it makes a difference, I'm testing this via HP ZCentral Remote Boost to a remote linux instance using a Mac OS 13.1 client with a Magic Trackpad (original, not the 2nd).

Trackpad Single Tap

pressed at 1673293639029 with e.getClickCount 1 and clickCount 1 clicked at 1673293639040 with e.getClickCount 1 // <-- This click event triggers the maximize/restore erroneously

Trackpad Single Click

pressed at 1673293654677 with e.getClickCount 1 and clickCount 1 // No click event sent to the handler

Mouse Single Click

pressed at 1673293672853 with e.getClickCount 1 and clickCount 1 // No click event sent to the handler

Trackpad Double Tap

pressed at 1673293689761 with e.getClickCount 1 and clickCount 1 clicked at 1673293689762 with e.getClickCount 1 // <-- This click event triggers the maximize/restore early // Only if the title bar stays at the top will you get the second press/click events pressed at 1673293689907 with e.getClickCount 2 and clickCount 2 clicked at 1673293689908 with e.getClickCount 2

Trackpad Double Click

pressed at 1673293708430 with e.getClickCount 1 and clickCount 1 pressed at 1673293708625 with e.getClickCount 2 and clickCount 2 clicked at 1673293708740 with e.getClickCount 2

Mouse Double Click

pressed at 1673293731535 with e.getClickCount 1 and clickCount 1 pressed at 1673293731707 with e.getClickCount 2 and clickCount 2 clicked at 1673293731807 with e.getClickCount 2

remcopoelstra commented 1 year ago

Does this only happen when using FlatLaf?

I have also had issues (see #621) where a Mac trackpad is causing invalid mouse events, but this is unrelated to FlatLaf.

rkeen-siemens commented 1 year ago

I've only seen it with FlatLaf.

rkeen-siemens commented 1 year ago

Some more data points:

DevCharly commented 1 year ago

Thanks for the detailed information :+1:

Tried to reproduce, but works for me. I'm running CentOS in VirtualBox on Win11 using Magic Trackpad Model 2011 connected to Win11 via https://magicutilities.net/.

Maybe it is related to VNC/remote access...

Could you please check, for trackpad single tap, the return value of FlatNativeLinuxLibrary.moveOrResizeWindow() in this line: https://github.com/JFormDesigner/FlatLaf/blob/425f3acced1b17854dd94f2deda8f7d8a0756982/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java#L1294

I'm also interested in the value of field linuxNativeMove in mouseClicked().

Maybe changing this line: https://github.com/JFormDesigner/FlatLaf/blob/425f3acced1b17854dd94f2deda8f7d8a0756982/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePane.java#L1236

to if( linuxNativeMove && SystemInfo.isLinux && ... fixes the issue?

DevCharly commented 1 year ago

I've added suggested change from previous post to main branch.

Could you please try latest 3.1-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

rkeen-siemens commented 1 year ago

Looks like it is still an issue. I may have some time at the end of next week to look further into this (since I can easily reproduce).

IanKrL commented 1 week ago

I'm testing with flatlaf-3.5.2and I see the same issue. Here is my test code:

package stuffs;

import java.net.UnknownHostException;

import javax.swing.DefaultSingleSelectionModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SingleSelectionModel;
import javax.swing.SwingUtilities;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLightLaf;

public class SimpleLaf {

    public static void main(String[] args) throws UnknownHostException {
        SwingUtilities.invokeLater(() -> {
            JFrame.setDefaultLookAndFeelDecorated(true);
            FlatLightLaf.setup();
            final JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("Some Title");
            frame.setSize(350, 100);
            frame.setVisible(true);
        });

    }
}

I believe setDefaultLookAndFeelDecorated(true) is critical.

The problem is intermittent, and I might need to try a dozen or more times to see the error. It seems to help instigate the error if the sample window is moved to partially overlap another window.

https://github.com/user-attachments/assets/2772331e-4311-4cf2-957c-99c42da8aa15

I am on local AlmaLinux 8.10 and Java 17.0.8. No VNC, no trackpad, just a mouse.