Dynamically show/hide the mouse cursor, depending on the input type

This commit is contained in:
Michael Zanetti 2020-08-04 11:15:51 +02:00
parent 4fb4c911bf
commit 0a0f952740
3 changed files with 30 additions and 1 deletions

View File

@ -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<QEvent::Type> 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<QEvent::Type> 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();

View File

@ -59,6 +59,8 @@ private:
QFile m_powerFile;
QFile m_brightnessFile;
bool m_cursorHidden = false;
int m_currentBrightness = 255;
};

View File

@ -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