#!/usr/bin/env bash set -euo pipefail repo_path=${LUMBRIDGE_REPO:-/home/metal/Desktop/Lumbridge Code/lumbridge} window_title='Lumbridge · GPUI workspace' bacon_title='Lumbridge · Bacon' manifest_path="$repo_path/Cargo.toml" binary_path="$repo_path/target/debug/lumbridge" if [[ ! -d "$repo_path/.git" ]]; then echo "Lumbridge repository not found at $repo_path" >&2 exit 1 fi export DISPLAY=${DISPLAY:-:0} export XAUTHORITY=${XAUTHORITY:-/run/user/1000/gdm/Xauthority} export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/1000} export DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/1000/bus} for command_name in wmctrl xdotool; do if ! command -v "$command_name" >/dev/null 2>&1; then echo "required command not found: $command_name" >&2 exit 1 fi done if [[ ! -x "$binary_path" ]]; then if ! command -v cargo >/dev/null 2>&1; then # Non-login Tailscale SSH commands do not inherit metal's Cargo PATH. # shellcheck source=/dev/null source /home/metal/.cargo/env fi if ! command -v cargo >/dev/null 2>&1; then echo "required command not found: cargo" >&2 exit 1 fi # shellcheck source=/dev/null source "$repo_path/scripts/native-libs.sh" cargo build --locked --manifest-path "$manifest_path" -p lumbridge fi # GPUI's X11 client sets WM_NAME but not _NET_WM_NAME, so wmctrl's window list # reports its title as N/A and a title match never succeeds. xdotool reads # WM_NAME, and matching the launched PID avoids picking up another client that # merely mentions the window title. window_for_pid() { local pid=$1 candidate for candidate in $(xdotool search --name 'GPUI workspace' 2>/dev/null); do if [[ "$(xdotool getwindowpid "$candidate" 2>/dev/null || true)" == "$pid" ]]; then printf '%s\n' "$candidate" return 0 fi done return 1 } existing_id='' app_pid=$(pgrep -f "^$binary_path$" | head -n 1 || true) if [[ -n "$app_pid" ]]; then existing_id=$(window_for_pid "$app_pid" || true) fi if [[ -z "$existing_id" ]]; then "$binary_path" >"$XDG_RUNTIME_DIR/lumbridge-gpui.log" 2>&1 & app_pid=$! for _attempt in $(seq 1 80); do existing_id=$(window_for_pid "$app_pid" || true) [[ -n "$existing_id" ]] && break sleep 0.1 done fi if [[ -z "$existing_id" ]]; then echo "Lumbridge window did not become visible; see $XDG_RUNTIME_DIR/lumbridge-gpui.log" >&2 exit 1 fi # Gigabyte G34WQC is 3440x1440 at X=0. Lumbridge owns the whole panel: the # workspace is a wall of agents and every pixel of width buys another column. # Set LUMBRIDGE_HALF=1 to fall back to the left half beside Bacon. if [[ "${LUMBRIDGE_HALF:-0}" == "1" ]]; then bacon_id=$(wmctrl -l | awk -v title="$bacon_title" 'index($0, title) { print $1; exit }') if [[ -n "$bacon_id" ]]; then wmctrl -i -r "$bacon_id" -b remove,maximized_vert,maximized_horz # GNOME's X11 move coordinate is scaled on this display even though window # sizes are not; 860 places the frame at physical X=1720. wmctrl -i -r "$bacon_id" -e 0,860,0,1720,1400 fi wmctrl -i -r "$existing_id" -b remove,fullscreen wmctrl -i -r "$existing_id" -b remove,maximized_vert,maximized_horz wmctrl -i -r "$existing_id" -e 0,0,0,1720,1400 wmctrl -i -a "$existing_id" # GPUI's undecorated X11 client ignores direct position requests under GNOME. # Use the window manager's move interaction to settle it into the left half. xdotool key alt+F7 sleep 0.15 xdotool mousemove 860 660 click 1 echo "Lumbridge is on the left half of the Gigabyte display (window $existing_id)." exit 0 fi # Fullscreen drops the title bar and the shell owns all 3440x1440. Move it onto # the Gigabyte first: a fullscreen request applies to whichever output the # window is currently on, so placing it after would fullscreen the wrong panel. wmctrl -i -r "$existing_id" -b remove,fullscreen wmctrl -i -r "$existing_id" -b remove,maximized_vert,maximized_horz wmctrl -i -r "$existing_id" -e 0,0,0,1720,1400 wmctrl -i -a "$existing_id" xdotool key alt+F7 sleep 0.15 xdotool mousemove 860 660 click 1 sleep 0.2 wmctrl -i -r "$existing_id" -b add,fullscreen sleep 0.3 geometry=$(xdotool getwindowgeometry "$existing_id" | awk '/Geometry/ { print $2 }') echo "Lumbridge is fullscreen on the Gigabyte display at ${geometry} (window $existing_id)."