-
Notifications
You must be signed in to change notification settings - Fork 162
[GTK4] Cleanup GtkEventControllerMotion Enter/Leave events #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can use the following snippet for testing: public class Snippet {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell(display);
shell.setSize(200, 200);
shell.setText("Mouse Enter/Exit");
shell.setToolTipText("Shell");
shell.setLayout(new GridLayout(2, true));
shell.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
System.out.println("mouseEnter: %s, x=%d, y=%d".formatted("Shell", e.x, e.y));
}
@Override
public void mouseExit(MouseEvent e) {
System.out.println("mouseExit: %s, x=%d, y=%d".formatted("Shell", e.x, e.y));
}
});
createButton(shell, "Button 1");
createButton(shell, "Button 2");
createButton(shell, "Button 3");
createButton(shell, "Button 4");
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
private static void createButton(Shell parent, String text) {
GridData gd = new GridData();
gd.horizontalIndent = 20;
gd.verticalIndent = 20;
gd.widthHint = 60;
gd.heightHint = 60;
Button b = new Button(parent, SWT.PUSH);
b.setText(text);
b.setToolTipText(text);
b.setLayoutData(gd);
b.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
System.out.println("mouseEnter: %s, x=%d, y=%d".formatted(text, e.x, e.y));
}
@Override
public void mouseExit(MouseEvent e) {
System.out.println("mouseExit: %s, x=%d, y=%d".formatted(text, e.x, e.y));
}
});
}
} Expectation: When moving the mouse cursor from the shell to one of the buttons, exactly two events should be fired:
When moving the mouse cursor from one of the buttons back to the shell, exactly two events should be fired:
When moving the mouse cursor in and out of the shell, exactly two events should be fired:
|
Recording.webm |
Test Results 408 files - 137 408 suites - 137 19m 41s ⏱️ - 12m 32s Results for commit 74edbbd. ± Comparison against base commit 81f9bd1. This pull request removes 37 tests.
♻️ This comment has been updated with latest results. |
c8e7f2a
to
e64db67
Compare
Support for mouse motion events was already implemented with b70cd16. However, following edge cases were missed: - Moving the cursor out of the shell and back in doesn't fire a "mouse enter" event. Similarly to the way motion events are handled in GTK3, the current control needs to be cleared on a "leave" event. Otherwise the "enter" event is suppressed when the cursor is moved out of and back in a shell again. - Moving from one widget to another fires two "mouse exit" events. One event is fired by "gtk4_motion_event()", the other by "leaveProc()". Only the former should be fired, as it contains the proper "x" and "y" coordinates. Latter is fired because "getCursorControl()" always returns "null". This has been fixed by first calculating the GtkWindow from the GdkSurface and then selecting the widget at the mouse coordinates. The whole implementation has also been restructured so that the X11-based heuristic via the XQueryPointer is only used for GTK3 (because it would simply return early for GTK4 anyway). - The tooltip window isn't moved when hovering over different widgets This is because the tooltip is set for the shell, even though it should be set for the individual widgets. As a result, only the text is updated but the window remains where it was initially shown. Closes eclipse-platform#219
Very nice fix. Failure is due to #2014 . Merging. |
Support for mouse motion events was already implemented with b70cd16. However, following edge cases were missed:
Similarly to the way motion events are handled in GTK3, the current control needs to be cleared on a "leave" event. Otherwise the "enter" event is suppressed when the cursor is moved out of and back in a shell again.
One event is fired by "gtk4_motion_event()", the other by "leaveProc()". Only the former should be fired, as it contains the proper "x" and "y" coordinates.
Latter is fired because "getCursorControl()" always returns "null". This has been fixed by first calculating the GtkWindow from the GdkSurface and then selecting the widget at the mouse coordinates. The whole implementation has also been restructured so that the X11-based heuristic via the XQueryPointer is only used for GTK3 (because it would simply return early for GTK4 anyway).
This is because the tooltip is set for the shell, even though it should be set for the individual widgets. As a result, only the text is updated but the window remains where it was initially shown.
Closes #219