I had the same problem and found this discussion.
My solution for X11 (matchbox window manager) with qt5 is as follows.
I optionally do not switch off the display completely but reduce the brightness instead. But I still want to avoid that the first click goes to the application, because the dimmed display is somewhat dark and the user might not have seen what he touched.
First, I have a script which waits for a touch screen event for a certain time (the same time as for the screensaver). If the time elapses, the brightness of the display is reduced and an animation is started which exits if someone pressed on the touch screen. If that application exits, the brightness is set to the original value.
Second, the animation application is a Qt5 QuickScript Qml application.
First: the script which runs in background:
device=/dev/input/mouse0
timeout=$screentime
while [ 1 ]; do
read -t $timeout -n 1 < $device
notread=$?
if [ $notread == 0 ]; then
echo $brightness > /sys/class/backlight/pwm-backlight/brightness
else
echo nobody has touched the screen, set screen more dark
echo $darkness > /sys/class/backlight/pwm-backlight/brightness
/usr/bin/qt5/qml /usr/local/bin/darkshow.qml
fi
done
Second - the script darkshow.qml:
import QtQuick 2.2
import QtQuick.Window 2.1
Item {
Window { id: mainwindows
width: 1024
height: 600
visible: true
visibility: Window.Maximized
opacity: 0.5
modality: Qt.ApplicationModal
// if it should stay on top: flags: Qt.SplashScreen
MouseArea {
onClicked: Qt.quit();
anchors.fill: parent
}
onActiveChanged: {
console.log("onActiveChanged");
if (active == 0) Qt.quit();
}
AnimatedSprite {
id: sprite
width: 1024
height: 600
anchors.centerIn: parent
source: "content/awibuben_spritesheet.png"
frameCount: 5
frameSync: true
frameWidth: 1024
frameHeight: 600
}
}
}