Compare commits

...

4 Commits

Author SHA1 Message Date
kenji 47ccb71a0d steam-session: added more opt
unfixed
2025-12-03 15:05:14 -06:00
kenji d8dc2ec1b8 steam-session: fixed binding 2025-12-01 22:05:22 -06:00
kenji c2faf2cda8 bind: fixed formatting 2025-12-01 22:05:11 -06:00
kenji 0fa579f28b bind: minor fix 2025-12-01 21:51:56 -06:00
3 changed files with 131 additions and 53 deletions
+2 -1
View File
@@ -62,5 +62,6 @@ bindd = SUPER SHIFT, F, File manager, exec, uwsm-app -- yazi
# Web App URL # Web App URL
# Session Switcher Keybinding # Session Switcher Keybinding
bindd = SUPER, F12, Switch to SteamOS, exec, ~/.local/bin/switch-session.sh bindd = SUPER, F12, Switch to SteamOS, exec, /home/kenji/.local/bin/switch-session.sh
-5
View File
@@ -46,8 +46,3 @@ env = XDG_MENU_PREFIX, plasma-
# env = WLR_DRM_NO_ATOMIC, 1 # env = WLR_DRM_NO_ATOMIC, 1
# ? # ?
# env = WLR_NO_HARDWARE_CURSORS, 1 # env = WLR_NO_HARDWARE_CURSORS, 1
# Session Switcher Keybinding
bind = SUPER, F12, exec, /home/kenji/.local/bin/switch-session.sh
+129 -47
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: Clean Config, User Inputs for HDR/VRR
# #
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}"
@@ -32,15 +32,54 @@ 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 -e "\n${C_YELLOW}Monitor Configuration:${C_NC}"
echo "Enter your Refresh Rate (e.g., 60, 144, 165). Leave empty for auto:"
# 1. Output Port
echo "Enter your Output Connector (default: DP-1):"
read USER_OUTPUT
USER_OUTPUT=${USER_OUTPUT:-DP-1}
# 2. Width
echo "Enter Screen Width (default: 3440):"
read USER_WIDTH
USER_WIDTH=${USER_WIDTH:-3440}
# 3. Height
echo "Enter Screen Height (default: 1440):"
read USER_HEIGHT
USER_HEIGHT=${USER_HEIGHT:-1440}
# 4. Refresh Rate
echo "Enter Refresh Rate (default: 180):"
read USER_REFRESH read USER_REFRESH
REFRESH_ARG="" USER_REFRESH=${USER_REFRESH:-180}
if [ -n "$USER_REFRESH" ]; then
REFRESH_ARG="-r $USER_REFRESH" # 5. VRR (Adaptive Sync)
echo "Enable VRR / Adaptive Sync? [Y/n] (Default: Yes)"
read USER_VRR
if [[ "$USER_VRR" =~ ^[Nn]$ ]]; then
VRR_FLAG=""
echo -e "-> VRR Disabled"
else
VRR_FLAG="--adaptive-sync"
echo -e "-> VRR Enabled"
fi fi
# 6. HDR
echo "Enable HDR? [Y/n] (Default: Yes)"
read USER_HDR
if [[ "$USER_HDR" =~ ^[Nn]$ ]]; then
HDR_FLAG=""
echo -e "-> HDR Disabled"
else
HDR_FLAG="--hdr-enabled"
echo -e "-> HDR Enabled"
fi
echo -e "${C_GREEN}Configured: ${USER_OUTPUT} @ ${USER_WIDTH}x${USER_HEIGHT} (${USER_REFRESH}Hz)${C_NC}\n"
# --- 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"
@@ -49,7 +88,7 @@ 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"
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" "walker" )
#======================================================= #=======================================================
# STEP 1: DEPENDENCY INSTALLATION # STEP 1: DEPENDENCY INSTALLATION
@@ -82,24 +121,62 @@ EOF
systemctl --user daemon-reload systemctl --user daemon-reload
#======================================================= #=======================================================
# STEP 4: CONFIGURE GAMESCOPE ENVIRONMENT # STEP 3.5: GRANT REAL-TIME PRIORITY CAPABILITIES
#======================================================= #=======================================================
echo -e "${C_BLUE}==> Configuring Gamescope Monitor Settings (DP-1)...${C_NC}" echo -e "${C_BLUE}==> Granting CAP_SYS_NICE to Gamescope...${C_NC}"
echo "Writing to: $GS_ENV_FILE" # This allows gamescope to use --rt (realtime) scheduling without root
GAME_BIN=$(which gamescope)
if [ -f "$GAME_BIN" ]; then
sudo setcap 'CAP_SYS_NICE=eip' "$GAME_BIN"
echo -e "${C_GREEN}Capability set on $GAME_BIN${C_NC}"
else
echo -e "${C_RED}Error: Gamescope binary not found!${C_NC}"
fi
#=======================================================
# STEP 4: CONFIGURE GAMESCOPE ENVIRONMENT (CLEAN)
#=======================================================
echo -e "${C_BLUE}==> Configuring Gamescope Command...${C_NC}"
if [ -f "$GS_ENV_DIR" ]; then 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"
# NOTE: We do NOT use quotes around EOF here.
# This allows the variables ($USER_OUTPUT, $VRR_FLAG, etc.) to expanded
# RIGHT NOW, so the resulting file contains only hardcoded values.
cat > "$GS_ENV_FILE" <<EOF cat > "$GS_ENV_FILE" <<EOF
# Force Output to DP-1 # --- GAMESCOPE CONFIGURATION ---
OUTPUT_CONNECTOR=DP-1 # Generated by setup script on $(date)
#
# Flags Explanation:
# -O : Output Connector
# -r : Refresh Rate
# -W/-H : Resolution the Game sees
# -w/-h : Resolution sent to Monitor
# -e : Steam Integration
# -f : Force Fullscreen
# --xwayland-count 2 : Vital for Steam Deck UI + Game
# --immediate-flips : Low latency mode
# --rt : Real-time priority
# Enable VRR (Disable if you still feel stuttering) GAMESCOPECMD="/usr/bin/gamescope \\
ADAPTIVE_SYNC=1 -O $USER_OUTPUT \\
-r $USER_REFRESH \\
# Force specific arguments for gamescope-session-plus -W $USER_WIDTH -H $USER_HEIGHT \\
# -O: Output -w $USER_WIDTH -h $USER_HEIGHT \\
# -r: Refresh Rate (Crucial for smoothness) $VRR_FLAG \\
# --steam -e: Steam Integration $HDR_FLAG \\
GAMESCOPE_ARGS="-O DP-1 $REFRESH_ARG --steam -e" --immediate-flips \\
--rt \\
-e \\
--mangoapp \\
--xwayland-count 2 \\
--default-touch-mode 4 \\
--hide-cursor-delay 3000 \\
--fade-out-duration 200"
EOF EOF
#======================================================= #=======================================================
@@ -142,7 +219,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 +227,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 +248,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,48 +256,50 @@ 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 ---
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 # Use the constructed variable from the conf file
export GAMESCOPECMD="/usr/bin/gamescope ${GAMESCOPE_ARGS:-"-O DP-1 --steam -e"}" echo "Executing Command: $GAMESCOPECMD"
export OUTPUT_CONNECTOR="${OUTPUT_CONNECTOR:-"DP-1"}"
# --- STUTTER FIX: SYSTEMD-RUN --- # Strip the leading binary path to get just the args
# We wrap the command in systemd-run to give it Real-Time Priority # We strip "/usr/bin/gamescope" OR just "gamescope" to be safe
# This mimics how a real Service would run it, eliminating scheduling latency. ARGS=$(echo "$GAMESCOPECMD" | sed 's|^/usr/bin/gamescope ||' | sed 's|^gamescope ||')
systemd-run --user --scope \
--property=Nice=-20 \ gamescope-session-plus steam -- $ARGS
--property=Slice=app.slice \
--unit=gamescope-session-manual \
gamescope-session-plus steam -- -O DP-1
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
@@ -303,12 +386,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 +399,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"