diff --git a/bin/omarchy-shell b/bin/omarchy-shell index 93312327..5bd615a8 100755 --- a/bin/omarchy-shell +++ b/bin/omarchy-shell @@ -40,6 +40,13 @@ fi [[ -n ${OMARCHY_PATH:-} ]] || fail "OMARCHY_PATH is not set" [[ -f $OMARCHY_PATH/shell/shell.qml ]] || fail "omarchy-shell config not found: $OMARCHY_PATH/shell/shell.qml" +# qs matches instances by display, and tmux run-shell strips WAYLAND_DISPLAY +# from hooks, so recover it from the compositor socket when it is missing. +if [[ -z ${WAYLAND_DISPLAY:-} ]]; then + socket=$(ls -t "${XDG_RUNTIME_DIR:-/run/user/$UID}"/wayland-[0-9]* 2>/dev/null | grep -v '\.lock$' | head -n1) + [[ -n $socket ]] && export WAYLAND_DISPLAY=${socket##*/} +fi + if [[ $1 == "shell" && ( $2 == "summon" || $2 == "toggle" ) ]] && (( $# == 3 )); then set -- "$1" "$2" "$3" "{}" fi diff --git a/test/shell.d/shell-ipc-display-test.sh b/test/shell.d/shell-ipc-display-test.sh new file mode 100755 index 00000000..57327a75 --- /dev/null +++ b/test/shell.d/shell-ipc-display-test.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -euo pipefail + +source "$(dirname "$0")/base-test.sh" + +test_dir=$(mktemp -d) +trap 'rm -rf "$test_dir"' EXIT + +mkdir -p "$test_dir/bin" "$test_dir/run" +touch "$test_dir/run/wayland-1" "$test_dir/run/wayland-1.lock" + +cat >"$test_dir/bin/qs" <<'STUB' +#!/bin/bash +echo "display=[$WAYLAND_DISPLAY]" +STUB +chmod +x "$test_dir/bin/qs" + +export PATH="$test_dir/bin:$PATH" +export OMARCHY_PATH="$ROOT" +export XDG_RUNTIME_DIR="$test_dir/run" + +# tmux hooks run without WAYLAND_DISPLAY, and qs matches instances by display. +output=$(env -u WAYLAND_DISPLAY "$ROOT/bin/omarchy-shell" omarchy.indicators refresh) +[[ $output == "display=[wayland-1]" ]] || fail "shell ipc recovers a missing display" "$output" +pass "shell ipc recovers a missing display" + +output=$(WAYLAND_DISPLAY=wayland-9 "$ROOT/bin/omarchy-shell" omarchy.indicators refresh) +[[ $output == "display=[wayland-9]" ]] || fail "shell ipc keeps an existing display" "$output" +pass "shell ipc keeps an existing display"