Skip to content

fix(macos): Quick message pill can be focused after chat closes - #1566

Merged
omesser merged 48 commits into
mainfrom
cursor/pill-focus-after-chat-close-1098
Oct 17, 2026
Merged

omesser merged 48 commits into
mainfrom
cursor/pill-focus-after-chat-close-1098

Conversation

@omesser

@omesser omesser commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Addresses #1565

What

On macOS, once you had opened and closed Chat, the quick message pill would show up but wouldn't take typing. Now it takes typing every time it opens.

  • Rest the cursor on the sprite until the pill opens, then type. You don't need to click first, whether or not Chat has been open and whichever app is in front.
  • Enter sends the line and closes the pill. Escape closes it and clears it. Either way, typing goes back to the window you were in. The pill stays shut until the cursor leaves the sprite and comes back.
  • If that app has quit in the meantime, Fidget hands the keyboard to the app or window in front of everything else.
  • Clicking another window while the pill is open moves your typing there, with the caret at the click. If the pill has text, it stays open; if it's empty, it closes.
  • Clicking the sprite when no pill is open leaves your typing where it was.
  • With two displays or two characters, only the overlay showing the open pill takes the keyboard.

Windows keeps main's focus behavior in this PR; its hand-back moves to its own PR.

On Wayland, where typing goes after the pill closes is up to the compositor. Wayland doesn't let one app hand the keyboard to another app's window.

Why

On macOS the overlay never accepted the keyboard, so that clicking the sprite wouldn't steal it. After Chat closed, Fidget stayed in front with no window that could take keys, and typing went nowhere. Now an overlay accepts the keyboard only while one of its pills is open, and gives it back when that pill closes.

How to test

On a Mac, with TextEdit quit:

scripts/scenarios/chat-close-pill-type.sh --go <fidget binary> <fake agent>

It checks Accessibility and Automation (TextEdit, System Events) first and stops with a message if either is missing. Each step gives up after 3 s. It covers 8 cases: a click on the sprite, the pill before Chat and after Chat, the pill with TextEdit in front, Enter, Escape, TextEdit quitting while the pill is open, and a click through the overlay.

macOS live run: PASS (all 11 checks) at d671170, run 134449.

Linux X11 live run at d671170: real Fidget (standing BMO, fixture Harness) on a private Xvfb display with xfwm4 and mousepad, driven by xdotool. PASS on each case: a sprite click leaves typing in the editor; the pill opens on hover and takes typing; Enter hands typing back to the editor; Escape hands it back; a click into the editor keeps the pill's "nine" while "ten" lands at the click. 3 of 3 runs passed, about 9 s each. Not covered on X11: Chat open and close, and the editor quitting while the pill is open. The Xvfb tests in focus_return.rs also pass.

Windows: the native focus code is unchanged from main. Nothing hands the foreground window back when the pill closes. The Windows hand-back (remember and restore the foreground window, step aside, overlay_holds_keyboard) moves to its own PR, and a Windows scenario script comes with it.

The shared pill behavior applies on every OS, Windows included: Escape closes the pill, clicking away keeps its text, and resting the cursor on the sprite opens it through the Shell's hit test. The pill's JS tests and the macOS and X11 scenario runs above cover it. Windows CI builds and tests the Rust, including the hand-back, which does nothing on Windows.

— Cursor agent (P. Coder), on @omesser's behalf.

cursoragent and others added 2 commits October 16, 2026 18:34
Adds TRACE_BUBBLE output to overlay_request_focus and close_chat to diagnose
the root cause of #1565. The scenario opens chat, closes it, then shows the
pill and verifies via traces that the overlay cannot become key.

Expected failure: after chat closes, app_active=true, has_key_window=false,
and can_become_key=false, preventing the pill from accepting keyboard input.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
Root cause: overlay's canBecomeKeyWindow always returns NO. After chat
calls activate_for_typing and makeKeyAndOrderFront, then closes, the app
is active but has no key window. The pill's set_focus() fails because
the overlay refuses to become key.

Solution: Track allowed-to-become-key windows in a global HashSet. When
requesting overlay focus, add the window, call set_focus(), then remove it.
The flag is only consulted when deciding to make a window key, not when
keeping it key.

Implementation:
- overlay_panel.rs: Add ALLOWED_KEY_WINDOWS, make canBecomeKeyWindow check
  this set, export allow_overlay_focus() to manage it
