Fix notification focus for agent terminals (#6801)
* Fix notification focus for agent terminals * Restrict notification title fallback to agents * Simplify the focus fallback to a lazy two-tier query Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: David Heinemeier Hansson <david@hey.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
David Heinemeier Hansson
parent
14dc3a31d1
commit
82ae514609
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# omarchy:summary=Focus a Hyprland window by application class
|
# omarchy:summary=Focus a Hyprland window by application identity
|
||||||
# omarchy:args=<app-name>
|
# omarchy:args=<app-name>
|
||||||
# omarchy:examples=omarchy hyprland focus app Slack
|
# omarchy:examples=omarchy hyprland focus app Slack
|
||||||
|
|
||||||
@@ -12,10 +12,17 @@ usage() {
|
|||||||
app=${1:-}
|
app=${1:-}
|
||||||
[[ -n $app ]] || usage
|
[[ -n $app ]] || usage
|
||||||
|
|
||||||
|
# Agent terminals notify as kitty/foot/etc. while their shared window class is
|
||||||
|
# org.omarchy.agent, leaving the terminal name only in initialTitle. So match
|
||||||
|
# by class first, then fall back to the launch-time title of agent windows.
|
||||||
address=$(
|
address=$(
|
||||||
hyprctl clients -j 2>/dev/null |
|
hyprctl clients -j 2>/dev/null |
|
||||||
jq -r --arg pattern "$app" \
|
jq -r --arg pattern "$app" \
|
||||||
'[.[] | select((.class // "") | test($pattern; "i"))] | first.address // empty'
|
'def matches($value): ($value // "") | test($pattern; "i");
|
||||||
|
first(
|
||||||
|
(.[] | select(matches(.class))),
|
||||||
|
(.[] | select(.initialClass == "org.omarchy.agent" and matches(.initialTitle)))
|
||||||
|
).address // empty'
|
||||||
)
|
)
|
||||||
|
|
||||||
[[ -n $address ]] || exit 1
|
[[ -n $address ]] || exit 1
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ mkdir -p "$mock_bin"
|
|||||||
cat >"$mock_bin/hyprctl" <<'SH'
|
cat >"$mock_bin/hyprctl" <<'SH'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [[ $1 == "clients" ]]; then
|
if [[ $1 == "clients" ]]; then
|
||||||
printf '[{"address":"0xabc","class":"chromium"}]\n'
|
printf '%s\n' "$OMARCHY_TEST_CLIENTS_JSON"
|
||||||
elif [[ $1 == "dispatch" ]]; then
|
elif [[ $1 == "dispatch" ]]; then
|
||||||
printf '%s\n' "$2" >"$OMARCHY_TEST_FOCUS_DISPATCH"
|
printf '%s\n' "$2" >"$OMARCHY_TEST_FOCUS_DISPATCH"
|
||||||
fi
|
fi
|
||||||
@@ -21,10 +21,39 @@ SH
|
|||||||
chmod +x "$mock_bin/hyprctl"
|
chmod +x "$mock_bin/hyprctl"
|
||||||
|
|
||||||
dispatch_log="$test_tmp/dispatch"
|
dispatch_log="$test_tmp/dispatch"
|
||||||
PATH="$mock_bin:$PATH" OMARCHY_TEST_FOCUS_DISPATCH="$dispatch_log" \
|
clients_json='[{"address":"0xabc","class":"chromium"}]'
|
||||||
bash "$ROOT/bin/omarchy-hyprland-focus-app" chromium
|
PATH="$mock_bin:$PATH" OMARCHY_TEST_CLIENTS_JSON="$clients_json" \
|
||||||
|
OMARCHY_TEST_FOCUS_DISPATCH="$dispatch_log" \
|
||||||
|
bash "$ROOT/bin/omarchy-hyprland-focus-app" '^chromium$'
|
||||||
|
|
||||||
grep -F 'hl.dsp.focus({ window = "address:0xabc" })' "$dispatch_log" >/dev/null || \
|
grep -F 'hl.dsp.focus({ window = "address:0xabc" })' "$dispatch_log" >/dev/null || \
|
||||||
fail "app focus uses the workspace-aware Hyprland dispatcher"
|
fail "app focus uses the workspace-aware Hyprland dispatcher"
|
||||||
|
|
||||||
pass "app focus follows windows across workspaces"
|
pass "app focus follows windows across workspaces"
|
||||||
|
|
||||||
|
clients_json='[
|
||||||
|
{"address":"0xviber","class":"com.viber.Viber","initialClass":"com.viber.Viber","initialTitle":"Viber"},
|
||||||
|
{"address":"0xagent","class":"org.omarchy.agent","initialClass":"org.omarchy.agent","initialTitle":"kitty"}
|
||||||
|
]'
|
||||||
|
PATH="$mock_bin:$PATH" OMARCHY_TEST_CLIENTS_JSON="$clients_json" \
|
||||||
|
OMARCHY_TEST_FOCUS_DISPATCH="$dispatch_log" \
|
||||||
|
bash "$ROOT/bin/omarchy-hyprland-focus-app" kitty
|
||||||
|
|
||||||
|
grep -F 'hl.dsp.focus({ window = "address:0xagent" })' "$dispatch_log" >/dev/null || \
|
||||||
|
fail "app focus falls back to the initial window title"
|
||||||
|
|
||||||
|
pass "app focus finds terminals launched under a shared agent class"
|
||||||
|
|
||||||
|
clients_json='[
|
||||||
|
{"address":"0xbrowser","class":"chromium","initialClass":"chromium","initialTitle":"Mail settings"}
|
||||||
|
]'
|
||||||
|
rm -f "$dispatch_log"
|
||||||
|
if PATH="$mock_bin:$PATH" OMARCHY_TEST_CLIENTS_JSON="$clients_json" \
|
||||||
|
OMARCHY_TEST_FOCUS_DISPATCH="$dispatch_log" \
|
||||||
|
bash "$ROOT/bin/omarchy-hyprland-focus-app" Mail; then
|
||||||
|
fail "app focus rejects title matches from non-agent windows"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ ! -e $dispatch_log ]] || fail "app focus leaves focus unchanged for unrelated title matches"
|
||||||
|
|
||||||
|
pass "app focus restricts title matching to agent terminals"
|
||||||
|
|||||||
Reference in New Issue
Block a user