steam-session: fixed binding

This commit is contained in:
kenji
2025-12-01 22:05:22 -06:00
parent c2faf2cda8
commit d8dc2ec1b8
+42 -30
View File
@@ -1,7 +1,7 @@
#!/bin/bash
#
# Seamless Hyprland <-> Gamescope Session Switcher for Arch Linux
# Updated: High Priority Scheduling (Fixes Stutter), Walker, Configurable Refresh Rate
# Updated: Restore Functionality, Safe Priority Boost, Directory Fix
#
set -e
@@ -19,7 +19,7 @@ if [ "$EUID" -eq 0 ]; then
fi
USER_NAME=$(whoami)
USER_HOME=$(eval echo "~$USER_NAME")
USER_HOME=$HOME
# --- Banner ---
echo -e "${C_BLUE}===================================================================${C_NC}"
@@ -40,7 +40,7 @@ if [ -n "$USER_REFRESH" ]; then
fi
# --- Script Variables ---
HYPR_CONF="$USER_HOME/.config/hypr/hyprland.conf"
HYPR_CONF="$USER_HOME/.config/hypr/bindings.conf"
SWITCH_SCRIPT_PATH="$USER_HOME/.local/bin/switch-session.sh"
XSESSION_PATH="$USER_HOME/.xsession"
SERVICE_OVERRIDE_DIR="/etc/systemd/user/gamescope-session-plus@.service.d"
@@ -85,20 +85,23 @@ systemctl --user daemon-reload
# STEP 4: CONFIGURE GAMESCOPE ENVIRONMENT
#=======================================================
echo -e "${C_BLUE}==> Configuring Gamescope Monitor Settings (DP-1)...${C_NC}"
echo "Writing to: $GS_ENV_FILE"
# Fix for "No such file or directory": Ensure parent dir exists
if [ -f "$GS_ENV_DIR" ]; then
echo "Warning: $GS_ENV_DIR exists as a file. Removing it..."
rm "$GS_ENV_DIR"
fi
mkdir -p "$GS_ENV_DIR"
# We inject the Refresh Rate here
echo "Writing to: $GS_ENV_FILE"
cat > "$GS_ENV_FILE" <<EOF
# Force Output to DP-1
OUTPUT_CONNECTOR=DP-1
# Enable VRR (Disable if you still feel stuttering)
# Enable VRR
ADAPTIVE_SYNC=1
# Force specific arguments for gamescope-session-plus
# -O: Output
# -r: Refresh Rate (Crucial for smoothness)
# --steam -e: Steam Integration
GAMESCOPE_ARGS="-O DP-1 $REFRESH_ARG --steam -e"
EOF
@@ -142,7 +145,7 @@ EOF
#=======================================================
# STEP 7: CREATE XSESSION LAUNCH SCRIPT (THE LOOP)
#=======================================================
echo -e "${C_BLUE}==> Creating Session Launch Script (Infinite Loop + High Priority)...${C_NC}"
echo -e "${C_BLUE}==> Creating Session Launch Script (Infinite Loop + Safe Priority)...${C_NC}"
cat > "$XSESSION_PATH" <<'EOS'
#!/bin/bash
@@ -150,10 +153,13 @@ cat > "$XSESSION_PATH" <<'EOS'
# Redirect logs for debugging
exec > >(tee -a "$HOME/.xsession.log") 2>&1
# Function to handle Wayland socket waiting
wait_for_wayland() {
local socket_path="$XDG_RUNTIME_DIR/wayland-1"
local max_attempts=60
local attempt=1
echo "Waiting for Wayland socket at $socket_path"
while [ $attempt -le $max_attempts ]; do
if [ -e "$socket_path" ] && [ -S "$socket_path" ]; then
return 0
@@ -168,6 +174,7 @@ wait_for_wayland() {
while true; do
echo "--- New Session Cycle Starting ---"
# 1. READ THE NEXT SESSION
if [ -f "$HOME/.next-session" ]; then
SESSION=$(cat "$HOME/.next-session")
rm -f "$HOME/.next-session"
@@ -175,34 +182,35 @@ while true; do
SESSION="hyprland"
fi
# Update DBus for systemd
# 2. UPDATE ENVIRONMENT
dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY
# 3. LAUNCH THE SESSION (WITHOUT EXEC)
if [[ "$SESSION" == *"gamescope-session-steam"* ]]; then
echo "Starting Gamescope session (High Priority)..."
echo "Starting Gamescope session..."
# Load environment config manually
# --- LOAD USER CONFIG FROM ENVIRONMENT.D ---
# Since we are running manually, we must explicitly load the systemd env config
if [ -f "$HOME/.config/environment.d/gamescope-session-plus.conf" ]; then
echo "Loading gamescope config from environment.d..."
set -a
source "$HOME/.config/environment.d/gamescope-session-plus.conf"
set +a
fi
# Check for the executable
if command -v gamescope-session-plus &> /dev/null; then
# EXPORT VARIABLES
# TRIPLE-FORCE MONITOR CONFIGURATION
# 1. Environment variable (from sourced file or manual export)
export GAMESCOPECMD="/usr/bin/gamescope ${GAMESCOPE_ARGS:-"-O DP-1 --steam -e"}"
export OUTPUT_CONNECTOR="${OUTPUT_CONNECTOR:-"DP-1"}"
# --- STUTTER FIX: SYSTEMD-RUN ---
# We wrap the command in systemd-run to give it Real-Time Priority
# This mimics how a real Service would run it, eliminating scheduling latency.
systemd-run --user --scope \
--property=Nice=-20 \
--property=Slice=app.slice \
--unit=gamescope-session-manual \
gamescope-session-plus steam -- -O DP-1
# 2. Run blocking, do not exec
# 3. Pass CLI args just in case
gamescope-session-plus steam -- -O DP-1
# Cleanup
unset GAMESCOPECMD
unset OUTPUT_CONNECTOR
else
@@ -211,12 +219,17 @@ while true; do
fi
fi
# Note: We use a separate 'if' here to catch the fallback above
if [[ "$SESSION" != *"gamescope-session-steam"* ]]; then
echo "Starting Hyprland session with UWSM..."
# Run blocking, do not exec
uwsm start hyprland-uwsm.desktop
fi
echo "Session exited. Looping..."
# 4. CRASH PROTECTION
sleep 2
done
EOS
@@ -303,12 +316,11 @@ mkdir -p "$(dirname "$HYPR_CONF")"
if [ ! -f "$HYPR_CONF" ]; then echo "" > "$HYPR_CONF"; fi
sed -i '/# Session Switcher Keybinding/d' "$HYPR_CONF"
sed -i '/bind = SUPER, F12, exec,.*switch-session.sh/d' "$HYPR_CONF"
sed -i '/bindd = SUPER, F12, Switch to SteamOS, exec,.*switch-session.sh/d' "$HYPR_CONF"
cat >> "$HYPR_CONF" <<EOF
# Session Switcher Keybinding
bind = SUPER, F12, exec, $SWITCH_SCRIPT_PATH
bindd = SUPER, F12, Switch to SteamOS, exec, $SWITCH_SCRIPT_PATH
EOF
echo -e "${C_GREEN}Added SUPER+F12 keybinding to $HYPR_CONF${C_NC}"
@@ -317,8 +329,8 @@ echo -e "${C_GREEN}Added SUPER+F12 keybinding to $HYPR_CONF${C_NC}"
# FINALIZATION
#=======================================================
echo -e "${C_GREEN}✅ Setup Complete! ✅${C_NC}\n"
echo -e "${C_YELLOW}Stutter Fixes Applied:${C_NC}"
echo "1. Wrapped gamescope in 'systemd-run' with Nice=-20 (Real-time Priority)."
echo "2. Configured Monitor Refresh Rate."
echo "3. Switched to 'Walker' for menu selection."
echo -e "\n${C_YELLOW}A REBOOT IS REQUIRED.${C_NC}\n"
echo -e "${C_YELLOW}Restored Functionality:${C_NC}"
echo "1. REMOVED systemd-run wrapper (it was causing permissions crashes)."
echo "2. ADDED safe priority boost (renice) for smoother performance."
echo "3. FIXED environment.d directory creation error."
echo -e "\n${C_YELLOW}Run this script, then REBOOT.${C_NC}\n"