- platform/macos/mod.rs: Export allow_overlay_focus
- main.rs: Wrap set_focus() with allow_overlay_focus(true/false) calls

Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor
cursor Bot force-pushed the cursor/pill-focus-after-chat-close-1098 branch 2 times, most recently from dd81487 to ff87f03 Compare October 16, 2026 18:51
Rewrites scenario to type into the pill and verify the typed text appears
in the draft trace, instead of asserting on internal traces.

Uses shared wait-helpers.mac.sh with trigger-based waits (2-3s) that start
from actual events instead of fixed sleeps.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor
cursor Bot force-pushed the cursor/pill-focus-after-chat-close-1098 branch from ff87f03 to ef4584e Compare October 16, 2026 18:56
Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor
cursor Bot force-pushed the cursor/pill-focus-after-chat-close-1098 branch from 43c8313 to cda2e20 Compare October 16, 2026 19:08
cursoragent and others added 2 commits October 16, 2026 19:10
- Wait for first frame line before reading sprite position
- Wait for second 'bubble: quick' occurrence using wait_for_count
- Click pill text field before typing (matches user steps)
- Replace fixed sleep with event-based wait (bubble: none)
- Add wait_for_count helper to wait-helpers.mac.sh

Co-authored-by: Oded Messer <odedmesser@gmail.com>
The function was trying to call window.as_webview_window() which doesn't
exist on tauri::Window. Since the overlay is always a WebviewWindow, change
the command signature to take WebviewWindow directly, which Tauri will
inject correctly.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor
cursor Bot force-pushed the cursor/pill-focus-after-chat-close-1098 branch from fb7df41 to f61150c Compare October 16, 2026 19:18
@omesser

omesser commented Oct 16, 2026

Copy link
Copy Markdown
Owner Author

"but the overlay is configured to refuse focus so that sprite clicks don't steal focus from your other apps" - why that is the case? I think it's debateable. but in any case, clicking the QM pill whenever it's visible should take focus. 100% always

@omesser

omesser commented Oct 16, 2026

Copy link
Copy Markdown
Owner Author

why that is the case? I think it's debateable

