fix(monitor): Only switch input method for the frontmost app#6
Merged
Conversation
AX window, focused-element, and title notifications fire even while an app is in the background. A terminal whose foreground program animates its title — Claude Code's braille spinner being the worst offender — emits a steady stream of these events, and handleWindowFocus acted on every one. The result: a backgrounded terminal's rule reached across and switched the input method of whatever app was actually in front, so typing in Obsidian (or a browser) kept getting yanked to the terminal's configured language. Guard handleWindowFocus so it ignores events whose app isn't frontmost, and re-check frontmost inside the debounce timer in case focus moved during the 0.15s window. activated stays unguarded since an activation notification is itself the signal that the app is now frontmost.
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
A backgrounded terminal could switch the input method of whatever app was actually in front. Reproed cleanly: with Claude Code running in a background Ghostty tab (its braille-spinner title constantly animating), focusing Obsidian would flip the IM — first to Obsidian's own rule, then immediately to the terminal rule's language.
Root cause
handleWindowFocusis driven by AX window / focused-element / title notifications, which fire even while the observed app is in the background. Claude Code's animated title (✳ …,⠂ …,⠐ …) emits a steady stream of title-change events on the background terminal; the matcher acted on each one and applied the terminal's title rule globally — regardless of which app was frontmost.Log excerpt while the user was in Obsidian:
Fix
handleWindowFocusto ignore events whose app isn'tNSWorkspace.frontmostApplication.activatedis left unguarded — an activation notification is itself the signal that the app is now frontmost.Test plan
make buildclean