Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import AppKit
import CmuxNextDesign

/// Open and close of a panel pinned to its window's top-right corner with no
/// control under it (the notifications and feed panels, cx-f6i7): it grows
/// out of that corner and shrinks back into it (`NSWindow.openPopup`), so it
/// never pops in or vanishes. A reopen during the close continues from what
/// is on screen. Reduce Motion keeps the fades only.
/// control under it (the notifications and feed panels, cx-f6i7): it appears
/// in one frame and fades/shrinks back into that corner on close. A reopen
/// during the close continues from what is on screen.
@MainActor
final class CornerPanelMotion {
private var generation = 0
/// The panel is fading out: it is on screen but no longer shown.
private(set) var isClosing = false

/// Orders `panel` front at its frame, growing out of its top-right corner.
/// Orders `panel` front at its frame in one frame.
func open(_ panel: NSWindow) {
let reopening = isClosing && panel.isVisible
isClosing = false
generation += 1
panel.ignoresMouseEvents = false
if !reopening { panel.alphaValue = 0 }
panel.orderFront(nil)
panel.openPopup(pivot: Self.pivot(of: panel), entrance: true)
panel.openPopup(pivot: Self.pivot(of: panel))
// A reopen continues the close's scale, whose pivot was for the frame before.
if reopening { resized(panel) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class ServerMenuBarController: NSObject, NSPopoverDelegate {
controller.view = view
let pop = NSPopover()
pop.behavior = .transient
pop.animates = Motion.overlays.animatesMovement
pop.animates = false
pop.contentViewController = controller
pop.contentSize = view.frame.size
pop.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public import CoreGraphics
/// The material itself (Liquid Glass, vibrancy before macOS 26, opaque under Reduce Transparency)
/// stays `OverlayMaterial`'s decision; this style only sets the tint, rim, radius and shadow.
///
/// Motion is not here: it lives in `MotionTunables` only. Popups open on the `popover` spring from
/// `Motion.popupOpenScale` and close on `popoverClose` to `Motion.popupCloseScale`; toasts rise on
/// Motion is not here: it lives in `MotionTunables` only. Popups open at once and close on
/// `popoverClose` to `Motion.popupCloseScale`; toasts rise on
/// `appear` and fade with `fadeIn`/`fadeOut`. Every one of them fades the card's layer, never the
/// window's `alphaValue` (a glass card ignores window alpha), and the rim fades with the card
/// because it sits inside it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ public import AppKit

/// Open and close of a popup window that a control opened (cx-f6i7): the
/// Chief pill's settings card, the group editors under a tab group chip or a
/// sidebar group header, page info, the toolbar menus. The card fades in
/// while it grows from `Motion.popupOpenScale` on the `popover` spring about
/// the middle of its edge that faces the control, so it reads as coming out
/// of that control; it closes faster (`popoverClose`), fading and shrinking
/// toward the same point. A reopen during the close continues from what is
/// on screen. Reduce Motion keeps a short crossfade at the popup's size;
/// `ui.animationSpeed` "off" applies both at once.
/// sidebar group header, page info, the toolbar menus. The card opens at its
/// final size and opacity in the same frame as the click. It closes faster
/// (`popoverClose`), fading and shrinking toward the control. A reopen during
/// the close continues from what is on screen. Reduce Motion keeps a short
/// crossfade at the popup's size; `ui.animationSpeed` "off" applies both at
/// once.
///
/// Both run on the content view's layer, never the window's alpha
/// (Lawrence's recording 2026-10-20): faded through `alphaValue`, the glass
/// card showed no fade at all, so it appeared at full size in one frame and
/// left after a ~75 ms hold. The window is opaque while the popup is up;
/// owners still order a fresh popup front at alpha 0, which `openPopup`
/// lifts once the card's layer starts at opacity 0, so nothing flashes.
/// Close motion runs on the content view's layer, never the window's alpha.
/// The window is opaque while the popup is up, and opening ends any stale
/// close animation before the card is shown.
@MainActor
public extension NSWindow {
/// The point the popup grows from, in its content view: the middle of
/// The point the popup closes toward, in its content view: the middle of
/// the content edge nearest `anchor` (screen coordinates), at the
/// anchor's horizontal center when that falls inside the popup.
func popupPivot(toward anchor: CGRect) -> CGPoint {
Expand All @@ -29,12 +25,20 @@ public extension NSWindow {
return CGPoint(x: x, y: y)
}

/// Opens the popup at `pivot`. Popups use their shared entrance motion by
/// default; menu callers opt out explicitly so they appear in one frame. A
/// fresh animated open (the owner left the window at alpha 0) starts from
/// nothing; a reopen during the close continues from what is on screen.
func openPopup(pivot: CGPoint, entrance: Bool = true) {
guard entrance else { return showPopupAtOnce() }
/// Opens the popup at its final size and opacity in this frame. Popup and
/// menu entrances never animate; their close may still fade and shrink.
func openPopup(pivot: CGPoint) {
_ = pivot // Kept at the call site for the matching close pivot.
showPopupAtOnce()
}

/// Opens a page tooltip (not a menu or popover) with its fade and grow
/// from `pivot`: the one entrance left, for the tooltips `popupHost.ts`
/// sends without `instant` (every tooltip outside New Tab). Menus and
/// popovers open with ``openPopup(pivot:)``. A fresh open (the owner left
/// the window at alpha 0) starts from nothing; a reopen during the close
/// continues from what is on screen.
func openTooltipWithEntrance(pivot: CGPoint) {
guard let content = contentView else {
alphaValue = 1
return
Expand All @@ -53,18 +57,18 @@ public extension NSWindow {
Motion.overlays.set(layer, "sublayerTransform", to: NSValue(caTransform3D: CATransform3DIdentity), spring: .popover,
from: fresh ? NSValue(caTransform3D: Motion.scale(Motion.popupOpenScale, about: pivot, in: layer)) : nil)
} else {
// Reduce Motion: at the popup's size, whatever a close left on screen.
// Reduce Motion: at the tooltip's size, whatever a close left on screen.
layer.removeAnimation(forKey: "sublayerTransform")
setPopupLayer(layer, opacity: nil, transform: CATransform3DIdentity)
}
// The card's first frame (opacity 0) reaches the screen before the window turns opaque.
// perf-gate-ok: one commit per popup open (no flash of the full card); a theme change never opens one.
// perf-gate-ok: one commit per tooltip open (no flash of the full card); a theme change never opens one.
CATransaction.flush()
alphaValue = 1
}

/// Shows the popup's card at its size and full opacity in this frame, ending any open or close
/// on screen: the open with no entrance (a page that asks for none, the New Tab; or no motion).
/// on screen, including a reopen during a close.
func showPopupAtOnce() {
if let content = contentView {
content.wantsLayer = true
Expand Down Expand Up @@ -148,7 +152,7 @@ public final class PopupFade {
window.orderFront(nil)
// The icon picker is a menu-like control: the instant-menu rule applies
// even though PopupFade also services animated card panels.
if opening { window.openPopup(pivot: window.popupPivot(toward: anchor), entrance: false) }
if opening { window.openPopup(pivot: window.popupPivot(toward: anchor)) }
}

/// Fades `window` out toward `anchor`, then takes it off its window.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ extension Motion {
/// Scale a floating panel closes to, with `fadeOut`: a slight shrink.
public static var panelCloseScale: CGFloat { CGFloat(MotionTunables.panelCloseScale.value) }

/// Scale a popup grows from, about the control it opened from, on the `popover` spring.
/// Legacy popup entrance scale retained for settings compatibility. Native popup entrances
/// are immediate.
public static var popupOpenScale: CGFloat { CGFloat(MotionTunables.popupOpenScale.value) }
/// Scale a popup shrinks to, toward its control, on the `popoverClose` spring.
public static var popupCloseScale: CGFloat { CGFloat(MotionTunables.popupCloseScale.value) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public import AppKit
/// and moves with the window. The host owns what every popup shares:
///
/// - placement: below the anchor or above it on the screen (``PopupPlacement``);
/// - motion: opens in one frame by default; an explicit entrance grows out of the anchor and
/// shrinks back toward it on the card's layer (``NSWindow/openPopup(pivot:entrance:)``);
/// - motion: opens in one frame and shrinks back toward the anchor on close
/// (``NSWindow/openPopup(pivot:)``);
/// - dismiss rules: a click outside the popup (``keepsOpen`` lists the clicks that do not count),
/// Escape in the popup, the app going inactive, the window moving, resizing, closing or
/// minimizing, and for a ``NativePopupPanel`` the popup losing the keys.
Expand All @@ -22,7 +22,7 @@ public final class NativePopupHost {
public var keepsOpen: (NSEvent) -> Bool = { _ in false }
/// The popup closed by a dismiss rule; ``hide()`` does not call it.
public var onDismiss: (() -> Void)?
/// The control the popup opened from (screen), which it grows from and shrinks toward.
/// The control the popup opened from (screen), which it closes toward.
public private(set) var anchor: CGRect = .zero
/// Fading out after a hide: gone for the owner and for tests.
public private(set) var isClosing = false
Expand Down Expand Up @@ -62,12 +62,14 @@ public final class NativePopupHost {
/// Shows (or moves) the popup with a card of `size` at `anchor` (screen) over `window`.
/// `trailing` and `centered` align it on the anchor (``PopupPlacement/frame(anchor:size:preferred:trailing:centered:screen:gap:margin:)``).
/// `makeKey` gives it the keys (a ``NativePopupPanel`` takes them only while the app is
/// active). `entrance` false shows it in one frame, with no grow or fade in (its close still
/// fades). Returns the card frame and the side it took, or nil when it cannot show.
/// active). The popup shows in one frame, with no grow or fade in; its close still fades.
/// `tooltipEntrance` is for a page tooltip only (``WebPopupHost``): it fades and grows in
/// (``NSWindow/openTooltipWithEntrance(pivot:)``). Menus and popovers never pass it.
/// Returns the card frame and the side it took, or nil when it cannot show.
@discardableResult
public func show(size: CGSize, anchor: CGRect, in window: NSWindow, preferred: PopupPlacement.Side = .below,
trailing: Bool = false, centered: Bool = false, makeKey: Bool = false,
entrance: Bool = false) -> (frame: CGRect, side: PopupPlacement.Side)? {
tooltipEntrance: Bool = false) -> (frame: CGRect, side: PopupPlacement.Side)? {
guard window.isVisible, let screen = PopupPlacement.screen(for: anchor, fallback: window) else { return nil }
let (frame, side) = PopupPlacement.frame(anchor: anchor, size: size, preferred: preferred, trailing: trailing,
centered: centered, screen: screen.visibleFrame)
Expand All @@ -86,7 +88,8 @@ public final class NativePopupHost {
if opening, !panel.isVisible { panel.alphaValue = 0 }
if makeKey { panel.makeKeyAndOrderFront(nil) } else { panel.orderFront(nil) }
if opening {
if entrance { panel.openPopup(pivot: panel.popupPivot(toward: anchor), entrance: true) } else { panel.showPopupAtOnce() }
let pivot = panel.popupPivot(toward: anchor)
if tooltipEntrance { panel.openTooltipWithEntrance(pivot: pivot) } else { panel.openPopup(pivot: pivot) }
}
watch(window)
return (frame, side)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public final class WebPopupHost {
public var width: CGFloat
/// A tooltip: one row that takes no clicks and draws no check column.
public var tooltip: Bool
/// The page shows nothing with an entrance (a New Tab, Leo 2026-10-22): the menu opens in
/// one frame; its close still fades.
/// The page asks for no entrance (`popupHost.ts` sets it on every menu, and on tooltips on
/// the New Tab). Menus open in one frame whatever it says; a tooltip without it keeps its
/// fade and grow in. Every close still fades.
public var instant: Bool

/// Reads `{items:[{id,label,shortcut?,checked?,disabled?,separator?}], highlighted?,
Expand Down Expand Up @@ -100,7 +101,8 @@ public final class WebPopupHost {
let anchor = window.convertToScreen(webView.convert(flipped, to: nil))
let size = CGSize(width: model.width * scale, height: panel.rows.contentHeight)
guard let placed = popup.show(size: size, anchor: anchor, in: window, preferred: model.side,
trailing: model.trailing, entrance: !model.instant) else { return ["shown": false] }
trailing: model.trailing,
tooltipEntrance: model.tooltip && !model.instant) else { return ["shown": false] }
panel.isClosing = false
let frame = placed.frame
return ["shown": true, "side": placed.side == .below ? "bottom" : "top",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public nonisolated enum MotionSpring: String, Sendable, CaseIterable {
/// not change it. Swift-only for now (cmux-motion's `MotionSpring` ends at `tabOpen`; parity
/// compares the tokens both ports have).
case split
/// A popup (a popover, a menu, a group editor) growing out of the control it opened from:
/// scale and fade on the card's own layer (``NSWindow/openPopup(pivot:)``). Slightly
/// under-damped, like `NSPopover`. Swift-only, like `split`.
/// The legacy popup entrance spring. Native popovers and menus now open in one frame;
/// this token remains for settings compatibility. Swift-only, like `split`.
case popover
/// The same popup shrinking back toward its control as it fades out, faster than it opened.
/// A popup shrinking back toward its control as it fades out.
/// Critically damped. Swift-only.
case popoverClose

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import Testing
let (window, page) = try Self.page()
defer { window.closeAfterTest() }
let host = WebPopupHost(webView: page, zoom: { 1 }, send: { _ in })
// The open and the close start with movement on; synchronous inside: the override is process-wide.
// Opening is synchronous; the close may animate. The override is process-wide.
let (reply, panel, opened) = try { () throws -> ([String: Any], WebPopupPanel, Bool) in
Motion.reduceMotionOverride = false
defer { Motion.reduceMotionOverride = nil }
let reply = host.show(try Self.menu(["a", "b"]))
let panel = try #require(NSApp.windows.compactMap { $0 as? WebPopupPanel }.first { $0.parent === window })
return (reply, panel, panel.contentView?.layer?.animation(forKey: "sublayerTransform") != nil)
return (reply, panel, panel.contentView?.layer?.animationKeys()?.isEmpty ?? true)
}()
#expect(!panel.hasShadow, "the system window shadow")
let card = try #require(panel.contentView as? PopupHostView, "no popup shadow").card
// The reply and `shownFrame` name the menu's card, not its shadow band.
let frame = try #require(reply["frame"] as? [CGFloat])
#expect(host.shownFrame == CGRect(x: frame[0], y: frame[1], width: frame[2], height: frame[3]))
#expect(host.shownFrame?.size == card.frame.size)
#expect(opened, "opened in one frame")
#expect(opened, "the menu animated in")

host.hide()
#expect(panel.isVisible, "closed in one frame")
Expand Down Expand Up @@ -79,8 +79,39 @@ import Testing
#expect(await GUIAnimationTestSupport.settle { !panel.isVisible }, "the close never ended")
}

/// Native menus and popovers use the host's default: no entrance motion. The explicit
/// `entrance` opt-in remains available for the command palette's own presentation.
/// Review of #27136: menus open in one frame, but a page tooltip that does not ask for
/// `instant` (every tooltip outside New Tab, `popupHost.ts`) keeps its fade and grow in.
@Test(.enabled("needs an awake display and animations on, or every popup snaps anyway") { await GUIAnimationTestSupport.animatesHere() })
func aPageTooltipKeepsItsEntranceUnlessItAsksForNone() async throws {
for instant in [false, true] {
let (window, page) = try Self.page()
defer { window.orderOut(nil) }
let host = WebPopupHost(webView: page, zoom: { 1 }, send: { _ in })
var params: [String: Any] = [
"items": [["id": "tip", "label": "A tooltip"]], "kind": "tooltip",
"anchor": ["left": 40, "top": 40, "right": 200, "bottom": 64], "width": 160,
]
if instant { params["instant"] = true }
let model = try #require(WebPopupHost.Model(params))
let opening = try { () throws -> [String] in
Motion.reduceMotionOverride = false
defer { Motion.reduceMotionOverride = nil }
host.show(model)
let panel = try #require(NSApp.windows.compactMap { $0 as? WebPopupPanel }.first { $0.parent === window })
let layer = panel.contentView?.layer
return ["opacity", "sublayerTransform"].filter { layer?.animation(forKey: $0) != nil }
}()
if instant {
#expect(opening == [], "an instant tooltip animated in")
} else {
#expect(opening == ["opacity", "sublayerTransform"], "the tooltip lost its entrance")
}
host.hide()
#expect(await GUIAnimationTestSupport.settle { host.shownFrame == nil })
}
}

/// Native menus and popovers use the host's default: no entrance motion.
@Test(.enabled("needs an awake display and animations on, or every popup snaps anyway") { await GUIAnimationTestSupport.animatesHere() })
func aNativePopupDefaultsToAnInstantOpenAndFadesOnClose() async throws {
let (window, _) = try Self.page()
Expand Down
Loading