#!/bin/sh
# Starts OpenWater Chartplotter (installed as /usr/bin/openwater-chartplotter).
# Under a desktop (Wayland or X11) it opens in a window, with a Full screen button; with no
# desktop (the dedicated panels, a later SD-card image) it takes the whole display (eglfs/KMS).
# QT_QPA_PLATFORM set by the caller wins. ADR-0007.
here=/usr/lib/openwater-chartplotter

export LD_LIBRARY_PATH="$here/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
# The F10R panel PC (RK3399): its GPU's driver library (libmali) in place of Mesa.
[ -d /usr/lib/aarch64-linux-gnu/mali ] && export LD_LIBRARY_PATH="/usr/lib/aarch64-linux-gnu/mali:$LD_LIBRARY_PATH"
export QML_IMPORT_PATH="$here/qml"

if [ -z "$QT_QPA_PLATFORM" ]; then
    if [ -n "$WAYLAND_DISPLAY" ]; then
        export QT_QPA_PLATFORM=wayland
    elif [ -n "$DISPLAY" ]; then
        export QT_QPA_PLATFORM=xcb
    else
        export QT_QPA_PLATFORM=eglfs
        export QT_QPA_EGLFS_INTEGRATION=eglfs_kms
        export QT_QPA_EGLFS_ALWAYS_SET_MODE=1
    fi
fi

exec "$here/chartplotter" --data "$here/data" "$@"
