From 0a0f9527401de96564521c009140935328b2ba1d Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 4 Aug 2020 11:15:51 +0200 Subject: [PATCH] Dynamically show/hide the mouse cursor, depending on the input type --- .../generic/raspberrypihelper.cpp | 27 +++++++++++++++++++ .../generic/raspberrypihelper.h | 2 ++ .../lightdm/60-nymea-app-kiosk.conf | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nymea-app/platformintegration/generic/raspberrypihelper.cpp b/nymea-app/platformintegration/generic/raspberrypihelper.cpp index b5ed043b..99f9eace 100644 --- a/nymea-app/platformintegration/generic/raspberrypihelper.cpp +++ b/nymea-app/platformintegration/generic/raspberrypihelper.cpp @@ -67,6 +67,10 @@ RaspberryPiHelper::RaspberryPiHelper(QObject *parent) : QObject(parent) if (m_screenOffTimer.interval() > 0) { m_screenOffTimer.start(); } + + // Hide the mouse cursor right away, it'll be restored on mouse move events + QApplication::setOverrideCursor(Qt::BlankCursor); + m_cursorHidden = true; } bool RaspberryPiHelper::active() const @@ -126,6 +130,29 @@ bool RaspberryPiHelper::eventFilter(QObject *watched, QEvent *event) return QObject::eventFilter(watched, event); } + // Hide the mouse cursor if touchscreen events are coming in + QList touchTypes = { + QEvent::TouchBegin, + QEvent::TouchUpdate, + QEvent::TouchEnd + }; + if (touchTypes.contains(event->type()) && !m_cursorHidden) { + QApplication::setOverrideCursor(Qt::BlankCursor); + m_cursorHidden = true; + } + + // Restore the mouse cursor if hidden and mouse events come in + QList mouseTypes = { + QEvent::MouseMove, + QEvent::MouseButtonPress, + QEvent::GrabMouse + }; + if (mouseTypes.contains(event->type()) && m_cursorHidden) { + QApplication::restoreOverrideCursor(); + m_cursorHidden = false; + } + + if (!m_screenOffTimer.isActive()) { screenOn(); m_screenOffTimer.start(); diff --git a/nymea-app/platformintegration/generic/raspberrypihelper.h b/nymea-app/platformintegration/generic/raspberrypihelper.h index b8ac87f8..6b90a2c6 100644 --- a/nymea-app/platformintegration/generic/raspberrypihelper.h +++ b/nymea-app/platformintegration/generic/raspberrypihelper.h @@ -59,6 +59,8 @@ private: QFile m_powerFile; QFile m_brightnessFile; + bool m_cursorHidden = false; + int m_currentBrightness = 255; }; diff --git a/packaging/linux-common/lightdm/60-nymea-app-kiosk.conf b/packaging/linux-common/lightdm/60-nymea-app-kiosk.conf index 2a6adddd..1d0d32ee 100644 --- a/packaging/linux-common/lightdm/60-nymea-app-kiosk.conf +++ b/packaging/linux-common/lightdm/60-nymea-app-kiosk.conf @@ -1,4 +1,4 @@ [Seat:*] autologin-user=nymea user-session=nymea-app-kiosk -xserver-command=X -s 0 -dpms -nocursor +xserver-command=X -s 0 -dpms