Hand the terminal launcher the focused window's pid from Lua (#13521)

To open a new terminal in the focused terminal's directory, the launcher
asked Hyprland for the active window with hyprctl, ~10ms on every
SUPER+RETURN. The binding now reads the pid from hl.get_active_window() and
passes it as --pid. Without one, from the menu or a shell, the launcher asks
Hyprland as before.

The bind is now a Lua function, which Hyprland reports only as __lua, so
o.bind_commands records the command it stands for and the keybindings menu
still launches a terminal when the entry is picked.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier HanssonandClaude Opus 5.5 authored and GitHub committed 2026-09-28 11:48:28 +02:00
1 parent fa729f139c
commit f814639556
7 files changed
+59 -5

No files matched your search

+12
View File
@@ -220,3 +220,15 @@ for action in "${expected_alternatives[@]}"; do
fail "every action named as having an alternative is bound twice" "$action"
done
pass "every action named as having an alternative is bound twice"
# The terminal bind is a Lua function Hyprland reports only as __lua, so picking
# it from the menu has to run the command the function stands for.
stub_hyprctl <<BINDS
$(lua_bind 64 "SUPER + RETURN" "Terminal")
BINDS
rm -rf "$tmpdir/cache"
keybindings >/dev/null
grep -qP '→ Terminal\texec\tomarchy-launch-terminal$' "$tmpdir"/cache/omarchy/keybindings-*.records ||
fail "picking the terminal bind from the menu launches a terminal" "$(cat "$tmpdir"/cache/omarchy/keybindings-*.records)"
pass "picking the terminal bind from the menu launches a terminal"
+12
View File
@@ -43,3 +43,15 @@ pass "a new terminal opens in the focused terminal's shell directory"
output=$(PATH="$stub_bin:$PATH" XDG_RUNTIME_DIR="$test_tmp" HOME="$test_tmp" "$ROOT/bin/omarchy-cmd-terminal-cwd" 2>&1)
[[ $output == "$test_tmp" ]] || fail "with no focused terminal the new one opens in HOME" "got: $output"
pass "with no focused terminal the new one opens in HOME, quietly"
# The Super+Return binding hands over the focused window's pid, so Hyprland is
# not asked again; a hyprctl that fails the test proves it goes unasked.
cat >"$stub_bin/hyprctl" <<'SH'
#!/bin/bash
echo "hyprctl was asked for the active window" >&2
exit 1
SH
cwd=$(PATH="$stub_bin:$PATH" XDG_RUNTIME_DIR="$test_tmp" "$ROOT/bin/omarchy-cmd-terminal-cwd" "$terminal_pid" 2>&1)
[[ $cwd == "$work_dir" ]] || fail "a terminal pid passed in finds its shell directory without hyprctl" "got: $cwd"
pass "a terminal pid passed in finds its shell directory without hyprctl"