Skip to content

Preserve focus after workspace transition invalidation#485

Open
henry-p wants to merge 1 commit into
BarutSRB:mainfrom
henry-p:fix/focus-previous-app-activation
Open

Preserve focus after workspace transition invalidation#485
henry-p wants to merge 1 commit into
BarutSRB:mainfrom
henry-p:fix/focus-previous-app-activation

Conversation

@henry-p

@henry-p henry-p commented Jul 14, 2026

Copy link
Copy Markdown

Fixes #484.

Preserves the exact-window focus handoff when a workspace reveal invalidates its relayout, without allowing stale focus steals.

Reproduced across Chrome, VS Code, Spotify, ChatGPT, Safari, Mail, and iTerm2; regression tests, format, and lint pass.

Summary by CodeRabbit

  • Bug Fixes

    • Improved window focus handling during workspace transitions, ensuring focus is applied only when the target window and workspace are still active.
    • Preserved focus handoff when layout invalidation occurs during a transition.
  • Tests

    • Added coverage for focus behavior when workspace layouts are invalidated mid-transition.

Trace: https://gist.github.com/henry-p/a39baac2dc3ec8218436c058c854d2b8

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace transitions now support a separate callback for invalidated post-layout refreshes. Window navigation uses guarded focus logic for both callback paths, with an async runtime test covering invalidated transition behavior.

Changes

Workspace focus handoff

Layer / File(s) Summary
Transition callback wiring
Sources/OmniWM/Core/Controller/LayoutRefreshController.swift, Sources/OmniWM/Core/Controller/WindowActionHandler.swift
commitWorkspaceTransition forwards postLayoutInvalidated, and navigation supplies a workspace-validated focus closure to both post-layout callbacks.
Invalidated transition validation
Tests/OmniWMTests/RuntimeArchitectureTests.swift
An async test drives an invalidated refresh to completion and verifies that the invalidated callback runs instead of the current-layout callback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WindowActionHandler
  participant LayoutRefreshController
  participant WorkspaceLayout
  participant TargetWindow

  WindowActionHandler->>LayoutRefreshController: commitWorkspaceTransition with focusTarget callbacks
  LayoutRefreshController->>WorkspaceLayout: invalidate during refresh
  LayoutRefreshController->>WindowActionHandler: invoke invalidated post-layout callback
  WindowActionHandler->>TargetWindow: verify workspace state and focus target
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes restore post-layout focus handoff during invalidated workspace transitions, matching issue #484's requirements.
Out of Scope Changes check ✅ Passed The PR stays focused on workspace-transition focus handling and its test coverage, with no evident unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: preserving focus through workspace transition invalidation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BarutSRB

Copy link
Copy Markdown
Owner

Thank you will look at this tomorrow and if all good will merge it ♥️

@henry-p

henry-p commented Jul 14, 2026

Copy link
Copy Markdown
Author

@BarutSRB

Copy link
Copy Markdown
Owner

Sorry will look at this tomorrow as tonight I'll be pushing a new release that targets one specific problem that is a bit risky and might break stuff, just wanted to let you know that I'm not ignoring and that I appreciate the PR and help ♥️♥️♥️

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.

Preserve focus after an invalidated workspace transition

2 participants