GNOME prototype: detect GNOME/GDM, GDM autologin and session switching

This commit is contained in:
theupriser committed 2026-10-14 13:40:13 +02:00
1 parent 7926e8b9ac
commit 66a9d33210
14 files changed
+268 -15

No files matched your search

+1 -2
View File
@@ -178,8 +178,7 @@ backend_apply() {
backend_sudo || return 1
LOGIN_MANAGER=plasmalogin
[[ "${WANTED[single]}" == 1 ]] && LOGIN_MANAGER=sddm
choose_login_manager
local -a failed=()
for c in "${TO_DISABLE[@]}"; do
if backend_run_component "$c" disable; then feature_record "$c" disable; else failed+=("$c"); fi
+1 -1
View File
@@ -23,7 +23,7 @@ boot_enable() {
# the session into the base config; run it right away rather than rely
# on its path unit, which could still be pending when the login manager
# starts.
service_file "$BOOT_UNIT_NAME" SESSION_SYNC="$SESSION_SYNC" | sudo tee "$BOOT_UNIT" > /dev/null
service_file "$BOOT_UNIT_NAME" SESSION_SYNC="$SESSION_SYNC" DESKTOP_SESSION="$(desktop_session_file)" | sudo tee "$BOOT_UNIT" > /dev/null
sudo systemctl daemon-reload
sudo systemctl enable "$BOOT_UNIT_NAME" || { err "Enabling $BOOT_UNIT_NAME failed."; return 1; }
ok "Boots into the desktop from the next boot on (Return to Gaming Mode still works)."
+14 -2
View File
@@ -23,7 +23,10 @@ create_desktop_shortcut() {
# the shortcut can't sudo for interactively (Terminal=false), so it gets
# a password-less rule scoped to exactly those two commands.
local exec_line="steamos-session-select gamescope"
if [[ "$LOGIN_MANAGER" == "plasmalogin" ]]; then
if [[ "$LOGIN_MANAGER" == "gdm" ]]; then
# Its own steamos-session-select (lib/login-manager.sh) restarts GDM, through the helper and rule gdm_fix_install adds.
:
elif [[ "$LOGIN_MANAGER" == "plasmalogin" ]]; then
exec_line="sh -c 'steamos-session-select gamescope && sudo -n /usr/bin/systemctl start sync-steamos-session.service && sudo -n /usr/bin/systemctl restart plasmalogin'"
local sudoers_tmp
sudoers_tmp="$(mktemp)"
@@ -40,6 +43,9 @@ EOF
else
sudo rm -f /etc/sudoers.d/gamescope-session-switch
fi
# GNOME shows no icons on the desktop: the application grid gets the shortcut too.
gnome_app_shortcut=false
[[ "$(desktop_kind)" == gnome ]] && gnome_app_shortcut=true
# SteamOS itself uses Valve's "gaming-return" icon (Steam logo with a
# return arrow; the Deck-style arrow is only used on Steam Deck
@@ -66,6 +72,12 @@ EOF
# Fix permissions for the target user and KDE Plasma desktop ecosystem
chmod +x "$shortcut_path"
if [[ "$gnome_app_shortcut" == true ]]; then
mkdir -p "$user_home/.local/share/applications"
cp "$shortcut_path" "$user_home/.local/share/applications/steamify-return-to-gaming-mode.desktop"
# GNOME only starts launchers it trusts.
gio set "$shortcut_path" metadata::trusted true 2>/dev/null || true
fi
ok "Desktop shortcut created successfully."
}
@@ -81,6 +93,6 @@ set_shortcut_icon() {
remove_desktop_shortcut() {
local desktop_dir
desktop_dir="$(xdg-user-dir DESKTOP 2>/dev/null || echo "$HOME/Desktop")"
rm -f "$desktop_dir/Return to Gaming Mode.desktop"
rm -f "$desktop_dir/Return to Gaming Mode.desktop" "$HOME/.local/share/applications/steamify-return-to-gaming-mode.desktop"
sudo rm -f /etc/sudoers.d/gamescope-session-switch
}
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
# Which desktop Steamify is running on (KDE Plasma or GNOME), and the
# session the login manager has to start for it. GNOME (GDM) is a prototype.
# Sourced by steamify.sh; not meant to be run on its own.
desktop_kind() {
# gnome or kde: the running session first, else what the login manager
# is (GDM means GNOME), else KDE, which Steamify was made for.
case ":${STEAMIFY_DESKTOP:-${XDG_CURRENT_DESKTOP:-}}:" in
*:GNOME:*|*:gnome:*) echo gnome; return ;;
*:KDE:*|*:kde:*) echo kde; return ;;
esac
[[ "$(current_display_manager)" == gdm ]] && { echo gnome; return; }
echo kde
}
desktop_session_file() {
# The login manager's session entry for the desktop: plasma.desktop, or
# whichever GNOME one is installed (gnome.desktop, gnome-xorg.desktop).
local f
if [[ "$(desktop_kind)" == gnome ]]; then
for f in /usr/share/wayland-sessions/gnome*.desktop /usr/share/xsessions/gnome*.desktop; do
[[ -f "$f" ]] && { basename "$f"; return; }
done
echo gnome.desktop
else
echo plasma.desktop
fi
}
choose_login_manager() {
# LOGIN_MANAGER for gaming_enable: gdm on GNOME, else sddm with single
# user mode and plasmalogin without.
if [[ "$(desktop_kind)" == gnome ]]; then LOGIN_MANAGER=gdm
elif [[ "${WANTED[single]:-0}" == 1 ]]; then LOGIN_MANAGER=sddm
else LOGIN_MANAGER=plasmalogin; fi
}
+93
View File
@@ -4,6 +4,11 @@
# Sourced by steamify.sh; not meant to be run on its own.
BASE_CONF="/etc/plasmalogin.conf"
GDM_CONF="/etc/gdm/custom.conf"
GDM_FIX_DIR=/usr/local/share/steamify-gdm
GDM_HOOK=/etc/pacman.d/hooks/95-steamify-gdm.hook
GDM_SUDOERS=/etc/sudoers.d/steamify-gdm-relogin
GDM_RELOGIN=/usr/local/libexec/steamify-gdm-relogin
# The "SteamOS conversion" menu item: gaming mode boot, the Return to
# Gaming Mode shortcut and Steam on the desktop (lib/steam-desktop.sh).
@@ -14,6 +19,9 @@ gaming_status() {
plasmalogin)
sed -n '/^\[Autologin\]/,/^\[/p' "$BASE_CONF" 2>/dev/null | grep -qx "User=$USER" &&
[[ -f /etc/systemd/system/sync-steamos-session.path ]] ;;
gdm)
sed -n '/^\[daemon\]/,/^\[/p' /etc/gdm/custom.conf 2>/dev/null | grep -qx "AutomaticLogin=$USER" &&
[[ -f "$GDM_FIX_DIR/steam-set-session" ]] ;;
*) return 1 ;;
esac
}
@@ -108,6 +116,14 @@ gaming_enable() {
configure_autologin
install_session_sync
;;
gdm)
# GNOME (prototype): GDM autologin, plus CachyOS's session tools made GDM-aware.
remove_sddm_autologin
remove_session_sync
switch_to_gdm || return 1
configure_gdm_autologin || return 1
gdm_fix_install || return 1
;;
esac
# (NVIDIA with single user mode from before the conversion: its desktop autologin would pin the Plasma session.)
single_login_release
@@ -122,8 +138,13 @@ gaming_disable() {
info "Turning off booting into gaming mode..."
remove_sddm_autologin
remove_session_sync
if [[ "$(current_display_manager)" == gdm ]]; then
gdm_fix_remove
restore_gdm_config
else
restore_plasmalogin_config
switch_to_plasmalogin
fi
remove_desktop_shortcut
steam_disable
gsn_disable
@@ -297,3 +318,75 @@ install_session_sync() {
sudo cat "$BASE_CONF"
echo
}
switch_to_gdm() {
# Already the login manager on a GNOME install; this only makes sure it is installed and enabled.
[[ "$(current_display_manager)" == gdm ]] && return 0
info "Installing and enabling GDM..."
sudo pacman -S --needed --noconfirm gdm || { err "Installing gdm failed."; return 1; }
local current
current="$(systemctl show -p Id --value display-manager 2>/dev/null)"
[[ -n "$current" && "$current" != gdm.service ]] && sudo systemctl disable "$current"
sudo systemctl enable -f gdm.service || { err "Enabling gdm failed."; return 1; }
ok "GDM is the login manager from the next boot on."
}
configure_gdm_autologin() {
# [daemon] AutomaticLogin: GDM reads it when it starts, which is why the
# session tools restart GDM to log in again (see patches/steamify-gdm-session-select.sh).
info "Configuring GDM autologin for $TARGET_USER"
sudo mkdir -p /etc/gdm
sudo touch "$GDM_CONF"
[[ -f "$GDM_CONF.bak-steamify" ]] || sudo cp -a "$GDM_CONF" "$GDM_CONF.bak-steamify"
sudo awk '
/^\[daemon\]/ { print; indaemon=1; next }
/^\[/ { indaemon=0 }
indaemon && /^(AutomaticLoginEnable|AutomaticLogin)=/ { next }
{ print }
' "$GDM_CONF" | sudo tee "$GDM_CONF.tmp" > /dev/null
grep -q '^\[daemon\]' "$GDM_CONF.tmp" || printf '[daemon]\n' | sudo tee -a "$GDM_CONF.tmp" > /dev/null
sudo sed -i "/^\[daemon\]/a AutomaticLoginEnable=True\nAutomaticLogin=$TARGET_USER" "$GDM_CONF.tmp"
sudo mv "$GDM_CONF.tmp" "$GDM_CONF"
ok "GDM autologin configured."
}
restore_gdm_config() {
if [[ -f "$GDM_CONF.bak-steamify" ]]; then
sudo cp -a "$GDM_CONF.bak-steamify" "$GDM_CONF" && sudo rm -f "$GDM_CONF.bak-steamify"
else
sudo sed -i '/^AutomaticLoginEnable=/d;/^AutomaticLogin=/d' "$GDM_CONF" 2>/dev/null
fi
}
gdm_fix_install() {
# CachyOS's steam-set-session and steamos-session-select only know
# plasma-login-manager/SDDM and KDE. Ours replace them at the same paths
# (Steam's Switch to Desktop calls them by path); a pacman hook puts them
# back after every update of gamescope-session-cachyos.
info "Making the session switching GDM-aware..."
sudo mkdir -p "$GDM_FIX_DIR"
patch_file steamify-gdm-steam-set-session.sh | sudo install -Dm755 /dev/stdin "$GDM_FIX_DIR/steam-set-session" &&
patch_file steamify-gdm-session-select.sh | fill DESKTOP_SESSION="$(desktop_session_file)" |
sudo install -Dm755 /dev/stdin "$GDM_FIX_DIR/steamos-session-select" || { err "Installing the GDM session tools failed."; return 1; }
patch_file steamify-gdm.hook | fill DIR="$GDM_FIX_DIR" | sudo install -Dm644 /dev/stdin "$GDM_HOOK"
# steamos-session-select logs in again through this helper (no password: it runs from the gaming session and from a shortcut).
patch_file steamify-gdm-relogin.sh | sudo install -Dm755 /dev/stdin "$GDM_RELOGIN"
echo "$TARGET_USER ALL=(root) NOPASSWD: $GDM_RELOGIN" | sudo install -Dm440 /dev/stdin "$GDM_SUDOERS"
sudo visudo -cf "$GDM_SUDOERS" > /dev/null || { sudo rm -f "$GDM_SUDOERS"; err "The sudoers rule for GDM is invalid."; return 1; }
for f in /usr/lib/steamos/steam-set-session /usr/bin/steamos-session-select; do
[[ -f "$f" && ! -f "$f.bak-steamify" ]] && sudo cp -a "$f" "$f.bak-steamify"
done
sudo install -m755 "$GDM_FIX_DIR/steam-set-session" /usr/lib/steamos/steam-set-session &&
sudo install -m755 "$GDM_FIX_DIR/steamos-session-select" /usr/bin/steamos-session-select || return 1
# Start in gamescope, as with the other login managers.
sudo /usr/lib/steamos/steam-set-session gamescope-session.desktop
ok "GDM autologin into gamescope is set up."
}
gdm_fix_remove() {
sudo rm -f "$GDM_HOOK" "$GDM_SUDOERS" "$GDM_RELOGIN"
for f in /usr/lib/steamos/steam-set-session /usr/bin/steamos-session-select; do
[[ -f "$f.bak-steamify" ]] && sudo mv "$f.bak-steamify" "$f"
done
sudo rm -rf "$GDM_FIX_DIR"
}
+3 -2
View File
@@ -60,6 +60,8 @@ component_available() {
# The SteamOS conversion is offered on NVIDIA PCs too: it installs the patched gamescope there (lib/gamescope-nvidia.sh)
# and turns off "Gaming on NVIDIA" (lib/nvidia.sh), which is not offered any more (nvidia_available).
nvidia|bigpicture|nvsilent) nvidia_available ;;
# Plasma only: the Vapor theme and single user mode (KDE Wallet, screen locker, Plasma's menu). Not on GNOME.
theme|single) [[ "$(desktop_kind)" == kde ]] ;;
machine|poweroff) machine_available ;;
vram) vram_available ;;
# Steamify in the Steam library is for gaming mode's controller: not needed for Big Picture on the desktop (NVIDIA PCs;
@@ -503,8 +505,7 @@ plan_changes() {
apply_changes() {
local c failed=()
LOGIN_MANAGER=plasmalogin
[[ "${WANTED[single]}" == 1 ]] && LOGIN_MANAGER=sddm
choose_login_manager
for c in "${TO_DISABLE[@]}"; do
if [[ "$c" == boot ]]; then echo; echo -e "${c_bold}Boot into: gamescope${c_reset}"
+5 -3
View File
@@ -84,9 +84,11 @@ python_hid_shim_ensure() {
install_required_packages() {
# Step 2: gamescope/Steam and the desktop helpers the rest of the setup uses.
local -a MISSING
info "Checking required packages: gamescope-session-cachyos, steam, mangohud, xterm, ttf-liberation, wqy-zenhei, plasma-keyboard"
mapfile -t MISSING < <(pacman -T gamescope-session-cachyos steam mangohud xterm ttf-liberation wqy-zenhei plasma-keyboard)
local -a MISSING required=(gamescope-session-cachyos steam mangohud xterm ttf-liberation wqy-zenhei)
# Plasma's on-screen keyboard; on GNOME kconfig instead, for the kreadconfig6/kwriteconfig6 Steamify's undo journal uses.
if [[ "$(desktop_kind)" == gnome ]]; then required+=(kconfig accountsservice); else required+=(plasma-keyboard); fi
info "Checking required packages: ${required[*]}"
mapfile -t MISSING < <(pacman -T "${required[@]}")
if [[ ${#MISSING[@]} -gt 0 ]]; then
python_hid_shim_ensure || return 1
+2 -2
View File
@@ -9,8 +9,8 @@ steam_enable() {
steam_env_dir="$HOME/.config/environment.d"
mkdir -p "$steam_env_dir"
# 2. Prevent KDE Wayland from blocking the virtual keyboard overlay
echo "KWIN_IM_SHOW_ALWAYS=1" > "$steam_env_dir/99-kde-virtual-keyboard.conf"
# 2. Prevent KDE Wayland from blocking the virtual keyboard overlay (KWin only)
[[ "$(desktop_kind)" == kde ]] && echo "KWIN_IM_SHOW_ALWAYS=1" > "$steam_env_dir/99-kde-virtual-keyboard.conf"
ok "Steam UI parameters and keyboard fix deployed successfully."
}
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# Log the autologin user in again, into the session steam-set-session picked
# (Steamify prototype, GDM). Run as root through sudo, from inside the session
# that is being left. GDM logs in by itself only when the daemon starts, and
# a new session refuses to start while the old user manager still runs
# ("A graphical session is already running!"): so the user is ended first,
# then GDM restarted. That work runs in its own transient unit, because
# ending the user kills this process too.
if [[ "$1" != --work ]]; then
[[ -n "${SUDO_USER:-}" ]] || exit 1
exec systemd-run --no-block --collect --unit=steamify-gdm-relogin "$0" --work "$SUDO_USER"
fi
USER_NAME="$2"
# No waiting for the old user manager to go: systemd starts the new login
# after it, and waiting only keeps GDM's login screen up in the meantime.
loginctl terminate-user "$USER_NAME"
systemctl restart gdm.service
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
# steamos-session-select for GDM (Steamify prototype): CachyOS's own ends the
# session with a KDE-only D-Bus call. GDM logs in by itself only when it
# starts, so after the new session is set the user is ended and GDM restarted
# (patches/steamify-gdm-relogin.sh): it then logs the autologin user straight into it.
set -e
DM_ID="$(systemctl show -p Id --value display-manager)"
DM_ID="${DM_ID%.service}"
DESKTOP_SESSION=@DESKTOP_SESSION@
relogin() {
# Out of the running session into the one that was set.
case "$DM_ID" in
gdm) sudo -n /usr/local/libexec/steamify-gdm-relogin ;;
*) qdbus6 org.kde.Shutdown /Shutdown org.kde.Shutdown.logout ;;
esac
}
case "$1" in
persistent)
systemctl --user mask cachyos-gamescope-autologin.service
pkexec /usr/lib/steamos/steam-set-session "$DESKTOP_SESSION" ;;
oneshot)
systemctl --user unmask cachyos-gamescope-autologin.service
pkexec /usr/lib/steamos/steam-set-session gamescope-session.desktop ;;
gamescope)
pkexec /usr/lib/steamos/steam-set-session gamescope-session.desktop
relogin ;;
desktop|plasma|gnome)
pkexec /usr/lib/steamos/steam-set-session "$DESKTOP_SESSION"
steam -shutdown || true
systemctl --user stop gamescope-session.target || true
# Under GDM nothing logs in again by itself after the session ends.
[[ "$DM_ID" == gdm ]] && relogin ;;
*)
[[ -n "$1" ]] && echo -e "Unknown session '$1'\n"
echo "Usage: $(basename "$0") persistent|oneshot|gamescope|desktop"
exit 1 ;;
esac
if [[ -e /dev/input/.hidden ]]; then
pkexec mv /dev/input/.hidden/* /dev/input
pkexec rm -r /dev/input/.hidden
fi
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
# steam-set-session with GDM support (Steamify prototype). CachyOS's own only
# knows plasma-login-manager and SDDM and quietly does nothing on GDM. GDM
# has no autologin fragment: it takes the user's session from
# AccountsService, so that is where the session goes.
set -e
DM_ID="$(systemctl show -p Id --value display-manager)"
DM_ID="${DM_ID%.service}"
SESSION="${1:-gamescope-session.desktop}"
case "$DM_ID" in
plasmalogin) CONF_FILE="/etc/plasmalogin.conf.d/zz-steamos-autologin.conf" ;;
sddm) CONF_FILE="/etc/sddm.conf.d/zz-steamos-autologin.conf" ;;
gdm)
if [[ -n "${PKEXEC_UID:-}" ]]; then TARGET_USER="$(id -un "$PKEXEC_UID")"
else TARGET_USER="${SUDO_USER:-$(logname 2>/dev/null)}"; fi
# At boot (steamify-boot-desktop.service) nobody is logged in: the autologin user.
[[ -n "$TARGET_USER" ]] || TARGET_USER="$(sed -n 's/^AutomaticLogin=//p' /etc/gdm/custom.conf 2>/dev/null)"
[[ -n "$TARGET_USER" ]] || exit 0
ACCOUNT="/var/lib/AccountsService/users/$TARGET_USER"
SESSION_ID="${SESSION%.desktop}"
mkdir -p /var/lib/AccountsService/users
touch "$ACCOUNT"
grep -q '^\[User\]' "$ACCOUNT" || echo "[User]" >> "$ACCOUNT"
for key in Session XSession; do
if grep -q "^$key=" "$ACCOUNT"; then sed -i "s|^$key=.*|$key=$SESSION_ID|" "$ACCOUNT"
else sed -i "/^\[User\]/a $key=$SESSION_ID" "$ACCOUNT"; fi
done
systemctl restart accounts-daemon 2>/dev/null || true
exit 0 ;;
esac
# Any other login manager: nothing to do.
[[ -n "${CONF_FILE:-}" ]] || exit 0
mkdir -p "$(dirname "$CONF_FILE")"
printf '[Autologin]\nSession=%s\n' "$SESSION" > "$CONF_FILE"
+10
View File
@@ -0,0 +1,10 @@
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = gamescope-session-cachyos
[Action]
Description = Steamify: GDM support for gamescope-session-cachyos...
When = PostTransaction
Exec = /bin/sh -c 'install -m755 @DIR@/steam-set-session /usr/lib/steamos/steam-set-session && install -m755 @DIR@/steamos-session-select /usr/bin/steamos-session-select'
+2 -2
View File
@@ -1,10 +1,10 @@
[Unit]
Description=Steamify CachyOS: boot into the desktop instead of gaming mode
Before=display-manager.service sddm.service plasmalogin.service
Before=display-manager.service sddm.service plasmalogin.service gdm.service
[Service]
Type=oneshot
ExecStart=/usr/lib/steamos/steam-set-session plasma.desktop
ExecStart=/usr/lib/steamos/steam-set-session @DESKTOP_SESSION@
ExecStart=/bin/sh -c '[ -x @SESSION_SYNC@ ] && exec @SESSION_SYNC@ || true'
[Install]
+1 -1
View File
@@ -19,7 +19,7 @@ VERSION=2.12.0
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for lib in common state packages login-manager single-user steam-desktop steam-machine fremont-poweroff vram-booster hdmi-refresh nvidia gamescope-nvidia controllers cec boot-session vapor-theme steamos-extras bios desktop-shortcut wizard-shortcut steam-game update-notifier first-login menu backend; do
for lib in common state desktop packages login-manager single-user steam-desktop steam-machine fremont-poweroff vram-booster hdmi-refresh nvidia gamescope-nvidia controllers cec boot-session vapor-theme steamos-extras bios desktop-shortcut wizard-shortcut steam-game update-notifier first-login menu backend; do
# shellcheck source=/dev/null
source "$SCRIPT_DIR/lib/$lib.sh"
done