#!/bin/bash
# PS5 gamescope session launcher — invoked by tty1 (ps5-tty-session.sh).
#
# All flags are PS5-specific workarounds:
#   LIBSEAT_BACKEND=logind   : avoids seatd/logind conflict; matches the user
#                              session so gamescope can take DRM/input devices
#                              via logind TakeDevice()
#   WLR_LIBINPUT_NO_DEVICES=1: suppresses libinput "no input devices" abort;
#                              PS5 has no directly-attached HID devices on boot
#   --backend drm            : take the DRM device directly (no nested compositor)
#   -e                       : embedded / Steam Big Picture mode
#   --prefer-output DP-1     : target the PS5's internal DP connector
#   --sdr-gamut-wideness 0   : keep SDR colour space at sRGB; the PS5's internal
#                              DP->HDMI bridge cannot translate BT2020 signalling
#
# The ps5-display.lua script in ~/.config/gamescope/scripts/ enforces sRGB
# colorimetry at the DRM atomic commit level (belt-and-suspenders with the flag).

export LIBSEAT_BACKEND=logind
export WLR_LIBINPUT_NO_DEVICES=1

# Launch flags:
#   -gamepadui  : controller-friendly Steam UI (Big Picture-like)
#   NOT -steamos3 : would enable SteamOS atomic-OS-update polling. CachyOS is
#                   pacman-rolling, no atomupd manifest server, so Steam loops
#                   "Updater apply error: 2: null" and the OOBE blocks on the
#                   "Software updates" step. (Field-reported by users.) Use
#                   `sudo pacman -Syu` for OS updates.
exec /usr/bin/gamescope \
    --backend drm \
    -e \
    --prefer-output DP-1 \
    --sdr-gamut-wideness 0 \
    -- \
    /usr/bin/steam -gamepadui
