JDK-8347154 : [Wayland] Robot.mouseMove does not visually move mouse cursor
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: jfx23
  • Priority: P4
  • Status: Closed
  • Resolution: External
  • OS: linux
  • CPU: x86_64
  • Submitted: 2025-01-02
  • Updated: 2025-03-13
  • Resolved: 2025-01-15
Description
ADDITIONAL SYSTEM INFORMATION :
Linux / Fedora 37 (x64)
Tested with Java 23.0.1 and JavaFX 23.0.1 / 24-ea+19

A DESCRIPTION OF THE PROBLEM :
Current javadoc says:

 /**
     * Moves mouse pointer to given screen coordinates.
     * @param x X position
     * @param y Y position
     */
    public synchronized void mouseMove(int x, int y) {


However, Robot.mouseMove() does not move the mouse cursor visually, but the following Robot.mousePress() is delivered to the correct place. This is the same bug as JDK-8280995 but this bug report is for AWT.

It works as expected with:
- JavaFX robot with Java 23.0.1 and JavaFX 23.0.1 on Windows 10.

It doesn't work as expected with:
- JavaFX robot with Java 23.0.1 and JavaFX 23.0.1 on Fedora 37.
- JavaFX robot with Java 23.0.1 and JavaFX 24-ea+19 on Fedora 37.
- AWT robot with Java 23.0.1 and JavaFX 24-ea+19 on Fedora 37 (I get the same buggy behaviour with both AWT and JavaFX robots).


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1/ Compile the attached code.
2/ Launch the resulting jar.
3/ Click on the button named "test robot" with your mouse.
4/ Type on the key Space to close the dialogbox that has just popped up.
5/ Click again on the left button of the mouse.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After step 3/, the mouse pointer should have moved above the button named "display hello".
ACTUAL -
After step 3/, the mouse pointer is still above the button named "test robot". But when clicking on the mouse at step 5/ without moving the mouse, the click gets registered on the button named "display hello", which is quite confusing.

---------- BEGIN SOURCE ----------
package com.mycompany.mavenproject3;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.FlowPane;
import javafx.scene.robot.Robot;
import javafx.stage.Stage;


/**
 * JavaFX App
 */
public class App extends Application {

    @Override
    public void start(Stage stage) {
        var button = new Button("test robot");
        var button2 = new Button("display hello");
        var scene = new Scene(new FlowPane(button, button2), 640, 480);
        stage.setScene(scene);
        stage.show();
        
        button.setOnAction(e -> {
            Robot robot = new Robot();
            robot.mouseMove(button2.localToScreen(1, 1));
            robot.mouseClick(MouseButton.PRIMARY);
        });
        button2.setOnAction(e -> {
            Dialog<String> dialog = new Dialog();
            dialog.setContentText("hello");
            dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
            dialog.show();
        });
    }

    public static void main(String[] args) {
        launch();
    }

}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Additional Information from submitter: ==================================== XWayland is indeed buggy but then you should move away from using XTest and, instead, target the functions of libei to be fully compatible with Wayland or even target the functions of libevdev to be fully compatible with X11 and Wayland.
15-01-2025

Reopen to close as "External".
15-01-2025

This is not a JavaFX bug It is a limitation of the XWayland compatibility layer and there's nothing we can do about it. For AWT we had to update the specification to say that java.awt.Robot.mouseMove() does not necessarily visually move the pointer.
07-01-2025