From b3d6b09f613f052da4eb8142bf4e0b79df1675a3 Mon Sep 17 00:00:00 2001 From: Philip Mueller Date: Mon, 3 Jul 2023 15:56:02 +0200 Subject: [PATCH] [presets] update steam --- presets/steam.toml | 18 +++- .../gamescope-wayland-teardown-workaround | 12 +++ presets/steam/os-session-select | 97 +++++++++---------- presets/steam/plasma-steamos-oneshot.desktop | 7 ++ presets/steam/startplasma-steamos-oneshot | 46 +++++++++ presets/steam/steamos-gamemode.desktop | 19 +--- 6 files changed, 128 insertions(+), 71 deletions(-) create mode 100755 presets/steam/gamescope-wayland-teardown-workaround create mode 100644 presets/steam/plasma-steamos-oneshot.desktop create mode 100755 presets/steam/startplasma-steamos-oneshot diff --git a/presets/steam.toml b/presets/steam.toml index 78c2fd0..0b0147e 100644 --- a/presets/steam.toml +++ b/presets/steam.toml @@ -5,10 +5,17 @@ set -eux wget -v https://gitlab.com/evlaV/jupiter_steam-jupiter-stable-PKGBUILD/-/raw/5cd60f3cd66527a95f93e6fefd9371fd659a5aea/steam_jupiter_stable_bootstrapped_20230316.1.tar.xz -O /usr/lib/steam/bootstraplinux_ubuntu12_32.tar.xz mkdir -p /etc/sddm.conf.d -echo "# Created by Manjaro ALMA" > /etc/sddm.conf.d/99-autologin.conf -echo "[Autologin]" >> /etc/sddm.conf.d/99-autologin.conf -echo "User=${ALMA_USER}" >> /etc/sddm.conf.d/99-autologin.conf -echo "Session=gamescope-session.desktop" >> /etc/sddm.conf.d/99-autologin.conf +echo "# Created by Manjaro ALMA" > /etc/sddm.conf.d/manjaro.conf +echo "[General]" >> /etc/sddm.conf.d/manjaro.conf +echo "DisplayServer=wayland" >> /etc/sddm.conf.d/manjaro.conf +echo "[Autologin]" >> /etc/sddm.conf.d/manjaro.conf +echo "Relogin=true" >> /etc/sddm.conf.d/manjaro.conf +echo "Session=gamescope-session.desktop" >> /etc/sddm.conf.d/manjaro.conf +echo "User=$ALMA_USER" >> /etc/sddm.conf.d/manjaro.conf +echo "[X11]" >> /etc/sddm.conf.d/manjaro.conf +echo "# Janky workaround for wayland sessions not stopping in sddm, kills" >> /etc/sddm.conf.d/manjaro.conf +echo "# all active sddm-helper sessions on teardown" >> /etc/sddm.conf.d/manjaro.conf +echo "DisplayStopCommand=/usr/bin/gamescope-wayland-teardown-workaround" >> /etc/sddm.conf.d/manjaro.conf echo "[General]" > /etc/sddm.conf.d/virtualkbd.conf echo "InputMethod=qtvirtualkeyboard" >> /etc/sddm.conf.d/virtualkbd.conf @@ -22,6 +29,9 @@ install -Dm755 /shared_dirs/steam/steamos-priv-write -t /usr/bin/steamos-polkit- install -Dm755 /shared_dirs/steam/os-session-select -t /usr/lib install -Dm755 /shared_dirs/steam/steamos-set-hostname -t /usr/bin/steamos-polkit-helpers install -Dm755 /shared_dirs/steam/steamos-set-timezone -t /usr/bin/steamos-polkit-helpers +install -Dm755 /shared_dirs/steam/gamescope-wayland-teardown-workaround -t /usr/bin +install -Dm755 /shared_dirs/steam/startplasma-steamos-oneshot -t /usr/bin +install -Dm755 /shared_dirs/steam/plasma-steamos-oneshot.desktop -t /usr/share/xsessions chown -R ${ALMA_USER}:${ALMA_USER} /home/${ALMA_USER} """ environment_variables = ["ALMA_USER"] diff --git a/presets/steam/gamescope-wayland-teardown-workaround b/presets/steam/gamescope-wayland-teardown-workaround new file mode 100755 index 0000000..e2432ec --- /dev/null +++ b/presets/steam/gamescope-wayland-teardown-workaround @@ -0,0 +1,12 @@ +#!/bin/bash + +set -eu + +TARGETS=('/bin/bash /usr/bin/gamescope-session' + '/usr/bin/kwin_x11') + +for target in "${TARGETS[@]}"; do + for processtree in $(pgrep -xf "$target" || true); do + kill -- "-$processtree" + done +done diff --git a/presets/steam/os-session-select b/presets/steam/os-session-select index b815a01..9107c5f 100755 --- a/presets/steam/os-session-select +++ b/presets/steam/os-session-select @@ -1,67 +1,40 @@ -#! /usr/bin/bash +#!/bin/bash set -e die() { echo >&2 "!! $*"; exit 1; } -CONF_FILE="/etc/sddm.conf.d/99-autologin.conf" +# FIXME Purge old files and use this one + +# File this script will modify, in addition to (potentially) the per-user sentinel file +CONF_FILE="/etc/sddm.conf.d/zz-steamos-autologin.conf" + SENTINEL_FILE="steamos-session-select" # For sanity this shipped file must be present, to ensure we're still on a normal-looking setup. -CHECK_FILE="/etc/sddm.conf.d/99-autologin.conf" +CHECK_FILE="/etc/sddm.conf.d/manjaro.conf" session="${1:-gamescope}" -session_type="wayland" -session_launcher="gamescope-session" +session_launcher="" create_sentinel="" +session_uses_x11="" -if [[ "$2" == "--sentinel-created" ]]; then - SENTINEL_CREATED=1 - session_type="wayland" -fi - -# Update config sentinel -if [[ -z $SENTINEL_CREATED ]]; then - [[ $EUID == 0 ]] && die "Running $0 as root is not allowed" - - [[ -n ${HOME+x} ]] || die "No \$HOME variable" - config_dir="${XDG_CONF_DIR:-"$HOME/.config"}" - session_type=$( - cd "$HOME" - mkdir -p "$config_dir" - cd "$config_dir" - if [[ -f "steamos-session-type" ]]; then - cp steamos-session-type "$SENTINEL_FILE" - else - echo "wayland" > "$SENTINEL_FILE" - fi - cat "$SENTINEL_FILE" - ) - - # clear steam game desktop shortcut clutter - DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} - grep --files-with-matches "Exec=steam steam://rungameid/" ${DATA_HOME}/applications/* | tr '\n' '\0' | xargs -0 -I {} rm {} || true - - # If we were executed as a session user and then re-execute as root below, we don't want to set root's sentinel too - export SENTINEL_CREATED=1 -fi - -# We use "plasma" as "desktop" to hook up to SteamOS's scripts case "$session" in plasma-wayland-persistent) - session_launcher="plasma" + session_launcher="plasmawayland.desktop" ;; - plasma-x11-persistent) - session_launcher="plasma" + plasma-persistent) + session_launcher="plasma.desktop" + session_uses_x11=1 ;; - desktop|plasma) - session_launcher="plasma" + plasma) + session_launcher="plasma-steamos-oneshot.desktop" create_sentinel=1 + session_uses_x11=1 ;; gamescope) - session_launcher="gamescope-session" - create_sentinel=1 + session_launcher="gamescope-session.desktop" ;; *) echo >&2 "!! Unrecognized session '$session'" @@ -69,21 +42,43 @@ case "$session" in ;; esac -echo "Updated user selected session to $session_launcher" +if [[ "$2" == "--sentinel-created" ]]; then + SENTINEL_CREATED=1 +fi + +# Update config sentinel +if [[ -z $SENTINEL_CREATED ]]; then + [[ -n ${HOME+x} ]] || die "No \$HOME variable" + config_dir="${XDG_CONF_DIR:-"$HOME/.config"}" + ( + cd "$HOME" + mkdir -p "$config_dir" + cd "$config_dir" + echo "$session_launcher" > "$SENTINEL_FILE" + ) + + # If we were executed as a session user and then re-execute as root below, we don't want to set root's sentinel too + export SENTINEL_CREATED=1 + echo "Updated user selected session to $session_launcher" +fi # Become root if [[ $EUID != 0 ]]; then exec pkexec "$(realpath $0)" "$session" --sentinel-created + exit 1 fi -sed -i "s/.*Session=.*/Session=$session_launcher/g" $CONF_FILE +{ + if [[ -n $session_uses_x11 ]]; then + # Default is Wayland + echo "[General]" + echo "DisplayServer=X11" + fi + echo "[Autologin]" + echo "Session=$session_launcher" +} > "$CONF_FILE" echo "Updated system autologin session to $session_launcher" systemctl reset-failed sddm systemctl restart sddm echo "Restarted SDDM" - -if [[ $session == plasma ]] || [[ $session == desktop ]]; then - echo "Ending gamescope session" - pkill -f gamescope -fi diff --git a/presets/steam/plasma-steamos-oneshot.desktop b/presets/steam/plasma-steamos-oneshot.desktop new file mode 100644 index 0000000..79730e7 --- /dev/null +++ b/presets/steam/plasma-steamos-oneshot.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=XSession +Exec=/usr/bin/startplasma-steamos-oneshot +TryExec=/usr/bin/startplasma-steamos-oneshot +DesktopNames=KDE (One-Time Launch) +Name=Plasma (One-Time Launch) +Comment=Plasma by KDE - One Time Launch Redirect for SteamOS Sessions diff --git a/presets/steam/startplasma-steamos-oneshot b/presets/steam/startplasma-steamos-oneshot new file mode 100755 index 0000000..c906aab --- /dev/null +++ b/presets/steam/startplasma-steamos-oneshot @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +die() { echo >&2 "!! $*"; exit 1; } + +SENTINEL_FILE="steamos-session-select" +SENTINEL_VALUE="plasma-steamos-oneshot.desktop" + +# If we proceed, execute this +CHAINED_SESSION="/usr/bin/startplasma-x11" +# If we decide the sentinel is consumed, execute this command instead and fail +RESTORE_SESSION=(steamos-session-select) # No arguments restores the session + +# Find or check config sentinel +check_sentinel() +{ + if [[ -z ${HOME+x} ]]; then + echo >&2 "$0: No \$HOME variable!" + # Rather than break we'll just launch plasma and hope for the best? + return 0 + fi + + local config_dir="${XDG_CONF_DIR:-"$HOME/.config"}" + ( + cd "$HOME" + cd "$config_dir" + sentinel_value="$(cat "$SENTINEL_FILE")" + [[ $sentinel_value = "$SENTINEL_VALUE" ]] || return 1 + rm "$SENTINEL_FILE" + ) || return 1 # If we couldn't read the value or it wasn't what we wanted + + # Found value and removed it, we're good to continue + return 0 +} + +if check_sentinel; then + # We found and consumed the oneshot sentinel, proceed to launch plasma + echo >&2 "$0: Found and removed sentinel file for one-shot plasma, proceeding to launch" + exec "$CHAINED_SESSION" +else + echo >&2 "$0: Sentinel value not found, executing session-select to restore session" + "${RESTORE_SESSION[@]}" || echo >&2 "$0: !! Failed to restore previous session, executing chained session" + # Session restore should've stopped us, if it is broken at least let plasma continue to open + exec "$CHAINED_SESSION" +fi diff --git a/presets/steam/steamos-gamemode.desktop b/presets/steam/steamos-gamemode.desktop index eb78000..c10dced 100755 --- a/presets/steam/steamos-gamemode.desktop +++ b/presets/steam/steamos-gamemode.desktop @@ -1,20 +1,7 @@ [Desktop Entry] -Comment[en_US]= -Comment= -Exec=steamos-session-select -GenericName[en_US]= -GenericName= +Name=Return to Gaming Mode +Exec=qdbus org.kde.Shutdown /Shutdown org.kde.Shutdown.logout Icon=steamdeck-gaming-return -MimeType= -Name[en_US]=Return to Gaming mode -Name=Return to Gaming mode -Name[zh_CN]=返回游戏模式 -Path=/usr/bin/ -StartupNotify=true Terminal=false -TerminalOptions= Type=Application -X-DBUS-ServiceName= -X-DBUS-StartupType= -X-KDE-SubstituteUID=false -X-KDE-Username= +StartupNotify=false