Skip to content

feat: add the missing + button to the macOS tab bar - #1395

Open
yhcharles wants to merge 1 commit into
tw93:mainfrom
yhcharles:chy/macos-tab-bar-new-tab
Open

yhcharles wants to merge 1 commit into
tw93:mainfrom
yhcharles:chy/macos-tab-bar-new-tab

Conversation

@yhcharles

Copy link
Copy Markdown
Contributor

Problem

Under --multi-window Pake gives its windows a shared tabbing identifier, so macOS groups them into native tabs and draws the tab bar. The bar arrives without its "+" button: AppKit only draws that button when the clicked window's responder chain answers newWindowForTab:, and neither tao nor Tauri implements the selector. The result is a tab bar the user can reorder and close tabs in but can't add one from — Cmd+N is the only way to get another tab.

Fix

The selector is installed on the window's own class, the first responder-chain link Apple documents for newWindowForTab:, so the click is handled by the window that was clicked. The class is resolved from a live window rather than by name, so a tao rename can't silently break this, and the method is only added when it's absent — a future tao implementing it upstream takes precedence and this becomes a no-op.

Asking the instance for [window class] (rather than object_getClass) matters: KVO swizzles the isa pointer to a hidden NSKVONotifying_ subclass, but AppKit decides whether to draw the button from [window class], which KVO overrides to report the real class. object_getClass would install on the swizzled subclass and miss.

Installing on the class (not the instance) covers every window tao creates from a single install call, which is also why nothing is installed at all unless native tabbing is actually on.

This is a workaround for a gap in tao rather than something Pake should own long-term — the selector really belongs in tao's window class. Filing an issue there is a reasonable follow-up if this is welcome here.

Verification

  • cargo test --lib — 48 passed
  • npx vitest run — 497 passed
  • cargo clippy --all-targets — no new warnings
  • cargo fmt --check, prettier --check — clean
  • Not yet verified by hand on macOS (the + button appearing and creating a new tab). I'll do that pass before this is ready to merge — flagging now rather than claiming it's confirmed.

Under `--multi-window` Pake gives its windows a shared tabbing identifier, so macOS groups them into native tabs and draws the tab bar. The bar arrives without its "+" button: AppKit only draws that button when the clicked window's responder chain answers `newWindowForTab:`, and neither tao nor Tauri implements the selector. The result is a tab bar the user can reorder and close tabs in but not add one from, with Cmd+N as the only way to get another tab.

The selector is installed on the window's own class, the first responder-chain link Apple documents for it, so the click is handled by the window that was clicked. The class is resolved from a live window rather than by name, so a tao rename cannot silently break this, and the method is only added when it is absent -- a future tao implementing it upstream takes precedence and this becomes a no-op.

Asking the instance for `[window class]` matters: KVO swizzles the isa to a hidden `NSKVONotifying_` subclass, and AppKit decides whether to draw the button from `[window class]`, which KVO overrides to report the real class. `object_getClass` would install on the swizzled subclass and miss.

Installing on the class covers every window tao creates, which is why nothing is installed at all unless native tabbing is on.

This is a workaround for a gap in tao rather than something Pake should own long-term; the selector belongs in tao's window class.
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.

1 participant