Bash · 3238 bytes Raw Blame History
1 #!/usr/bin/env bash
2 # Start gar window manager on a real X session
3 #
4 # IMPORTANT: Run this from a TTY, not from Hyprland!
5 # 1. Press Ctrl+Alt+F2 to switch to TTY2
6 # 2. Login
7 # 3. Run: ~/GithubOrgs/tenseleyFlow/gar/start-gar.sh
8 #
9 # PANIC MODE: Super+Shift+Escape to exit gar immediately
10 # BACKUP: Ctrl+Alt+F3 to switch to another TTY if gar freezes
11 #
12 # To return to Hyprland after exiting:
13 # Press Ctrl+Alt+F1 (or wherever SDDM is running)
14
15 set -e
16
17 GAR_DIR="$(cd "$(dirname "$0")" && pwd)"
18 GAR_BIN="$GAR_DIR/target/release/gar"
19
20 # Check if gar is built
21 if [[ ! -x "$GAR_BIN" ]]; then
22 echo "Error: gar not found at $GAR_BIN"
23 echo "Run: nix-shell --run 'cargo build --release'"
24 exit 1
25 fi
26
27 # Check if running from a TTY
28 if [[ -z "$XDG_SESSION_TYPE" ]] || [[ "$XDG_SESSION_TYPE" == "tty" ]]; then
29 echo "Good: Running from TTY"
30 else
31 echo "WARNING: You appear to be running from a graphical session."
32 echo "For best results, switch to a TTY first (Ctrl+Alt+F2)"
33 echo ""
34 read -p "Continue anyway? [y/N] " -n 1 -r
35 echo
36 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
37 exit 1
38 fi
39 fi
40
41 # Find an available display
42 for i in 1 2 3 4 5; do
43 if [[ ! -e "/tmp/.X$i-lock" ]]; then
44 DISPLAY_NUM=":$i"
45 break
46 fi
47 done
48
49 if [[ -z "$DISPLAY_NUM" ]]; then
50 echo "Error: No available display found"
51 exit 1
52 fi
53
54 # Detect current VT
55 CURRENT_VT=$(tty | grep -o 'tty[0-9]*' | grep -o '[0-9]*' || echo "")
56 if [[ -z "$CURRENT_VT" ]]; then
57 CURRENT_VT=7
58 fi
59
60 echo "========================================"
61 echo " Starting gar window manager"
62 echo "========================================"
63 echo ""
64 echo " PANIC MODE: Super+Shift+Escape"
65 echo " TTY ESCAPE: Ctrl+Alt+F$((CURRENT_VT == 2 ? 3 : 2))"
66 echo ""
67 echo " Display: $DISPLAY_NUM"
68 echo " VT: $CURRENT_VT"
69 echo "========================================"
70 echo ""
71
72 # Create xinitrc for gar
73 XINITRC=$(mktemp)
74 cat > "$XINITRC" << EOF
75 #!/bin/sh
76 # Set up environment
77 export GAR_LOG=info
78
79 # Configure monitor layout: 1080p -> 1440p -> 4k (left to right)
80 # Wait a moment for X to fully initialize
81 sleep 0.5
82 xrandr \\
83 --output DP-1 --mode 1920x1080 --pos 0x0 \\
84 --output HDMI-1 --mode 2560x1440 --pos 1920x0 \\
85 --output HDMI-0 --mode 3840x2160 --pos 4480x0
86
87 # Ensure gar config directory exists
88 mkdir -p ~/.config/gar
89
90 # Launch compositor before WM (for proper screen repainting)
91 # gar generates picom.conf on startup and signals picom to reload
92 if command -v picom > /dev/null 2>&1; then
93 if [[ -f ~/.config/gar/picom.conf ]]; then
94 picom -b --config ~/.config/gar/picom.conf &
95 else
96 # First run: start with GLX backend, gar will generate config and signal reload
97 picom -b --backend glx &
98 fi
99 sleep 0.1
100 fi
101
102 # Start gar
103 exec $GAR_BIN
104 EOF
105 chmod +x "$XINITRC"
106
107 # Trap to clean up
108 cleanup() {
109 rm -f "$XINITRC"
110 echo ""
111 echo "gar exited. Press Ctrl+Alt+F1 to return to SDDM/Hyprland."
112 }
113 trap cleanup EXIT
114
115 # Start X with gar
116 echo "Starting X server with gar..."
117 echo "Press Ctrl+C here or Super+Shift+Escape in gar to exit"
118 echo ""
119
120 # Use xinit directly - show all output for debugging
121 # -keeptty is required for systemd-logind integration
122 xinit "$XINITRC" -- "$DISPLAY_NUM" "vt$CURRENT_VT" -keeptty