TransWikia.com

Touchscreen with Qt QML eglfs

Raspberry Pi Asked by Velkan on December 8, 2020

The goal is to run QtQuick2 Qt5 applications on the RPI 2B with USB+HDMI resistive touchscreen (7″ 800×480 AR1100 http://www.adafruit.com/products/2407).

Current state

Visual part is fine. Touch input doesn’t work.

evtest on /dev/input/event2 shows EV_ABS events when moving and BTN_LEFT events on pushing and releasing.

  • tslib: says that ‘selected device is not a touchscreen I understand’; screw that lib anyways, too complex
  • evdev plugin in Qt without udev plugin: all is fine except when released it stays pressed
  • evdev plugin in Qt with udev plugin: push/release are ok, but the movements are too fast. Looks like it uses abs coordinates as relative values.
  • evdev plugin in Qt with udev plugin and specifying
    export QT_QPA_EVDEV_MOUSE_PARAMETERS=abs to deal with absolute values: SegFault.

Test app is qt5/examples/quick/touchinteraction/flickable/corkboards.qml launched by the qmlscene. Running fullscreen with eglfs qt plugin.

Config

As I understand, it has a poor video driver so QtQuick2 won’t run inside a window manager. The application must be launched in the fullscreen mode with the eglfs qt plugin.

(there is a mesa driver by Eric Anholt, but that is a different story)

Qt 5.5 cross-compile configuration:

Building on:   linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for:  devices/linux-rasp-pi2-g++ (arm, CPU features: neon)
Platform notes:

            - Also available for Linux: linux-kcc linux-icc linux-cxx

qmake vars .......... styles += mac fusion windows DEFINES += QT_NO_MTDEV DEFINES += QT_NO_LIBINPUT QMAKE_X11_PREFIX = /usr sql-drivers =  sql-plugins =  sqlite qmake switches ......... 

Build options:
  Configuration .......... accessibility audio-backend c++11 clock-gettime clock-monotonic compile_examples concurrent cross_compile dbus egl eglfs eglfs_brcm enable_new_dtags evdev eventfd freetype full-config getaddrinfo getifaddrs harfbuzz iconv inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap neon nis no-pkg-config opengl opengles2 pcre png posix_fallocate precompile_header qpa qpa reduce_exports release rpath shared small-config tslib use_gold_linker zlib 
  Build parts ............  libs tools
  Mode ................... release
  Using sanitizer(s)...... none
  Using C++11 ............ yes
  Using gold linker....... yes
  Using new DTAGS ........ yes
  Using PCH .............. yes
  Target compiler supports:
    Neon ................. yes

Qt modules and options:
  Qt D-Bus ............... yes (loading dbus-1 at runtime)
  Qt Concurrent .......... yes
  Qt GUI ................. yes
  Qt Widgets ............. yes
  Large File ............. yes
  QML debugging .......... yes
  Use system proxies ..... no

Support enabled for:
  Accessibility .......... yes
  ALSA ................... no
  CUPS ................... no
  Evdev .................. yes
  FontConfig ............. no
  FreeType ............... yes (bundled copy)
  Glib ................... no
  GStreamer .............. no
  GTK theme .............. no
  HarfBuzz ............... yes (bundled copy)
  Iconv .................. yes
  ICU .................... no
  Image formats: 
    GIF .................. yes (plugin, using bundled copy)
    JPEG ................. yes (plugin, using bundled copy)
    PNG .................. yes (in QtGui, using bundled copy)
  journald ............... no
  libinput................ no
  mtdev .................. no
  Networking: 
    getaddrinfo .......... yes
    getifaddrs ........... yes
    IPv6 ifname .......... yes
    libproxy.............. no
    OpenSSL .............. no
  NIS .................... yes
  OpenGL / OpenVG: 
    EGL .................. yes
    OpenGL ............... yes (OpenGL ES 2.0+)
    OpenVG ............... no
  PCRE ................... yes (bundled copy)
  pkg-config ............. no 
  PulseAudio ............. no
  QPA backends: 
    DirectFB ............. no
    EGLFS ................ yes
      EGLFS i.MX6....... . no
      EGLFS KMS .......... no
      EGLFS Mali ......... no
      EGLFS Raspberry Pi . yes
      EGLFS X11 .......... no
    LinuxFB .............. yes
    XCB .................. no
  Session management ..... yes
  SQL drivers: 
    DB2 .................. no
    InterBase ............ no
    MySQL ................ no
    OCI .................. no
    ODBC ................. no
    PostgreSQL ........... no
    SQLite 2 ............. no
    SQLite ............... yes (plugin, using bundled copy)
    TDS .................. no
  tslib .................. yes
  udev ................... yes
  xkbcommon-x11........... no
  xkbcommon-evdev......... no
  zlib ................... yes (bundled copy)

I’ll probably fix the segfault and make it work. But does anyone have some other idea or experience?

update

Segfault quick fix. Corrects the case when app starts without the screen.

diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
index 2e97233..b8dcc46 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp
@@ -101,7 +101,12 @@ QEvdevMouseHandler::QEvdevMouseHandler(const QString &device, int fd, bool abs,
     // Turning this on will not affect mice as these do not report in absolute coordinates
     // but will make touchpads act like touch screens
     if (m_abs)
-        m_abs = getHardwareMaximum();
+    {
+        if (QScreen *screen = QGuiApplication::primaryScreen())
+            handleAbsTouchScreenAdded(screen);
+
+        connect(qGuiApp, &QGuiApplication::screenAdded, this, &QEvdevMouseHandler::handleAbsTouchScreenAdded);
+    }

     // socket notifier for events on the mouse device
     QSocketNotifier *notifier;
@@ -115,9 +120,14 @@ QEvdevMouseHandler::~QEvdevMouseHandler()
         qt_safe_close(m_fd);
 }

+void QEvdevMouseHandler::handleAbsTouchScreenAdded(QScreen *screen)
+{
+    m_abs = getHardwareMaximum(screen);
+}
+
 // Ask touch screen hardware for information on coordinate maximums
 // If any ioctls fail, revert to non abs mode
-bool QEvdevMouseHandler::getHardwareMaximum()
+bool QEvdevMouseHandler::getHardwareMaximum(QScreen *screen)
 {
     unsigned char absFeatures[(ABS_MAX / 8) + 1];
     memset(absFeatures, '', sizeof (absFeatures));
@@ -141,7 +151,7 @@ bool QEvdevMouseHandler::getHardwareMaximum()

     m_hardwareHeight = absInfo.maximum - absInfo.minimum;

-    QRect g = QGuiApplication::primaryScreen()->virtualGeometry();
+    QRect g = screen->virtualGeometry();
     m_hardwareScalerX = static_cast<qreal>(m_hardwareWidth) / (g.right() - g.left());
     m_hardwareScalerY = static_cast<qreal>(m_hardwareHeight) / (g.bottom() - g.top());

diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
index 172136b..977350e 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
+++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler_p.h
@@ -51,6 +51,7 @@
 QT_BEGIN_NAMESPACE

 class QSocketNotifier;
+class QScreen;

 class QEvdevMouseHandler : public QObject
 {
@@ -65,12 +66,13 @@ signals:

 private slots:
     void readMouseData();
+    void handleAbsTouchScreenAdded(QScreen *screen);

 private:
     QEvdevMouseHandler(const QString &device, int fd, bool abs, bool compression, int jitterLimit);

     void sendMouseEvent();
-    bool getHardwareMaximum();
+    bool getHardwareMaximum(QScreen *screen);

     QString m_device;
     int m_fd;

Btw, if someone files a bug on the Qt bug tracker, it will probably count as ‘accepted answer’.

One Answer

The setup described at https://wiki.qt.io/index.php?title=RaspberryPi2EGLFS makes multitouch support work out of the box for me, using EGLFS (Qt 5.6, RPI B+, official 7" LCD screen). No special configure option or env var, so it's either a fix in Qt 5.6 compared to 5.5, or the set of libs that have to be installed before compiling Qt as described on that page. Unless of course there's a difference due to the fact that we're not using the same type of screen.

Answered by David Faure on December 8, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP