Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8217955

Problems with touch input and JavaFX 11

    XMLWordPrintable

Details

    • 9
    • x86_64
    • linux

    Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Ubuntu 18.04.01 LTS
      Kernel: 4.15.0-42-generic

      OpenJDK 11.0.2
      JavaFX 11.0.2

      Touchscreen: Atmel maXTouch Digitizer

      A DESCRIPTION OF THE PROBLEM :
      I'm working on a JavaFX project and would like to switch from Oracle JDK 1.8 to OpenJDK 11. So far the transition has been pretty seamless, but there is still one main problem related to touch/mouse input that's causing some trouble.

      The JavaFX UI is supposed to run on a touch-enabled device, which used to work straight out of the box with Oracle JDK 1.8. When I touch the screen, the following sequence of mouse events is fired as expected:

      MOUSE_PRESSED
      MOUSE_RELEASED
      MOUSE_CLICKED

      After building the same application with OpenJDK11 (using OpenJFX 11 as an external library) I get the follwing sequence of events:

      MOUSE_ENTERED_TARGET
      MOUSE_ENTERED_TARGET
      MOUSE_EXITED_TARGET
      MOUSE_EXITED_TARGET

      This explains why I can't click any buttons (or controls in general). So far so good. The question is, how do I get my MOUSE_{PRESSED,RELEASED,CLICKED} events back?

      I have spent some time analyzing the low-level mouse and touch events generated by the touchscreen and compared them to events generated by a regular USB mouse and another touchscreen that does not cause this sort of behaviour.
      Comparing the output of the xev tool (simple tool for printing X11 input events), the only thing that struck me was that both the mouse and the working touchscreen would have different values in the "state" field for ButtonPress and ButtonRelease events:

         ButtonPress event, serial 34, synthetic NO, window 0x3400001,
           root 0x193, subw 0x0, time 16982696, (93,90), root:(964,612),
           state 0x0, button 1, same_screen YES

         ButtonRelease event, serial 34, synthetic NO, window 0x3400001,
           root 0x193, subw 0x0, time 16983364, (93,90), root:(964,612),
           state 0x100, button 1, same_screen YES
           
      whereas the problematic touchscreen would get the same state for both event types (0x100):

         ButtonPress event, serial 34, synthetic NO, window 0x3400001,
           root 0x193, subw 0x0, time 17599475, (93,145), root:(964,667),
           state 0x100, button 1, same_screen YES

         ButtonRelease event, serial 34, synthetic NO, window 0x3400001,
           root 0x193, subw 0x0, time 17599537, (93,145), root:(964,667),
           state 0x100, button 1, same_screen YES

      Another interesting thing I randomly noticed is that MOUSE_PRESSED and MOUSE_RELEASED events will fire in addition to the MOUSE_ENTERED_TARGET and MOUSE_EXITED_TARGET events in JavaFX 11, but only on PopupWindows. The example to reproduce the issue therefore adds mouse/touch event listeners to both the main window and to the PopupWindow that is created for displaying the items of a ComboBox.

      I would also like to note that the touchscreen works just fine with any other applications, the only problems I've had with it so far were with applications using JavaFX 11.

      REGRESSION : Last worked in version 8u202

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Compile and run the example using JDK 11.0.2 and JavaFX 11.0.2
      2) Touch the main window area with the problematic touchscreen
      3) Open up the ComboBox and select an item with the problematic touchscreen


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      MOUSE_PRESSED and MOUSE_RELEASED (or TOUCH_PRESSED and TOUCH_RELEASED) events should be fired in steps 2) and 3)
      ACTUAL -
      In step 2) only MOUSE_ENTERED_TARGET and MOUSE_EXITED_TARGET are fired
      In step 3) MOUSE_PRESSED and MOUSE_RELEASED are fired alongside MOUSE_ENTERED_TARGET and MOUSE_EXITED_TARGET


      ---------- BEGIN SOURCE ----------
      package com.example.jfxtouchtest;

      import javafx.application.Application;
      import javafx.collections.ListChangeListener;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.input.TouchEvent;
      import javafx.scene.layout.Pane;
      import javafx.stage.PopupWindow;
      import javafx.stage.Stage;
      import javafx.stage.Window;


      public class JFXTouchTest {

          public static void main(String[] args) {
              Application.launch(JFXApp.class, args);
          }

          public static class JFXApp extends Application implements ListChangeListener<Window> {

              @Override
              public void start(Stage primaryStage) {
                  primaryStage.addEventFilter(TouchEvent.ANY, e -> System.out.println("touch event: " + e.getEventType()));
                  primaryStage.addEventFilter(MouseEvent.ANY, e -> System.out.println("mouse event: " + e.getEventType()));
                  final ComboBox<String> comboBox = new ComboBox<>();
                  comboBox.getItems().addAll("Test1", "Test2", "Test3");
                  primaryStage.setScene(new Scene(new Pane(comboBox)));
                  primaryStage.setWidth(800);
                  primaryStage.setHeight(800);
                  primaryStage.show();
                  Window.getWindows().addListener(this);
              }

              @Override
              public void onChanged(Change<? extends Window> c) {
                  if (!c.next()) return;
                  for (Window w : c.getAddedSubList()) {
                      if (w instanceof PopupWindow) {
                          w.addEventFilter(TouchEvent.ANY,
                                  e -> System.out.println("touch event (PopupWindow): " + e.getEventType()));
                          w.addEventFilter(MouseEvent.ANY,
                                  e -> System.out.println("mouse event (PopupWindow): " + e.getEventType()));
                          Window.getWindows().removeListener(this);
                      }
                  }
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      JDK1.8 with JavaFX 8 does not have this issue

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: