#!/bin/sh
# use interactive shell environment for machine specific env vars
. /etc/profile

if [ -e /dev/input/res-touchscreen ] && [ -e /dev/input/touchscreen0 ]; then
    if [ ! -e /etc/pointercal ]; then
        #res. touchscreen is not calibrate. We should do this first
        /usr/bin/ts_calibrate
    fi
    #forbid libinput when using resistive touchscreens
    export QT_QPA_EGLFS_NO_LIBINPUT=1
    export QT_QPA_FB_NO_LIBINPUT=1
    #enable tslib
    export QT_QPA_EGLFS_TSLIB=1
    export QT_QPA_FB_TSLIB=1
    export TSLIB_TSDEVICE="/dev/input/touchscreen0"
fi

# disable qt's audiosink if no audio present
ls -1 /dev/snd/pcm* > /dev/null 2>&1
if [ "$?" != "0" ]; then
    export QT_GSTREAMER_PLAYBIN_AUDIOSINK=fakesink
fi

export QT_QPA_PLATFORM=wayland
export QT_QPA_EGLFS_ALWAYS_SET_MODE="1"
export QT_QPA_EGLFS_KMS_CONFIG=/etc/eglfs_kms.config
export QT_WAYLAND_SHELL_INTEGRATION=xdg-shell

# Common Debug Settings
#export QT_DEBUG_PLUGINS=1
#export QT_LOGGING_RULES=qt.qpa.*=true

if [ $# -eq 0 ]; then
    echo 'usage: qtLauncher <your_qt_application>'
else
    $@ #run the application
fi
