feat: Add scripts and systemd services for SteamOS session management and game launching
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
LOG_FILE="$HOME/.local/logs/session.log"
|
||||
|
||||
log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOG_FILE"; }
|
||||
|
||||
start_gamescope() {
|
||||
log "Starting Gamescope session..."
|
||||
|
||||
CONF_FILE="$HOME/.config/gamescope/gamescope.conf"
|
||||
[ -f "$CONF_FILE" ] && source "$CONF_FILE"
|
||||
|
||||
OUTPUT_CONNECTOR=${OUTPUT_CONNECTOR:-HDMI-A-1}
|
||||
FRAMERATE=${FRAMERATE:-60}
|
||||
RESOLUTION=${RESOLUTION:-1920x1080}
|
||||
WIDTH="${RESOLUTION%x*}"
|
||||
HEIGHT="${RESOLUTION#*x}"
|
||||
|
||||
# export __GL_GSYNC_ALLOWED=1
|
||||
# export __GL_VRR_ALLOWED=1
|
||||
# # export __GL_THREADED_OPTIMIZATIONS=1
|
||||
# export __GL_SHADER_DISK_CACHE=1
|
||||
# export __GL_SYNC_TO_VBLANK=0
|
||||
|
||||
GAMESCOPE_BIN="$(command -v gamescope || true)"
|
||||
if [ -z "$GAMESCOPE_BIN" ]; then
|
||||
log "ERROR: gamescope not found in PATH"
|
||||
exit 127
|
||||
fi
|
||||
|
||||
HDR_FLAG=""
|
||||
if [[ "$HDR_ENABLED" == "1" || "$HDR_ENABLED" == "true" || "$HDR_ENABLED" == "yes" ]]; then
|
||||
HDR_FLAG="--hdr-enabled"
|
||||
log "HDR flag added: --hdr-enabled"
|
||||
else
|
||||
log "HDR disabled, no HDR flag added"
|
||||
fi
|
||||
|
||||
env | tee -a "$LOG_FILE"
|
||||
|
||||
# Build gamescope argument array for safe quoting and readability
|
||||
GAMESCOPE_ARGS=(
|
||||
--generate-drm-mode fixed
|
||||
--fade-out-duration 200
|
||||
--cursor-scale-height 720
|
||||
-f
|
||||
-W "$WIDTH" -H "$HEIGHT"
|
||||
-w "$WIDTH" -h "$HEIGHT"
|
||||
--rt --mangoapp -e
|
||||
-O "$OUTPUT_CONNECTOR"
|
||||
-r "$FRAMERATE"
|
||||
)
|
||||
|
||||
# Append HDR flag if enabled
|
||||
if [ -n "${HDR_FLAG:-}" ]; then
|
||||
GAMESCOPE_ARGS+=("$HDR_FLAG")
|
||||
fi
|
||||
|
||||
log "Launching Gamescope: $GAMESCOPE_BIN ${GAMESCOPE_ARGS[*]} -- $*"
|
||||
|
||||
# Execute gamescope inside a DBus session, preserving proper argument quoting
|
||||
exec dbus-run-session -- "$GAMESCOPE_BIN" "${GAMESCOPE_ARGS[@]}" -- "$@" >>"$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
start_kwin() {
|
||||
log "Starting KWin session..."
|
||||
KWIN_BIN="$(command -v kwin_wayland || true)"
|
||||
if [ -z "$KWIN_BIN" ]; then
|
||||
log "ERROR: kwin_wayland not found in PATH"
|
||||
exit 127
|
||||
fi
|
||||
|
||||
export XDG_CURRENT_DESKTOP=plasma
|
||||
export XDG_SESSION_TYPE=wayland
|
||||
export XDG_DATA_DIRS=/usr/local/share/:/usr/share/
|
||||
export XDG_CONFIG_DIRS=/usr/local/etc/xdg:/etc/xdg
|
||||
export XDG_CURRENT_DESKTOP=KDE
|
||||
export XDG_RUNTIME_DIR=/run/user/$(id -u)
|
||||
|
||||
# Ensure we don't run nested; width/height/fullscreen are for the windowed backend.
|
||||
unset DISPLAY WAYLAND_DISPLAY
|
||||
KWIN_ARGS="--drm --exit-with-session"
|
||||
log "Launching KWin (DRM): $KWIN_BIN ${KWIN_ARGS} $*"
|
||||
exec dbus-run-session -- "$KWIN_BIN" ${KWIN_ARGS} "$@" >>"$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
export XDG_SEAT=seat0
|
||||
|
||||
if [[ -f "$HOME/.desktop-session-plasma" ]]; then
|
||||
log "Plasma session selected."
|
||||
rm "$HOME/.desktop-session-plasma"
|
||||
start_kwin /usr/local/bin/launch_kde.sh
|
||||
else
|
||||
log "Gamescope session selected."
|
||||
start_gamescope /usr/local/bin/launch_steam.sh
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user