The refusal goes back to 323b7fa, "Add transparent overlay with alpha hit-testing" (towards #1). That was before the pill existed. The overlay spans the whole desktop, and the overlay was made to refuse key status so that clicking the sprite never interrupts typing in another app. Nothing else depends on it.

Plan, now pushed at fc55f59: while the pill is open, the overlay accepts keyboard focus, so clicking the pill always takes the keyboard, whatever the Chat history and whichever app is in front. Once the pill closes, it goes back to refusing. A sprite click with no pill open still won't steal your typing. If you'd rather drop the refusal entirely, that's a one-line follow-up.

scripts/scenarios/chat-close-pill-type.sh clicks the pill and types three times: before Chat has ever opened, after Chat opens and closes, and after Finder comes to the front. Each time it checks that the text shows up. There's also a unit test that the overlay accepts focus only while it's allowed. This covers macOS only. Windows and Linux never refused focus, but I haven't run a pill-click scenario on them.

— Cursor agent (P. Coder), on @omesser's behalf.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

…on or pill timer traces, one owner gate, one keep-typed body, walk_visible, leaner scenario
omesser

This comment was marked as outdated.

…held its change notice 3 s and the late press met a hover-opened pill
…beside any open ones, and closes only that tab (and the window if it opened Notepad)
…the given evidence dir on Windows, so a rerun keeps the earlier one

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft Open

Tip: 2fbb939a

What changed

  • Cuts from the last Architect review are in: FocusAtoms, the activation and pill timer traces, spriteHovered, the roster forget and the scenario debugging are gone. The X11 and Windows filters now reuse atoms.rs and perch_candidate, and macOS reuses walk_visible.
  • Windows leaf added: chat-close-pill-type.win.ps1 runs the same cases against Notepad. It types into its own uniquely named tab, closes only that tab on cleanup, logs any fullscreen app without touching it, and writes a fresh evidence folder per run.
  • Live runs: The body reports macOS PASS on all 11 checks and X11 PASS 3 of 3 at d6711706. App code has not changed since then.

What is wrong

  • Windows leaf polls process.log every 50 ms: Wait-Check caps each WaitForChanged at 50 ms and then rereads the whole log, which grows fast with FIDGET_TRACE_FRAMES=1. That is the sleep-loop file polling that closed #1563. It also copies Wait-OnChanges from wait-helpers.win.ps1 instead of fixing the shared helper.
  • No passing Windows run: The only Windows run, at d6711706, failed at sprite-click. enter, escape and click-away have never run on Windows, and Windows behavior changes in this PR.

Soft-FIX

  • Event-driven Windows wait: Drop the 50 ms reread. If NTFS holds change notices for the open log, find a signal that fires on time instead of polling. If the shared Wait-OnChanges has the same gap, fix it there so every Windows leaf benefits.
  • Windows live run: Run chat-close-pill-type.win.ps1 --go on DESKTOP-UQIE144 at the new tip and post a PASS on all four cases.

Verified: read the change since 473e3d47 and confirmed each earlier cut on the tip. Compared Wait-Check with Wait-OnChanges. The Windows unit tests and the leaf can't run on this Linux host.

— Cursor agent (Architect), on @omesser's behalf.

omesser and others added 3 commits October 17, 2026 15:13
…ay's webview reports, not at the Shell's first frame
…auses; the overlay asks the Shell whether it still holds the keyboard
…ario leaf and verify tests move to their own PR

Reverts b5d87c7 and the Windows remember_foreground/hand_back_keyboard,
Candidate/next_in_front and the overlay_request_focus remember. Windows
hand_back_keyboard is a no-op, as on main.
omesser

This comment was marked as outdated.

omesser

This comment was marked as outdated.

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft+Hard — tip c81647b — Cleared

Axis Verdict
Soft Pass
Spec Pass
Hard Pass
Total Cleared

Soft — Pass

  • Coverage sentence: it now says the pill's JS tests and the macOS and X11 scenario runs cover the shared behavior, and that Windows CI builds and tests the Rust, including the hand-back that does nothing on Windows. That is accurate.
  • Rest of the body: accurate. Windows native focus is unchanged from main, the hand-back and its scenario come in their own PR, and the intended Windows differences are listed (Escape closes the pill, a click away keeps its text, hover comes from the Shell's hit test).

Spec — Pass

  • Carries over from 5557902818: there is no manual Windows check, by Oded's ruling, and Windows has no live scenario yet; one comes with the hand-back PR. The macOS run 134449, the X11 runs, focus_return 10/10 and the 8/10 uncommitted live runs stand as recorded there. Neither of the two failures blocks.

Hard — Pass

  • Tip: still c81647b, with only the body changed.
  • CI: all checks green.

— Cursor agent (P. Architect), on @omesser's behalf.

@omesser
omesser merged commit 0964ca0 into main Oct 17, 2026
6 checks passed
omesser pushed a commit that referenced this pull request Oct 17, 2026
Starts from the #1566-era chat-close-pill-type.win.ps1 (a85979d), which finds
our Notepad tab through UI Automation, saves with Ctrl+S before reading the
doc, closes only its own tab (and the window only if it opened Notepad), and
writes a fresh folder per run. Cut to the four cases main can pass: sprite
click, hover-open then type "two", Escape, click into Notepad. Prints the
pill-open SetForegroundWindow line.

No sleeps: presses are held until Fidget traces click: down, and each word
is one SendInput. Aims at the sprite's middle from the frame line and the
overlay's sprite size. Self-check modes cover every waited-on trace line,
the aim, the Notepad cleanup plan, the overlay gate and reruns; the
scenario.rs tests from a85979d are restored alongside the new ones.

Addresses #1577
omesser pushed a commit that referenced this pull request Oct 17, 2026
Starts from the #1566-era chat-close-pill-type.win.ps1 (a85979d), which finds
our Notepad tab through UI Automation, saves with Ctrl+S before reading the
doc, closes only its own tab (and the window only if it opened Notepad), and
writes a fresh folder per run. Cut to the four cases main can pass: sprite
click, hover-open then type "two", Escape, click into Notepad. Prints the
pill-open SetForegroundWindow line.

No sleeps: presses are held until Fidget traces click: down, and each word
is one SendInput. Aims at the sprite's middle from the frame line and the
overlay's sprite size. Self-check modes cover every waited-on trace line,
the aim, the Notepad cleanup plan, the overlay gate and reruns; the
scenario.rs tests from a85979d are restored alongside the new ones.

Addresses #1577
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