Fix: Prevent background apps from stealing keyboard focus #62
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
Fixes a bug where background applications steal keyboard focus from the currently active window (e.g., terminal) when launched or during drag-and-drop operations.
Problem
When background applications are launched, they incorrectly receive keyboard focus, interrupting the user's workflow. This is especially problematic when:
Root Cause
The
UIWindowcomponent was callingfocusWindow()unconditionally in several places:is_visiblewas trueBackground apps should not receive focus, but the component had no mechanism to distinguish them from regular apps.
Impact
Solution
Implemented a component-level solution that adds an
options.backgroundproperty to theUIWindowcomponent, which prevents focus operations when set totrue.Changes Made
1. Add
options.backgroundPropertyLocation:
src/gui/src/UI/UIWindow.jsAdd a new
options.backgroundproperty to theUIWindowcomponent, which defaults tofalse.2. Modify Initial Window Creation Logic
Location:
src/gui/src/UI/UIWindow.jsModify the initial window creation logic to only call
focusWindow()if theoptions.backgroundproperty isfalse.Before:
After:
3. Update Event Handlers
Location:
src/gui/src/UI/UIWindow.jsUpdate two additional event handlers to also respect the
options.backgroundflag:A. Drop Event Handler
When items are dropped on the window, only focus if not a background app:
B. Dragster Enter Event Handler
When items are dragged over the window, only set focus timeout if not a background app:
Testing
Manual Testing
Verified the following scenarios:
Launch a background app (with
background: true)Drag items over a background app window
Drop items on a background app window
Launch a regular app (with
background: falseor undefined)Acceptance Criteria
Related Files
src/gui/src/UI/UIWindow.js- Main implementationsrc/gui/src/helpers/launch_app.js- Passes background flag to UIWindowBreaking Changes
None. This is a bug fix that maintains backward compatibility. Regular apps (without
background: true) continue to behave exactly as before.