Reach every window the region picker can highlight

Warping to a target window's center selects the wrong window when a smaller
one covers that center: slurp keeps highlighting the coverer, so Tab could
never leave it. Navigation now warps to the most central point that resolves
back to the target, and skips windows that hovering could not reach either.

Unbinding the picker's transient keys by name also took a same-key binding
out of the user's own config with it; the bind handles are now kept and
removed individually.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-08-10 10:17:08 -07:00
co-authored by Claude Opus 5
parent 366c708e44
commit 199bd01f94
2 changed files with 84 additions and 27 deletions
+16 -11
View File
@@ -44,18 +44,26 @@ o.bind("SUPER + CTRL + PRINT", "Extract text (OCR) from screenshot", "omarchy-ca
-- Keyboard control for the slurp region picker (see omarchy-capture-region).
-- The binds live exactly as long as a selection layer is on screen (slurp
-- opens one per monitor), so they cannot leak or get stuck.
-- Unbinding by key would take a same-key binding out of the user's own config
-- with it, so each handle is kept and removed individually.
local selection_layers = 0
local selection_binds = {}
hl.on("layer.opened", function(layer)
if layer.namespace == "selection" then
selection_layers = selection_layers + 1
if selection_layers == 1 then
hl.bind("RETURN", hl.dsp.exec_cmd("omarchy-capture-region --take-window"), { description = "Capture highlighted window" })
hl.bind("CTRL + RETURN", hl.dsp.exec_cmd("omarchy-capture-region --take-fullscreen"), { description = "Capture entire screen" })
hl.bind("TAB", hl.dsp.exec_cmd("omarchy-capture-region --select-window next"), { description = "Select next window to capture" })
hl.bind("CTRL + TAB", hl.dsp.exec_cmd("omarchy-capture-region --select-window prev"), { description = "Select previous window to capture" })
selection_binds = {
hl.bind("RETURN", hl.dsp.exec_cmd("omarchy-capture-region --take-window"), { description = "Capture highlighted window" }),
hl.bind("CTRL + RETURN", hl.dsp.exec_cmd("omarchy-capture-region --take-fullscreen"), { description = "Capture entire screen" }),
hl.bind("TAB", hl.dsp.exec_cmd("omarchy-capture-region --select-window next"), { description = "Select next window to capture" }),
hl.bind("CTRL + TAB", hl.dsp.exec_cmd("omarchy-capture-region --select-window prev"), { description = "Select previous window to capture" }),
}
for _, direction in ipairs({ "left", "right", "up", "down" }) do
hl.bind(direction:upper(), hl.dsp.exec_cmd("omarchy-capture-region --select-window " .. direction), { description = "Select window to capture" })
table.insert(
selection_binds,
hl.bind(direction:upper(), hl.dsp.exec_cmd("omarchy-capture-region --select-window " .. direction), { description = "Select window to capture" })
)
end
end
end
@@ -65,13 +73,10 @@ hl.on("layer.closed", function(layer)
if layer.namespace == "selection" and selection_layers > 0 then
selection_layers = selection_layers - 1
if selection_layers == 0 then
hl.unbind("RETURN")
hl.unbind("CTRL + RETURN")
hl.unbind("TAB")
hl.unbind("CTRL + TAB")
for _, direction in ipairs({ "LEFT", "RIGHT", "UP", "DOWN" }) do
hl.unbind(direction)
for _, keybind in ipairs(selection_binds) do
keybind:unbind()
end
selection_binds = {}
end
end
end)