#!/bin/sh

# SDDM sets this to wayland but apps using Gamescope must use x11
export XDG_SESSION_TYPE=x11

# Update the enviroment with DESKTOP_SESSION and all XDG variables
dbus-update-activation-environment --systemd DESKTOP_SESSION `env | grep ^XDG_ | cut -d = -f 1`

# This makes it so that xdg-desktop-portal doesn't find any portal implementations and doesn't start them and makes
# them crash/exit because the dbus env has no DISPLAY. In turn this causes dbus calls to the portal which don't rely
# on implementations to hang (such as SDL talking to the real time portal)
# Plasma resets this variable when it starts
systemctl --user set-environment XDG_DESKTOP_PORTAL_DIR=""

# Remove these as they prevent gamescope-session from starting correctly
systemctl --user unset-environment DISPLAY XAUTHORITY

# If this shell script is killed then stop gamescope-session
trap 'systemctl --user stop gamescope-session.service' HUP INT TERM

# Start gamescope-session and wait
systemctl --user --wait start gamescope-session.service &
wait
