Bash · 2909 bytes Raw Blame History
1 #!/bin/bash
2 # gar session wrapper - sets up environment before starting gar
3 # This script is typically installed to /usr/local/share/gar/gar-session.sh
4
5 # Find gar binary - check common locations
6 GAR_BIN="${GAR_BIN:-}"
7 if [ -z "$GAR_BIN" ]; then
8 for path in /usr/local/bin/gar /usr/bin/gar "$HOME/.local/bin/gar"; do
9 if [ -x "$path" ]; then
10 GAR_BIN="$path"
11 break
12 fi
13 done
14 fi
15
16 # Fallback to PATH lookup
17 if [ -z "$GAR_BIN" ] || [ ! -x "$GAR_BIN" ]; then
18 GAR_BIN="$(command -v gar 2>/dev/null || true)"
19 fi
20
21 if [ -z "$GAR_BIN" ] || [ ! -x "$GAR_BIN" ]; then
22 echo "ERROR: gar binary not found. Please ensure gar is installed." >&2
23 exit 1
24 fi
25
26 # Optional: configure monitor layout
27 # Uncomment and customize for your setup:
28 # xrandr --output eDP-1 --mode 2880x1800 --pos 0x0
29 # xrandr --output DP-1 --mode 1920x1080 --pos 0x0 \
30 # --output HDMI-1 --mode 2560x1440 --pos 1920x0
31
32 # Ensure gar config directory exists
33 mkdir -p ~/.config/gar
34
35 # ═══════════════════════════════════════════════════════════════════
36 # SYSTEMD SESSION SETUP - Required for user services like garbg
37 # Pattern from sway-systemd, i3-session, and ArchWiki systemd/User
38 # ═══════════════════════════════════════════════════════════════════
39
40 # Import DISPLAY and XAUTHORITY to systemd user session
41 # This allows user services to connect to X11
42 systemctl --user import-environment DISPLAY XAUTHORITY
43
44 # Also update D-Bus activation environment (for D-Bus services)
45 if command -v dbus-update-activation-environment &> /dev/null; then
46 dbus-update-activation-environment DISPLAY XAUTHORITY
47 fi
48
49 # Start gar-session.target - this binds to graphical-session.target
50 # (graphical-session.target has RefuseManualStart=yes, so we use our own target)
51 systemctl --user start gar-session.target
52
53 # ═══════════════════════════════════════════════════════════════════
54
55 # Launch compositor before WM (for proper screen repainting)
56 # gar generates picom.conf on startup and signals picom to reload
57 if command -v picom &> /dev/null; then
58 if [[ -f ~/.config/gar/picom.conf ]]; then
59 picom -b --config ~/.config/gar/picom.conf &
60 else
61 # First run: start with GLX backend, gar will generate config and signal reload
62 picom -b --backend glx &
63 fi
64 sleep 0.1
65 fi
66
67 # Set log level
68 export GAR_LOG=info
69
70 # garbar is now launched natively by gar when gar.bar is configured in init.lua
71 # (Legacy polybar launch removed - use gar.bar config instead)
72
73 # Start gar
74 exec "$GAR_BIN"