Skip to content

Focus an open app at once: wait for the keyboard handoff, not an unmap - #118

Merged
cpow merged 1 commit into
typecraft-dev:mainfrom
poterstar:fix/focus-open-app-without-wait
Dec 1, 2026
Merged

cpow merged 1 commit into
typecraft-dev:mainfrom
poterstar:fix/focus-open-app-without-wait

Conversation

@poterstar

Copy link
Copy Markdown
Contributor

Generated by Claude (Claude Code): diagnosis, fix, tests and this description.

Summary

↵ on an app that already has a window took about a second to focus it. AppFocuser waits for the omacast layer to leave hyprctl layers before it dispatches focus, but since c4cb76c the surface stays mapped while hidden, so that wait always runs its full 20 × 50 ms.

What the wait stood for is the keyboard handoff: Hyprland refuses focus while the layer holds exclusive keyboard focus, and refocuses the window under the pointer when it lets go. The launcher's window turns inactive (Window.active) once Hyprland has moved the keyboard away, so the focus is now queued until then and dispatched right after. A 1 s timer, the old worst case, covers a handoff that never reports back. With the launcher hidden (omacast run app:…) it dispatches at once, and a launcher that takes the keyboard again drops a focus still queued from the last session.

SPEC.md §5.1 said the surface is mapped fresh on every open, and the CLAUDE.md note on opening an open app said the focus waits for an unmap; both now describe the mapped surface and the handoff.

 focusWindow(address):
-  bash: poll `hyprctl layers` until "omacast" is gone (never, since c4cb76c) -> focus
+  launcher has the keyboard ? queue, focus on Window.active -> false (1 s fallback)
+                            : focus now

Evidence

Omarchy 4.5.0, Hyprland 0.56.2, Quickshell 0.3.2, Qt 6.12.

The hidden launcher's layer is still listed, so the old loop never breaks:

$ hyprctl layers -j | jq -c '..|objects|select(.namespace?=="omacast")'
{"address":"0x55f4e1677310","x":0,"y":0,"w":2400,"h":1600,"alpha":1,"namespace":"omacast","pid":800982}
$ time (for _ in $(seq 20); do hyprctl layers -j | grep -q '"namespace": *"omacast"' || break; sleep 0.05; done)
real    0m1.057s

shown and Window.active logged on the launcher around omacast show / omacast hide:

shown=true    t+0 ms     active=true    t+49 ms
shown=false   t+0 ms     active=false   t+27 ms

A hl.dsp.focus dispatched right after active=false is accepted on the first try and stays.

Time from ↵ to hyprctl activewindow reporting the app (launcher mapped and focused first, query cleared with Ctrl+U), with focus checked again 0.6 s later:

  • Before (main): Telegram 1057, 1060, 1061 ms.
  • After: Telegram 19–33 ms over 10 runs; Thunderbird on another workspace 19, 20 ms; omacast run app:… with the launcher hidden 30, 31 ms. Focus held in every run.

node --test tests/*.test.js: 187 pass, 0 fail, 3 skipped. omarchy plugin validate . passes. tests/smoke.sh: all ok, worst toggle 35 ms. An independent read-only review of the diff found no bugs; its one suggestion (drop a stale queued focus on reopen) is in.

Merge Danger

Door: two-way

Reverting the commit restores the old wait.

Blast Radius: ↵ on an app that already has a window

Launching an app with no window, Shift+↵ and every other command take the same path as before. If the launcher's window never reports inactive, the focus fires after 1 s, as it did before this change.

↵ on an app that already has a window took about a second to focus it.
AppFocuser waited for the omacast layer to leave `hyprctl layers`, but since
c4cb76c the surface stays mapped while hidden, so the wait always ran its
full 20 × 50 ms.

What it stood for is the keyboard: Hyprland refuses focus while the layer
holds exclusive keyboard focus, and refocuses the window under the pointer
when it lets go. The launcher's window turns inactive once Hyprland has
moved the keyboard away, so the focus is queued until then and dispatched
right after, with a 1 s timer for a handoff that never reports back. A
launcher that takes the keyboard again drops a focus still queued from the
last session.

↵ to focused: ~1060 ms -> 19-33 ms. SPEC §5.1 and CLAUDE.md now describe the
mapped surface and the handoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cpow
cpow merged commit 2c388c7 into typecraft-dev:main Dec 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants