steam-session: fixed binding

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