Skip to content

Ignore keyboard shortcuts while Mission Control is active - #1935

Merged
rxhanson merged 2 commits into
rxhanson:mainfrom
AkiyamaKunka:fix/ignore-shortcuts-in-mission-control
Oct 29, 2026
Merged

rxhanson merged 2 commits into
rxhanson:mainfrom
AkiyamaKunka:fix/ignore-shortcuts-in-mission-control

Conversation

@AkiyamaKunka

@AkiyamaKunka AkiyamaKunka commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1739

While Mission Control is showing, Rectangle's shortcuts still fire and move the last focused window behind the overview, so its thumbnail stretches or jumps. In the issue you wrote that this "would be better fixed on Apple's side" and that you "don't have plans to implement this workaround myself, but see no reason to turn down a pull request for it." This is that pull request.

Why it happens

Mission Control is drawn by the Dock but does not make the Dock the frontmost application, so NSWorkspace.shared.frontmostApplication is still the app the user was in. The Carbon hotkeys keep firing, ShortcutManager.execute hands the action to WindowManager, and WindowManager resolves the front window via Accessibility and moves it. Nothing on the keyboard path knew about Mission Control.

What this changes

ShortcutManager gets one more injectable provider, missionControlActiveProvider, next to appDisabledProvider. Its default is the Mission Control detector that #1886 added for window animations, WindowAnimationInterruptionPolicy.missionControlActive (an AXGroup child of the Dock with identifier mc). At the top of execute(_:), a request whose source is .keyboardShortcut is dropped while that provider reports Mission Control, with a line in View Logging:

Ignoring leftHalf while Mission Control is active

Details:

  • The guard sits before windowActionWillExecute is posted and before MultiWindowManager/TodoManager run, so nothing downstream observes an ignored shortcut; the existing defer still runs any completion the request carries. Duplicate-shortcut cycles and pointer-targeted mouse buttons still resolve their target window before reaching the guard, as they do today.
  • Mouse-button shortcuts and duplicate-shortcut cycles build their ExecutionParameters with the default .keyboardShortcut source, so they are covered too.
  • Menu items, the URL scheme, the title-bar menu and drag-to-snap are deliberate requests and are left untouched.
  • Todo mode's own Toggle Todo / Reflow Todo shortcuts and the stack-badge toggle keep their separate MASShortcutBinder bindings in TodoManager/StackBadgeManager and are not gated here; the Move Todo left/right window actions are. Happy to add the same one-line guard to the Todo reflow binding if you would like it in this PR.
  • No new setting. The check fails open: if the Dock is not running, the Accessibility read fails, or Apple renames the marker, the shortcut executes as before.
  • WindowManager.swift and the Isolate and improve optional window animations #1886 policy file are not modified; ExecutionSource is only read.

Cost

The detector is one Accessibility read of the Dock's children (with the existing 0.05 s messaging timeout on the Dock element) plus a role/identifier read per child. On macOS 27.0.1 it took about 1–3 ms per call once warm (the very first call in a fresh process took ~48 ms while the Accessibility connection to the Dock was established). The keyboard path already performs several Accessibility reads per shortcut to find the front window, so this fits the existing cost profile.

Verified on macOS 27.0.1 (26A434)

A standalone script evaluating the same query as the detector, with the Dock's Accessibility children dumped:

State Dock children Detector
Mission Control closed AXList false
Opened via tell application "Mission Control" to launch AXList, AXGroup id mc title "Mission Control" true
Closed with Escape AXList false

The frontmost application stayed the same (Finder) throughout, which is exactly why the hotkeys kept firing.

Tests

Four new cases in ShortcutManagerSessionTests, using the existing provider injection and CapturingWindowManager:

  • a keyboard shortcut is dropped while Mission Control is active (its completion still runs) and executes once it is not;
  • a mouse-button shortcut behaves the same way;
  • an ignored shortcut never posts windowActionWillExecute;
  • menu, URL, title-bar and drag-to-snap requests still execute while Mission Control is active.

Full RectangleTests suite: 606 tests, 0 failures, on macOS 27.0.1 / Xcode 27.

Mission Control does not change the frontmost application, so Rectangle's
hotkeys kept firing and moved the last focused window behind the overview,
stretching its thumbnail (rxhanson#1739).

ShortcutManager now takes a missionControlActiveProvider, defaulting to the
detector that rxhanson#1886 added for window animations, and drops requests whose
source is .keyboardShortcut while it reports Mission Control, before anything
downstream observes them. Mouse-button shortcuts and duplicate-shortcut cycles
share that source and are covered; menu, URL, title-bar and drag-to-snap
requests are unchanged, and a dropped request still runs its completion.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@AkiyamaKunka
AkiyamaKunka marked this pull request as draft October 19, 2026 16:10
@AkiyamaKunka
AkiyamaKunka marked this pull request as ready for review October 20, 2026 19:57
@AkiyamaKunka
AkiyamaKunka marked this pull request as draft October 23, 2026 03:05
@AkiyamaKunka
AkiyamaKunka marked this pull request as ready for review October 23, 2026 03:31
@rxhanson

Copy link
Copy Markdown
Owner

Thanks! I think this should have a corresponding Defaults setting, as I can see Next/Prev display as still being beneficial to use while in Mission Control. I'm thinking the defaults setting can also be left off, since this issue is likely not too commonly hit, but I don't feel too strongly about it so I'd actually be fine either way.

Gate the rxhanson#1739 guard behind a hidden default,
ignoreShortcutsInMissionControl, defaulting to true (the current
behavior). Users who prefer shortcuts to keep firing can opt out with:

  defaults write com.knollsoft.Rectangle ignoreShortcutsInMissionControl -bool false

BoolDefault gains an optional defaultValue (matching DoubleDefault and
the other Default types) so the toggle can default to true.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@AkiyamaKunka

Copy link
Copy Markdown
Contributor Author

Thanks! I've made this configurable via a hidden default instead of always-on.

  • New ignoreShortcutsInMissionControl default in Defaults.swift, defaulting to true, so the behavior is unchanged out of the box.
  • ShortcutManager's execute path only holds a keyboard/mouse-button shortcut back while that default is enabled (checked before the Mission Control query, via a provider that mirrors the existing missionControlActiveProvider seam).
  • Opt out with: defaults write com.knollsoft.Rectangle ignoreShortcutsInMissionControl -bool false
  • Added tests for both states of the toggle (and for the new BoolDefault default-value path). Full suite passes.

@rxhanson
rxhanson merged commit ee30219 into rxhanson:main Oct 29, 2026
1 check passed
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.

I'm able to move the last selected window while in mission control, causing the window to stretch visually.

2 participants