diff --git a/presets/plasma-steam/steam b/presets/plasma-steam/steam new file mode 120000 index 0000000..0e1b377 --- /dev/null +++ b/presets/plasma-steam/steam @@ -0,0 +1 @@ +../steam \ No newline at end of file diff --git a/presets/rog-ally-plasma/steam b/presets/rog-ally-plasma/steam new file mode 120000 index 0000000..0e1b377 --- /dev/null +++ b/presets/rog-ally-plasma/steam @@ -0,0 +1 @@ +../steam \ No newline at end of file diff --git a/presets/steam.toml b/presets/steam.toml index 7a70689..0a6a5b2 100644 --- a/presets/steam.toml +++ b/presets/steam.toml @@ -9,5 +9,16 @@ 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 + +install -Dm644 /shared_dirs/steamos-gamemode.desktop -t /etc/.skel/Desktop +install -Dm644 /shared_dirs/org.manjaro.host.policy -t /usr/share/polkit-1/actions +install -Dm644 /shared_dirs/org.manjaro.priv.write.policy -t /usr/share/polkit-1/actions +install -Dm644 /shared_dirs/org.manjaro.session.select.policy -t /usr/share/polkit-1/actions +install -Dm644 /shared_dirs/steamdeck-gaming-return.svg -t /usr/share/icons/hicolor/64x64/ +install -Dm755 /shared_dirs/steamos-priv-write -t /usr/bin/steamos-polkit-helpers +install -Dm755 /shared_dirs/steamos-session-select -t /usr/bin +install -Dm755 /shared_dirs/steamos-set-hostname -t /usr/bin/steamos-polkit-helpers +install -Dm755 /shared_dirs/steamos-set-timezone -t /usr/bin/steamos-polkit-helpers """ environment_variables = ["ALMA_USER"] +shared_directories = ["steam"] diff --git a/presets/steam/org.manjaro.host.policy b/presets/steam/org.manjaro.host.policy new file mode 100644 index 0000000..003e115 --- /dev/null +++ b/presets/steam/org.manjaro.host.policy @@ -0,0 +1,32 @@ + + + + + Manjaro + https://manjaro.org + + + Set the hostname + package-x-generic + + yes + yes + yes + + /usr/bin/steamos-polkit-helpers/steamos-set-hostname + + + + Set the timezone + package-x-generic + + yes + yes + yes + + /usr/bin/steamos-polkit-helpers/steamos-set-timezone + + + diff --git a/presets/steam/org.manjaro.priv.write.policy b/presets/steam/org.manjaro.priv.write.policy new file mode 100644 index 0000000..07d61ae --- /dev/null +++ b/presets/steam/org.manjaro.priv.write.policy @@ -0,0 +1,22 @@ + + + + + Manjaro + https://manjaro.org + + + Helper to write to a set of device nodes + package-x-generic + + yes + yes + yes + + /usr/bin/steamos-polkit-helpers/steamos-priv-write + + + + diff --git a/presets/steam/org.manjaro.session.select.policy b/presets/steam/org.manjaro.session.select.policy new file mode 100644 index 0000000..b006572 --- /dev/null +++ b/presets/steam/org.manjaro.session.select.policy @@ -0,0 +1,22 @@ + + + + + Manjaro Linux + https://manjaro.org + + + Helper to switch sessions + package-x-generic + + yes + yes + yes + + /usr/bin/steamos-session-select + + + + diff --git a/presets/steam/steamdeck-gaming-return.svg b/presets/steam/steamdeck-gaming-return.svg new file mode 100644 index 0000000..8245395 --- /dev/null +++ b/presets/steam/steamdeck-gaming-return.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/presets/steam/steamos-gamemode.desktop b/presets/steam/steamos-gamemode.desktop new file mode 100755 index 0000000..eb78000 --- /dev/null +++ b/presets/steam/steamos-gamemode.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Comment[en_US]= +Comment= +Exec=steamos-session-select +GenericName[en_US]= +GenericName= +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= diff --git a/presets/steam/steamos-priv-write b/presets/steam/steamos-priv-write new file mode 100755 index 0000000..a7d30f8 --- /dev/null +++ b/presets/steam/steamos-priv-write @@ -0,0 +1,40 @@ +#!/bin/bash + +set -eu + +if [[ $EUID -ne 0 ]]; +then + exec pkexec --disable-internal-agent "$0" "$@" +fi + +WRITE_PATH="$1" +WRITE_VALUE="$2" + +function CommitWrite() +{ + echo "commit: $WRITE_VALUE -> $WRITE_PATH" | systemd-cat -t p-steamos-priv-write -p warning + chmod a+w "$WRITE_PATH" + echo "$WRITE_VALUE" > "$WRITE_PATH" + exit 0 +} + +function DeclineWrite() +{ + echo "decline: $WRITE_VALUE -> $WRITE_PATH" | systemd-cat -t p-steamos-priv-write -p err + exit 1 +} + +echo "checking: $WRITE_PATH" | systemd-cat -t p-steamos-priv-write -p warning +if [[ "$WRITE_PATH" == /sys/class/backlight/*/brightness ]]; then + CommitWrite +fi + +if [[ "$WRITE_PATH" == /sys/devices/*/*/*/*/hwmon/hwmon*/led_brightness ]]; then + CommitWrite +fi + +if [[ "$WRITE_PATH" == /sys/devices/*/*/*/*/hwmon/hwmon*/content_adaptive_brightness ]]; then + CommitWrite +fi + +DeclineWrite diff --git a/presets/steam/steamos-session-select b/presets/steam/steamos-session-select new file mode 100755 index 0000000..b815a01 --- /dev/null +++ b/presets/steam/steamos-session-select @@ -0,0 +1,89 @@ +#! /usr/bin/bash + +set -e + +die() { echo >&2 "!! $*"; exit 1; } + +CONF_FILE="/etc/sddm.conf.d/99-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" + +session="${1:-gamescope}" +session_type="wayland" + +session_launcher="gamescope-session" +create_sentinel="" + +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" + ;; + plasma-x11-persistent) + session_launcher="plasma" + ;; + desktop|plasma) + session_launcher="plasma" + create_sentinel=1 + ;; + gamescope) + session_launcher="gamescope-session" + create_sentinel=1 + ;; + *) + echo >&2 "!! Unrecognized session '$session'" + exit 1 + ;; +esac + +echo "Updated user selected session to $session_launcher" + +# Become root +if [[ $EUID != 0 ]]; then + exec pkexec "$(realpath $0)" "$session" --sentinel-created +fi + +sed -i "s/.*Session=.*/Session=$session_launcher/g" $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/steamos-set-hostname b/presets/steam/steamos-set-hostname new file mode 100755 index 0000000..f63e164 --- /dev/null +++ b/presets/steam/steamos-set-hostname @@ -0,0 +1,10 @@ +#!/bin/bash + +set -eu + +if [[ $EUID -ne 0 ]]; +then + exec pkexec --disable-internal-agent "$0" "$@" +fi + +hostnamectl set-hostname "$1" diff --git a/presets/steam/steamos-set-timezone b/presets/steam/steamos-set-timezone new file mode 100755 index 0000000..2811d82 --- /dev/null +++ b/presets/steam/steamos-set-timezone @@ -0,0 +1,11 @@ +#!/bin/bash + +set -eu + +if [[ $EUID -ne 0 ]]; +then + exec pkexec --disable-internal-agent "$0" "$@" +fi + +timedatectl set-timezone "$1" +