gamescope-session fixed scripting

This commit is contained in:
kenji
2025-12-01 21:15:02 -06:00
parent 417f5e17ad
commit e31f67e53e
+52 -93
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: Infinite Loop, env.d Config, Color Reset, IWD Backend # Updated: Walker, Infinite Loop, env.d Config, Color Reset, IWD Backend
# #
set -e set -e
@@ -37,13 +37,12 @@ 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"
SERVICE_OVERRIDE_FILE="$SERVICE_OVERRIDE_DIR/override.conf" SERVICE_OVERRIDE_FILE="$SERVICE_OVERRIDE_DIR/override.conf"
# UPDATED: Correct config path for systemd user environment
GS_ENV_DIR="$USER_HOME/.config/environment.d" GS_ENV_DIR="$USER_HOME/.config/environment.d"
GS_ENV_FILE="$GS_ENV_DIR/gamescope-session-plus.conf" GS_ENV_FILE="$GS_ENV_DIR/gamescope-session-plus.conf"
# UPDATED: Removed lib32-networkmanager # UPDATED: Removed wofi, added walker to AUR packages
OFFICIAL_PACKAGES=( "hyprland" "wofi" "sddm" "uwsm" "networkmanager" ) OFFICIAL_PACKAGES=( "hyprland" "sddm" "uwsm" "networkmanager" )
AUR_PACKAGES=( "gamescope-git" "gamescope-session-git" "steam" "gamescope-session-steam-git" "mangohud" ) AUR_PACKAGES=( "gamescope-git" "gamescope-session-git" "steam" "gamescope-session-steam-git" "mangohud" "walker" )
#======================================================= #=======================================================
# STEP 1: DEPENDENCY INSTALLATION # STEP 1: DEPENDENCY INSTALLATION
@@ -102,8 +101,6 @@ EOF
echo "Enabling NetworkManager..." echo "Enabling NetworkManager..."
sudo systemctl enable NetworkManager sudo systemctl enable NetworkManager
# We don't force start here to avoid killing the user's current SSH/Session immediately,
# but it will be active on reboot.
#======================================================= #=======================================================
# STEP 6: INSTALL SESSION SWITCHING LOGIC # STEP 6: INSTALL SESSION SWITCHING LOGIC
@@ -179,30 +176,12 @@ while true; do
if [[ "$SESSION" == *"gamescope-session-steam"* ]]; then if [[ "$SESSION" == *"gamescope-session-steam"* ]]; then
echo "Starting Gamescope session..." echo "Starting Gamescope session..."
# --- 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 # Check for the executable
if command -v gamescope-session-plus &> /dev/null; then if command -v gamescope-session-plus &> /dev/null; then
# Run blocking, do not exec
# TRIPLE-FORCE MONITOR CONFIGURATION export GAMESCOPECMD="/usr/bin/gamescope -O DP-1 --steam -e --"
# 1. Environment variable (from sourced file or manual export) gamescope-session-plus steam
export GAMESCOPECMD="/usr/bin/gamescope ${GAMESCOPE_ARGS:-"-O DP-1 --steam -e"}"
export OUTPUT_CONNECTOR="${OUTPUT_CONNECTOR:-"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 GAMESCOPECMD
unset OUTPUT_CONNECTOR
else else
echo "Error: gamescope-session-plus not found, falling back to Hyprland" echo "Error: gamescope-session-plus not found, falling back to Hyprland"
SESSION="hyprland" SESSION="hyprland"
@@ -222,91 +201,42 @@ while true; do
# 4. CRASH PROTECTION # 4. CRASH PROTECTION
sleep 2 sleep 2
done done
EOS EOS
chmod +x "$XSESSION_PATH" chmod +x "$XSESSION_PATH"
#======================================================= #=======================================================
# STEP 8: CREATE SWITCHING SCRIPT (COLOR RESET FIX) # STEP 8: CREATE SWITCHING SCRIPT (WALKER EDITION)
#======================================================= #=======================================================
echo -e "${C_BLUE}==> Creating Session Switching Helper...${C_NC}" echo -e "${C_BLUE}==> Creating Session Switching Helper...${C_NC}"
mkdir -p "$(dirname "$SWITCH_SCRIPT_PATH")" mkdir -p "$(dirname "$SWITCH_SCRIPT_PATH")"
cat > "$SWITCH_SCRIPT_PATH" <<'EOSWITCH' cat > "$SWITCH_SCRIPT_PATH" <<'EOSWITCH'
#!/bin/bash #!/bin/bash
# Set environment variables for Wofi to work properly
export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-1}" export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-1}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
# Create Wofi config directory if it doesn't exist choice=$(printf "🎮 SteamOS" | walker --dmenu \
mkdir -p "$HOME/.config/wofi" --placeholder "Switch Mode:" \
# --width 400 \
# Create custom Wofi stylesheet for SteamOS appearance # --height 250 \
cat > "$HOME/.config/wofi/style.css" <<'EOSTYLE' # --cache-file /dev/null \
window { # --style "$HOME/.config/wofi/style.css" \
background-color: rgba(30, 30, 46, 0.85); # --hide-scroll \
border: 1px solid rgba(60, 125, 210, 0.5); # --no-actions \
border-radius: 16px; # --lines 2)
font-family: "Noto Sans", sans-serif; )
font-size: 18px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
min-height: 250px;
}
#input {
background-color: rgba(42, 42, 62, 0.6);
border: 1px solid rgba(60, 125, 210, 0.3);
border-radius: 8px;
color: #cdd6f4;
font-size: 16px;
margin: 12px;
padding: 12px 16px;
}
#inner-box { background-color: transparent; margin: 8px; min-height: 150px; }
#outer-box { background-color: rgba(255, 255, 255, 0.02); border-radius: 12px; margin: 4px; padding: 8px; }
#scroll { background-color: transparent; min-height: 120px; }
#text { color: rgba(205, 214, 244, 0.95); padding: 12px 16px; font-weight: 500; font-size: 18px; }
#entry {
background-color: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
margin: 8px 12px;
padding: 12px;
min-height: 48px;
transition: all 0.2s ease;
}
#entry:hover { background-color: rgba(255, 255, 255, 0.08); border-color: rgba(60, 125, 210, 0.4); transform: translateX(4px); }
#entry:selected {
background: linear-gradient(135deg, rgba(60, 125, 210, 0.8) 0%, rgba(37, 99, 235, 0.8) 100%);
border: 1px solid rgba(60, 125, 210, 0.6);
}
#entry:selected #text { color: #ffffff; font-weight: 600; }
EOSTYLE
# Show session switcher with Wofi
choice=$(printf "🎮 SteamOS" | wofi --dmenu \
--prompt "Switch Mode:" \
--width 400 \
--height 250 \
--cache-file /dev/null \
--style "$HOME/.config/wofi/style.css" \
--hide-scroll \
--no-actions \
--lines 2)
case "$choice" in case "$choice" in
"🎮 SteamOS") "🎮 SteamOS")
# --- FIX: RESET SCREEN COLOR ---
notify-send "Session Switcher" "Disabling Night Light..." -t 1000
pkill hyprsunset
pkill wlsunset
pkill gammastep
sleep 1 # Give GPU time to reset gamma
# -------------------------------
# Validate we can write the session file # Validate we can write the session file
if echo "gamescope-session-steam.desktop" > "$HOME/.next-session" 2>/dev/null; then if echo "gamescope-session-steam.desktop" > "$HOME/.next-session" 2>/dev/null; then
notify-send "Session Switcher" "Switching to SteamOS..." -t 2000 notify-send "Session Switcher" "Switching to SteamOS..." -t 2000
echo "Session file written successfully" echo "Session file written successfully"
pkill hyprsunset
sleep 1
else else
notify-send "Session Switcher" "Error: Failed to write session file" -t 3000 notify-send "Session Switcher" "Error: Failed to write session file" -t 3000
echo "Error: Cannot write to $HOME/.next-session" echo "Error: Cannot write to $HOME/.next-session"
@@ -328,33 +258,62 @@ cleanup_session() {
# Detect current session more reliably # Detect current session more reliably
if pgrep -x "gamescope" > /dev/null || pgrep -f "gamescope-session" > /dev/null; then if pgrep -x "gamescope" > /dev/null || pgrep -f "gamescope-session" > /dev/null; then
echo "Detected Gamescope session, shutting down..." echo "Detected Gamescope session, shutting down..."
# Try graceful shutdown first
systemctl --user stop gamescope-session-plus@steam 2>/dev/null || true systemctl --user stop gamescope-session-plus@steam 2>/dev/null || true
sleep 1 sleep 1
# Force kill if still running
if pgrep -x "gamescope" > /dev/null; then if pgrep -x "gamescope" > /dev/null; then
pkill -TERM gamescope pkill -TERM gamescope
sleep 0.5 sleep 0.5
pkill -KILL gamescope 2>/dev/null || true pkill -KILL gamescope 2>/dev/null || true
fi fi
# Wait for processes to fully exit
while pgrep -x "gamescope" > /dev/null && [ $wait_count -lt $max_wait ]; do
sleep 1
((wait_count++))
done
elif [ -n "$HYPRLAND_INSTANCE_SIGNATURE" ] || pgrep -x "Hyprland" > /dev/null; then elif [ -n "$HYPRLAND_INSTANCE_SIGNATURE" ] || pgrep -x "Hyprland" > /dev/null; then
echo "Detected Hyprland session, shutting down..." echo "Detected Hyprland session, shutting down..."
# Try hyprctl first if available
if command -v hyprctl &> /dev/null && [ -n "$HYPRLAND_INSTANCE_SIGNATURE" ]; then if command -v hyprctl &> /dev/null && [ -n "$HYPRLAND_INSTANCE_SIGNATURE" ]; then
hyprctl dispatch exit 2>/dev/null || true hyprctl dispatch exit 2>/dev/null || true
else else
# Fallback to pkill
pkill -TERM Hyprland 2>/dev/null || true pkill -TERM Hyprland 2>/dev/null || true
fi fi
sleep 1 sleep 1
# Force kill if still running
if pgrep -x "Hyprland" > /dev/null; then if pgrep -x "Hyprland" > /dev/null; then
pkill -KILL Hyprland 2>/dev/null || true pkill -KILL Hyprland 2>/dev/null || true
fi fi
# Wait for processes to fully exit
while pgrep -x "Hyprland" > /dev/null && [ $wait_count -lt $max_wait ]; do
sleep 1
((wait_count++))
done
else else
echo "No specific session detected, attempting general cleanup..."
# Fallback cleanup
pkill -u $USER Hyprland 2>/dev/null || true pkill -u $USER Hyprland 2>/dev/null || true
pkill -u $USER gamescope 2>/dev/null || true pkill -u $USER gamescope 2>/dev/null || true
systemctl --user stop gamescope-session-plus@steam 2>/dev/null || true systemctl --user stop gamescope-session-plus@steam 2>/dev/null || true
sleep 1 sleep 1
fi fi
# Clean up any remaining compositor processes
pkill -u $USER -f "gamescope-session" 2>/dev/null || true pkill -u $USER -f "gamescope-session" 2>/dev/null || true
pkill -u $USER -f "steam" 2>/dev/null || true pkill -u $USER -f "steam" 2>/dev/null || true
# Give time for cleanup
sleep 0.5 sleep 0.5
} }
@@ -394,7 +353,7 @@ echo -e "${C_GREEN}Added SUPER+F12 keybinding to $HYPR_CONF${C_NC}"
echo -e "${C_GREEN}✅ Setup Complete! ✅${C_NC}\n" echo -e "${C_GREEN}✅ Setup Complete! ✅${C_NC}\n"
echo -e "${C_YELLOW}Important Fixes Applied:${C_NC}" echo -e "${C_YELLOW}Important Fixes Applied:${C_NC}"
echo "1. REMOVED 'lib32-networkmanager' (Using 64-bit standard package)." echo "1. REPLACED 'wofi' with 'walker'."
echo "2. CONFIGURED NetworkManager to use 'iwd' backend." echo "2. CONFIGURED NetworkManager to use 'iwd' backend."
echo "3. UPDATED '.xsession' to use an infinite loop (prevents logout)." echo "3. UPDATED '.xsession' to use an infinite loop (prevents logout)."
echo "4. CREATED '~/.config/environment.d/gamescope-session-plus.conf' to force DP-1." echo "4. CREATED '~/.config/environment.d/gamescope-session-plus.conf' to force DP-1."