cleaned up and removed environment.d

This commit is contained in:
kenji
2025-12-01 21:40:10 -06:00
parent e31f67e53e
commit 638e26e026
3 changed files with 60 additions and 109 deletions
@@ -1,7 +0,0 @@
# FIXME: "It works on my machine!" Look at ChorinOS/gamescope-session github for more config info
# Force Output
OUTPUT_CONNECTOR="DP-1"
# Enable VRR
ADAPTIVE_SYNC=1
+2
View File
@@ -47,5 +47,7 @@ env = XDG_MENU_PREFIX, plasma-
# ? # ?
# env = WLR_NO_HARDWARE_CURSORS, 1 # env = WLR_NO_HARDWARE_CURSORS, 1
# Session Switcher Keybinding # Session Switcher Keybinding
bind = SUPER, F12, exec, /home/kenji/.local/bin/switch-session.sh bind = SUPER, F12, exec, /home/kenji/.local/bin/switch-session.sh
+58 -102
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: Walker, Infinite Loop, env.d Config, Color Reset, IWD Backend # Updated: High Priority Scheduling (Fixes Stutter), Walker, Configurable Refresh Rate
# #
set -e set -e
@@ -26,11 +26,19 @@ echo -e "${C_BLUE}==============================================================
echo -e "${C_BLUE} Hyprland <-> Gamescope Session Switcher Setup for: ${C_YELLOW}$USER_NAME${C_NC}" echo -e "${C_BLUE} Hyprland <-> Gamescope Session Switcher Setup for: ${C_YELLOW}$USER_NAME${C_NC}"
echo -e "${C_BLUE}===================================================================${C_NC}\n" echo -e "${C_BLUE}===================================================================${C_NC}\n"
# --- USER CHOICE FOR AUTOLOGIN --- # --- USER INPUTS ---
echo -e "${C_YELLOW}Configuration Choice:${C_NC}" echo -e "${C_YELLOW}Configuration Choice:${C_NC}"
echo "Do you want to enable automatic login? [y/N]: " echo "Do you want to enable automatic login? [y/N]: "
read AUTOLOGIN_CHOICE read AUTOLOGIN_CHOICE
echo -e "\n${C_YELLOW}Monitor Configuration:${C_NC}"
echo "Enter your Refresh Rate (e.g., 60, 144, 165). Leave empty for auto:"
read USER_REFRESH
REFRESH_ARG=""
if [ -n "$USER_REFRESH" ]; then
REFRESH_ARG="-r $USER_REFRESH"
fi
# --- Script Variables --- # --- Script Variables ---
HYPR_CONF="$USER_HOME/.config/hypr/hyprland.conf" HYPR_CONF="$USER_HOME/.config/hypr/hyprland.conf"
SWITCH_SCRIPT_PATH="$USER_HOME/.local/bin/switch-session.sh" SWITCH_SCRIPT_PATH="$USER_HOME/.local/bin/switch-session.sh"
@@ -40,7 +48,6 @@ SERVICE_OVERRIDE_FILE="$SERVICE_OVERRIDE_DIR/override.conf"
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 wofi, added walker to AUR packages
OFFICIAL_PACKAGES=( "hyprland" "sddm" "uwsm" "networkmanager" ) OFFICIAL_PACKAGES=( "hyprland" "sddm" "uwsm" "networkmanager" )
AUR_PACKAGES=( "gamescope-git" "gamescope-session-git" "steam" "gamescope-session-steam-git" "mangohud" "walker" ) AUR_PACKAGES=( "gamescope-git" "gamescope-session-git" "steam" "gamescope-session-steam-git" "mangohud" "walker" )
@@ -75,30 +82,35 @@ EOF
systemctl --user daemon-reload systemctl --user daemon-reload
#======================================================= #=======================================================
# STEP 4: CONFIGURE GAMESCOPE ENVIRONMENT (MONITOR FIX) # 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" echo "Writing to: $GS_ENV_FILE"
mkdir -p "$GS_ENV_DIR" mkdir -p "$GS_ENV_DIR"
# We inject the Refresh Rate here
cat > "$GS_ENV_FILE" <<EOF cat > "$GS_ENV_FILE" <<EOF
# Force Output to DP-1 (Fixes display issue) # Force Output to DP-1
OUTPUT_CONNECTOR=DP-1 OUTPUT_CONNECTOR=DP-1
# Enable VRR (Disable if you still feel stuttering)
ADAPTIVE_SYNC=1
# Force specific arguments for gamescope-session-plus # Force specific arguments for gamescope-session-plus
GAMESCOPE_ARGS="-O DP-1 --steam -e" # -O: Output
# -r: Refresh Rate (Crucial for smoothness)
# --steam -e: Steam Integration
GAMESCOPE_ARGS="-O DP-1 $REFRESH_ARG --steam -e"
EOF EOF
#======================================================= #=======================================================
# STEP 5: CONFIGURE NETWORK MANAGER (IWD BACKEND) # STEP 5: CONFIGURE NETWORK MANAGER (IWD BACKEND)
#======================================================= #=======================================================
echo -e "${C_BLUE}==> Configuring NetworkManager for SteamOS compatibility...${C_NC}" echo -e "${C_BLUE}==> Configuring NetworkManager for SteamOS compatibility...${C_NC}"
# Create config to use iwd backend (prevents conflicts)
sudo mkdir -p /etc/NetworkManager/conf.d sudo mkdir -p /etc/NetworkManager/conf.d
sudo tee /etc/NetworkManager/conf.d/wifi_backend.conf > /dev/null <<EOF sudo tee /etc/NetworkManager/conf.d/wifi_backend.conf > /dev/null <<EOF
[device] [device]
wifi.backend=iwd wifi.backend=iwd
EOF EOF
echo "Enabling NetworkManager..." echo "Enabling NetworkManager..."
sudo systemctl enable NetworkManager sudo systemctl enable NetworkManager
@@ -107,7 +119,6 @@ sudo systemctl enable NetworkManager
#======================================================= #=======================================================
echo -e "${C_BLUE}==> Installing Session Switching Workflow...${C_NC}" echo -e "${C_BLUE}==> Installing Session Switching Workflow...${C_NC}"
# --- SDDM AUTOLOGIN (CONDITIONAL) ---
if [[ "$AUTOLOGIN_CHOICE" =~ ^[Yy]$ ]]; then if [[ "$AUTOLOGIN_CHOICE" =~ ^[Yy]$ ]]; then
echo "--> Configuring SDDM for autologin..." echo "--> Configuring SDDM for autologin..."
sudo tee /etc/sddm.conf > /dev/null <<EOF sudo tee /etc/sddm.conf > /dev/null <<EOF
@@ -121,7 +132,6 @@ else
AUTOLOGIN_ENABLED=false AUTOLOGIN_ENABLED=false
fi fi
# --- WAYLAND SESSION DESKTOP ENTRY ---
sudo tee /usr/share/wayland-sessions/switcher.desktop > /dev/null <<EOF sudo tee /usr/share/wayland-sessions/switcher.desktop > /dev/null <<EOF
[Desktop Entry] [Desktop Entry]
Name=Auto Session Switcher Name=Auto Session Switcher
@@ -132,7 +142,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)...${C_NC}" echo -e "${C_BLUE}==> Creating Session Launch Script (Infinite Loop + High Priority)...${C_NC}"
cat > "$XSESSION_PATH" <<'EOS' cat > "$XSESSION_PATH" <<'EOS'
#!/bin/bash #!/bin/bash
@@ -140,13 +150,10 @@ 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
@@ -161,7 +168,6 @@ 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"
@@ -169,39 +175,50 @@ while true; do
SESSION="hyprland" SESSION="hyprland"
fi fi
# 2. UPDATE ENVIRONMENT # Update DBus for systemd
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..." echo "Starting Gamescope session (High Priority)..."
# Check for the executable # Load environment config manually
if [ -f "$HOME/.config/environment.d/gamescope-session-plus.conf" ]; then
set -a
source "$HOME/.config/environment.d/gamescope-session-plus.conf"
set +a
fi
if command -v gamescope-session-plus &> /dev/null; then if command -v gamescope-session-plus &> /dev/null; then
# Run blocking, do not exec
export GAMESCOPECMD="/usr/bin/gamescope -O DP-1 --steam -e --" # EXPORT VARIABLES
gamescope-session-plus steam 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
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"
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
chmod +x "$XSESSION_PATH" chmod +x "$XSESSION_PATH"
@@ -212,34 +229,25 @@ 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
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)}"
choice=$(printf "🎮 SteamOS" | walker --dmenu \ # Walker in dmenu mode
--placeholder "Switch Mode:" \ choice=$(printf "🎮 SteamOS" | walker --dmenu --placeholder "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")
# Validate we can write the session file notify-send "Session Switcher" "Disabling Night Light..." -t 1000
pkill hyprsunset
pkill wlsunset
pkill gammastep
sleep 1
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"
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"
exit 1 exit 1
fi fi
;; ;;
@@ -249,75 +257,40 @@ case "$choice" in
;; ;;
esac esac
# Improved session cleanup with better reliability
cleanup_session() { cleanup_session() {
local max_wait=5 local max_wait=5
local wait_count=0 local wait_count=0
# 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
} }
# Execute cleanup
cleanup_session cleanup_session
EOSWITCH EOSWITCH
chmod +x "$SWITCH_SCRIPT_PATH" chmod +x "$SWITCH_SCRIPT_PATH"
@@ -326,14 +299,8 @@ chmod +x "$SWITCH_SCRIPT_PATH"
# STEP 9: CONFIGURE HYPRLAND KEYBINDING # STEP 9: CONFIGURE HYPRLAND KEYBINDING
#======================================================= #=======================================================
echo -e "${C_BLUE}==> Configuring Hyprland Keybinding...${C_NC}" echo -e "${C_BLUE}==> Configuring Hyprland Keybinding...${C_NC}"
# Create hyprland config directory if it doesn't exist
mkdir -p "$(dirname "$HYPR_CONF")" mkdir -p "$(dirname "$HYPR_CONF")"
if [ ! -f "$HYPR_CONF" ]; then echo "" > "$HYPR_CONF"; fi
if [ ! -f "$HYPR_CONF" ]; then
echo "# Hyprland Configuration" > "$HYPR_CONF"
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 '/bind = SUPER, F12, exec,.*switch-session.sh/d' "$HYPR_CONF"
@@ -346,23 +313,12 @@ 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}"
#======================================================= #=======================================================
# 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}Important Fixes Applied:${C_NC}" echo "1. Wrapped gamescope in 'systemd-run' with Nice=-20 (Real-time Priority)."
echo "1. REPLACED 'wofi' with 'walker'." echo "2. Configured Monitor Refresh Rate."
echo "2. CONFIGURED NetworkManager to use 'iwd' backend." echo "3. Switched to 'Walker' for menu selection."
echo "3. UPDATED '.xsession' to use an infinite loop (prevents logout)." echo -e "\n${C_YELLOW}A REBOOT IS REQUIRED.${C_NC}\n"
echo "4. CREATED '~/.config/environment.d/gamescope-session-plus.conf' to force DP-1."
echo "5. MODIFIED Switch script to kill 'hyprsunset' before switching."
echo -e "\n${C_YELLOW}A REBOOT IS REQUIRED to activate NetworkManager and the new Session structure.${C_NC}\n"
if [ "$AUTOLOGIN_ENABLED" = true ]; then
echo -e "-> Autologin is enabled. System will boot directly into Hyprland."
else
echo -e "-> Autologin is disabled. Choose 'Auto Session Switcher' at login."
fi