fix(agent-isolation): close the macOS touch overlay when it loses the keyboard - #1325
Merged
Merged
Conversation
… keyboard take_focus takes the keyboard once, on the way up, and the window is -topmost. Anything that takes it afterwards — a notification, another application activating, the terminal being clicked — left the overlay painted over the screen with Esc going somewhere else and nothing but a kill to get rid of it. Bind <Deactivate> so the window closes instead. Not <FocusOut>: Tk's focus events track the keyboard moving between widgets inside one application, and nothing moves between widgets here, so it never fires when another application takes over. The binding is deferred past a short grace period because activation itself churns focus — bound immediately, the window closes on its own way up. Re-grabbing the keyboard would make Esc always work too, but this window deliberately does not trap the screen: the key still has to be touched for the command to go through. Generated-by: Claude Opus 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
from the keyboard.
take_focustakes the keyboard once, on the way up, andthe window is
-topmost— so anything that takes focus afterwards (anotification, another app activating, clicking back to the terminal) left the
overlay painted over the screen with
Escgoing elsewhere. Reported by a userwho had to
killthe process to clear it.<Deactivate>so the window closes when another application takes thekeyboard, rather than lingering in a state where it is visible but not
listening.
Escalways work, butthe module's contract is that it does not trap the screen — the key still has
to be touched for the command to go through.
Why
<Deactivate>and not<FocusOut>Tk's focus events track the keyboard moving between widgets inside one
application, and nothing moves between widgets here.
<FocusOut>readscorrect and does nothing when a different application takes over. I tried it
first and measured it doing nothing before switching.
Type of change
tools/*/withpyproject.toml)Test plan
prek run --all-filespassesuv run pytest tools/agent-isolation/tests/test_gpg_touch_overlay.py— green(1 skip: no interpreter on this machine can import
gi)test_the_aqua_window_closes_when_it_loses_the_keyboardfails without the fix (
AssertionError: ... it binds only ['<Button-1>', '<Escape>']) and passes with it_tk_pythonactually selects:Escwith overlay focusedEscafter another app activatesNotes for review
gpg-touch-overlay-window.py) callspresent()once and hasno equivalent focus-loss handling, so it likely shares this flaw. I did not
touch it: I have no Linux/GTK environment here and did not want to ship an
unverified change to that path. Worth a follow-up by someone who can test it.
FOCUS_GRACE_MS = 750is empirical — long enough to cover activation churn onthis machine, short enough to still catch a real focus loss. Happy to adjust.