简体   繁体   English

触摸输入和 OpenJDK 11 与 JavaFX 11 的问题

[英]Problems with touch input and OpenJDK 11 with JavaFX 11

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.我正在处理一个 JavaFX 项目,并想从 Oracle JDK 1.8 切换到 OpenJDK 11。到目前为止,过渡非常顺利,但仍然存在一个与触摸/鼠标输入相关的主要问题,这会导致一些麻烦。

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. JavaFX UI 应该在支持触摸的设备上运行,该设备过去直接与 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 as JavaFX is no longer part of the JDK by default) I get the follwing sequence of events:使用 OpenJDK11 构建相同的应用程序后(使用 OpenJFX 11 作为外部库,因为默认情况下 JavaFX 不再是 JDK 的一部分)我得到以下事件序列:

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?问题是,如何让我的MOUSE_{PRESSED,RELEASED,CLICKED}事件恢复?

SSCE: SSCE:

package com.example.jfxtouchtest;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;


public class JFXTouchTest {

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

    public static class JFXApp extends Application {
        @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()));
            primaryStage.setScene(new Scene(new Pane()));
            primaryStage.setWidth(800);
            primaryStage.setHeight(600);
            primaryStage.show();
        }
    }
}

I think it's worth noting that all fired events are MouseEvents (not TouchEvents ), regardless of whether I'm using the touchscreen or not.我认为值得注意的是,无论我是否使用触摸屏,所有触发的事件都是MouseEvents (不是TouchEvents )。 That in itself is sort of strange in my opinion, but at least I'm getting the desired behaviour with JDK 8...在我看来,这本身就有点奇怪,但至少我在 JDK 8 中得到了想要的行为......

Some background information:一些背景资料:

  • OS: Ubuntu 18.04.01 LTS操作系统:Ubuntu 18.04.01 LTS
  • Kernel: 4.15.0-42-generic内核:4.15.0-42-generic
  • Oracle JDK 1.8.0_191甲骨文 JDK 1.8.0_191
  • OpenJDK 11.0.1 OpenJDK 11.0.1
  • Touchscreen (as reported by xinput ): Atmel maXTouch Digitizer触摸屏(由xinput报告):Atmel maXTouch Digitizer
  • The touchscreen works just fine with other applications, click events seem to be handled as expected.触摸屏与其他应用程序配合得很好,点击事件似乎按预期处理。
  • The somehwat related VM-arguments somehwat 相关的 VM 参数

    -Dcom.sun.javafx.isEmbedded=true and -Dcom.sun.javafx.isEmbedded=true

    -Dcom.sun.javafx.touch=true

    both seem to have no effect on the issue两者似乎都对这个问题没有影响

  • There seems to be a slight difference in the xev output I'm getting depending on whether I'm using the mouse or the touchscreen:根据我使用的是鼠标还是触摸屏,我得到的xev输出似乎略有不同:

    Mouse ( state is 0x0 for ButtonPress, 0x100 for ButtonRelease):鼠标(ButtonPress state0x0 ,ButtonRelease state0x100 ):

     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

    Touchscreen ( state is 0x100 in both cases):触摸屏(两种情况下的state都是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

    I'm not exactly sure what this means, though.不过,我不确定这意味着什么。

Any help would be greatly appreciated, even if it's just a confirmation that the issue is reproducible on another machine with another type of touchscreen!任何帮助将不胜感激,即使只是确认该问题可以在另一台具有其他类型触摸屏的机器上重现! Many thanks in advance!提前谢谢了!

UPDATE: I have managed to get my hands on a different touchscreen in the meantime, and it seems to work fine with that one.更新:在此期间,我已经设法让我的手接触到了另一个触摸屏,它似乎在那个触摸屏上工作得很好。 What's interesting is that, just like with regular mouse events, xev reports two different states for ButtonPress and ButtonRelease, so maybe the state field being the same for both event types on the other touchscreen has something to do with this after all?有趣的是,就像常规鼠标事件一样, xev报告 ButtonPress 和 ButtonRelease 的两种不同状态,所以也许另一个触摸屏上两种事件类型的状态字段相同毕竟与此有关?

I had the same problem with my touch screen and JFX.我的触摸屏和 JFX 也有同样的问题。 My code works fine with Open JDK 1.8 and its corresponding JFX, it fails with OpenJDK 11 and its corresponding JFX.我的代码在 Open JDK 1.8 及其相应的 JFX 上运行良好,但在 OpenJDK 11 及其相应的 JFX 上运行失败。 It works fine with the JDK and JFX from Liberica https://bell-sw.com/pages/java-11.0.7-for-Embedded/它适用于来自 Liberica https://bell-sw.com/pages/java-11.0.7-for-Embedded/的 JDK 和 JFX

So for me my workaround was to change to the Liberica JDK 11 and JFX distribution.所以对我来说,我的解决方法是更改​​为 Liberica JDK 11 和 JFX 发行版。 Other options may be JDK, JFX distributions from Azul or Corretto.其他选项可能是来自 Azul 或 Corretto 的 JDK、JFX 发行版。

Force JavaFX to use gtk-2 by using the java parameter -Djdk.gtk.version=2.通过使用 java 参数 -Djdk.gtk.version=2 强制 JavaFX 使用 gtk-2。 The touchscreen works with that setting although this causes other problems with our application (possibly related to 3rd party libraries).触摸屏可以使用该设置,尽管这会导致我们的应用程序出现其他问题(可能与 3rd 方库有关)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM