#!/bin/sh
HERE="/opt/rpi-imager-embedded"

# Set up paths
export PATH="${HERE}/bin:${PATH}"
export LD_LIBRARY_PATH="${HERE}/lib:${LD_LIBRARY_PATH}"
export QT_PLUGIN_PATH="${HERE}/plugins"
export QML_IMPORT_PATH="${HERE}/qml"
export QT_QPA_PLATFORM_PLUGIN_PATH="${HERE}/plugins/platforms"
export QT_QPA_PLATFORM=linuxfb

# Font configuration for bundled fontconfig
export FONTCONFIG_PATH="${HERE}/etc/fonts"
export FONTCONFIG_FILE="${HERE}/etc/fonts/fonts.conf"
# Add our bundled fonts to the font path
export XDG_DATA_DIRS="${HERE}/share:${XDG_DATA_DIRS}"

# Disable desktop-specific features for embedded use
export QT_QUICK_CONTROLS_STYLE=Material

# UI scale factor is determined by the application itself: it reads the
# connected display's resolution and EDID from DRM and sets QT_SCALE_FACTOR
# before Qt initialises (see PlatformQuirks::applyEmbeddedDisplayScaling).
# Export QT_SCALE_FACTOR here only to force a manual override — the app
# respects an already-set value and won't overwrite it.

# GPU memory optimization for embedded systems
export QT_QUICK_BACKEND=software

# Software renderer with DPI scaling fix
export QSG_RENDER_LOOP=basic
export QT_QUICK_DEFAULT_TEXT_RENDER_TYPE=NativeRendering
export QSG_ATLAS_WIDTH=0
export QSG_ATLAS_HEIGHT=0
export QT_QPA_FB_DRM=/dev/dri/card1

exec "${HERE}/bin/rpi-imager" "$@"
