#!/bin/bash
# Runs inside the plasma68-vnc user unit (see linuxdoors-plasma68-vnc).
GEOM="$1"
P=/opt/plasma68
export LINUXDOORS_PLASMA68_W="${GEOM%x*}" LINUXDOORS_PLASMA68_H="${GEOM#*x}"
export XDG_CONFIG_HOME="$HOME/.config/plasma68"
export XDG_DATA_HOME="$HOME/.local/share/plasma68"
export XDG_CACHE_HOME="$HOME/.cache/plasma68"
export XDG_STATE_HOME="$HOME/.local/state/plasma68"
mkdir -p "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" "$XDG_CACHE_HOME" "$XDG_STATE_HOME"
# Only the 6.8 config dirs: startplasma sources every plasma-workspace/env/*.sh
# in XDG_CONFIG_DIRS, and /etc/xdg holds Plasma 6.7.5's (they force
# KWIN_COMPOSE=Q and put the /usr 6.7.5 plugin paths first).
export XDG_CONFIG_DIRS="$P/etc/xdg"
export XDG_DATA_DIRS="$P/share:/usr/share"
export PATH="$P/libexec/linuxdoors-headless:$P/bin:/opt/qt6-full/bin:/usr/local/bin:/usr/bin:/bin"
export LD_LIBRARY_PATH="$P/lib:/opt/qt6-full/lib"
export QT_PLUGIN_PATH="$P/lib/plugins:/usr/lib/plugins:/opt/qt6-full/plugins"
export QML2_IMPORT_PATH="$P/lib/qml:/usr/lib/qml:/opt/qt6-full/qml"
export QML_IMPORT_PATH="$QML2_IMPORT_PATH"
# KWin 6.8's virtual backend only does OpenGL (no QPainter any more) and
# needs a render device. With KWIN_DRM_DEVICES set but naming no usable GPU,
# KWin picks its software render device (Mesa llvmpipe) -- right for a
# headless session, and it never touches the machine's real GPU.
export KWIN_DRM_DEVICES=/dev/null
export XDG_CURRENT_DESKTOP=KDE XDG_SESSION_DESKTOP=KDE KDE_FULL_SESSION=true XDG_SESSION_TYPE=wayland
export KRFB_LISTEN_ADDRESS=127.0.0.1
unset DISPLAY WAYLAND_DISPLAY SESSION_MANAGER
# classic (non-systemd) Plasma startup: plasma_session starts kwin via PATH
kwriteconfig6 --file startkderc --group General --key systemdBoot false
# a headless VNC desktop: no auto screen lock (it can still be locked by hand)
kwriteconfig6 --file kscreenlockerrc --group Daemon --key Autolock false
kwriteconfig6 --file kscreenlockerrc --group Daemon --key LockOnResume false
exec dbus-run-session -- "$P/bin/startplasma-wayland"
