Skip to content

Open source CapCut alternative.

TypeScript

Refine notch hover expansion and panel interaction

David Le2bc847e6fce2
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
index f7634399..fd038d7c 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
@@ -26,6 +26,9 @@ final class PointerPromptOverlayController {
private var isVoiceInputActive = false
private var isStatusExpanded = false
private var isStatusHostExpanded = false
+ // Hover can produce enter/exit samples faster than SwiftUI's spring can settle.
+ // Track the lifecycle explicitly so pending host resizes, opens, and closes
+ // are cancelled in order instead of racing into a stale animation origin.
private var statusHoverPhase: StatusHoverPhase = .collapsed
private var statusCollapseWorkItem: DispatchWorkItem?
private var statusExpansionWorkItem: DispatchWorkItem?
@@ -131,7 +134,7 @@ final class PointerPromptOverlayController {
panel.hidesOnDeactivate = false
panel.isReleasedWhenClosed = false
panel.becomesKeyOnlyIfNeeded = true
- panel.ignoresMouseEvents = true
+ panel.ignoresMouseEvents = false
panel.level = .statusBar
panel.collectionBehavior = [
.canJoinAllSpaces,
@@ -445,6 +448,9 @@ final class PointerPromptOverlayController {
NSAnimationContext.runAnimationGroup { context in
context.duration = 0
context.allowsImplicitAnimation = false
+ // The NSPanel is just the render host. It must jump to its target rect
+ // before SwiftUI animates the visible notch, otherwise AppKit's frame
+ // animation can combine with the SwiftUI spring and look corner-born.
CATransaction.begin()
CATransaction.setDisableActions(true)
if statusPanel.frame.size != metrics.surfaceSize {
@@ -531,6 +537,8 @@ final class PointerPromptOverlayController {
statusHoverPhase = .preparingOpen
isStatusExpanded = false
+ // First render the collapsed visual notch inside the already-expanded
+ // host. The delayed flip below is the only step that should animate.
prepareStatusHostForExpansion()
let workItem = DispatchWorkItem { [weak self] in
@@ -544,7 +552,10 @@ final class PointerPromptOverlayController {
self.updateStatusPanelView()
}
statusExpansionWorkItem = workItem
- DispatchQueue.main.async(execute: workItem)
+ DispatchQueue.main.asyncAfter(
+ deadline: .now() + NotchMetrics.openHostPreparationDelay,
+ execute: workItem
+ )
return
}
@@ -570,6 +581,24 @@ final class PointerPromptOverlayController {
isStatusHostExpanded = true
positionStatusPanel()
updateStatusPanelView()
+ flushStatusHostLayout()
+ }
+
+ private func flushStatusHostLayout() {
+ guard let statusPanel else { return }
+
+ NSAnimationContext.runAnimationGroup { context in
+ context.duration = 0
+ context.allowsImplicitAnimation = false
+
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ statusPanel.contentView?.layoutSubtreeIfNeeded()
+ statusHostingView?.layoutSubtreeIfNeeded()
+ statusHostingView?.displayIfNeeded()
+ statusPanel.displayIfNeeded()
+ CATransaction.commit()
+ }
}
private func scheduleStatusCollapse() {
@@ -602,6 +631,9 @@ final class PointerPromptOverlayController {
private func scheduleStatusHostShrink() {
statusHostShrinkWorkItem?.cancel()
+ // Wait for SwiftUI's short close animation, then collapse the transparent
+ // host without animation. Shrinking it earlier changes the coordinate
+ // space while the visible surface is still animating.
let workItem = DispatchWorkItem { [weak self] in
Task { @MainActor in
self?.shrinkStatusHostIfCollapsed()
@@ -1044,6 +1076,7 @@ private struct NotchMetrics {
private static let collapsedSideLaneWidth: CGFloat = 34
private static let collapsedCornerRadius: CGFloat = 14
private static let expandedCornerRadius: CGFloat = 26
+ static let openHostPreparationDelay: TimeInterval = 1.0 / 60.0
static let closeAnimationDuration: TimeInterval = 0.22
private static let maximumExpandedContentTopInset: CGFloat = 44
}
@@ -1059,6 +1092,9 @@ private struct StatusPanelViewSnapshot: Equatable {
}
private enum StatusHoverPhase {
+ // The status panel has two layers of state: an invisible AppKit host rect and
+ // the SwiftUI notch surface. These phases keep quick hover churn from leaving
+ // one layer expanded while the other is still opening or closing.
case collapsed
case preparingOpen
case expanded
diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
index ccf82b78..dfdc8500 100644
--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
@@ -37,6 +37,10 @@ public struct PointerPromptNotchStatusView: View {
public var body: some View {
GeometryReader { proxy in
animatedNotchSurface
+ // Pin the top edge to the host's top center for every spring frame.
+ // Alignment-based layout occasionally reused a stale host geometry
+ // after quick hover enter/exit, making expansion appear to start
+ // from the bottom-right instead of from the physical notch.
.position(
x: proxy.size.width / 2,
y: animatingSurfaceHeight / 2
diff --git a/docs/guides/pointer-prompt-overlay.md b/docs/guides/pointer-prompt-overlay.md
index 212ac58a..fdbf3459 100644
--- a/docs/guides/pointer-prompt-overlay.md
+++ b/docs/guides/pointer-prompt-overlay.md
@@ -14,7 +14,7 @@ Donkey supports a floating macOS pointer prompt overlay:
- makes the resting notch envelope height match the detected physical notch height when a notch is present
- only expands from controller-tracked hover over the visible notch surface, not SwiftUI hover over the transparent host panel area
- lets the physical notch void participate in collapsed hover activation while keeping expanded content below the void
-- keeps the native status panel collapsed at rest, jumps it to expanded render bounds with AppKit animations disabled before the SwiftUI open spring, and jumps it back after the short non-spring close finishes
+- keeps the native status panel collapsed at rest, jumps it to expanded render bounds with AppKit animations disabled, forces a collapsed layout/display in that expanded host before the SwiftUI open spring, and jumps it back after the short non-spring close finishes
- coalesces quick hover enter and exit samples through explicit collapsed, preparing-open, expanded, and closing phases so pending opens and closes do not fight each other
- keeps expanded notch text and controls below the detected physical notch void while allowing the black surface to extend through it, adding vertical surface space instead of squeezing the below-notch content area
- keeps the notch arrow mark pointed up-right at a fixed 45-degree angle
@@ -24,6 +24,7 @@ Donkey supports a floating macOS pointer prompt overlay:
- lays out collapsed and expanded notch content inside the animated, clipped surface so content reveals and reflows with the current surface width
- fades collapsed notch content out quickly, then fades expanded content in after the surface has started expanding
- shows an update button in the expanded notch header when Sparkle reports a valid appcast update
+- accepts mouse clicks in the notch status panel so expanded header and command-row controls can invoke their actions
- shows a black prompt modal with text input and a white voice waveform while active
- uses a wide pill-shaped prompt for single-line text, then expands to a rounded rectangle when text wraps at the max input width or the user inserts new lines
- places the waveform in a bottom toolbar that blends with the input background when the prompt is expanded
@@ -33,7 +34,6 @@ Donkey supports a floating macOS pointer prompt overlay:
- dismisses the active modal when the user clicks outside it
- dismisses the active modal when the user presses Escape while it is visible
- supports dragging the active modal from capsule areas outside the text input
-- lets normal clicks pass through the inactive overlay and transparent active overlay space
- opens the prompt input centered on the current screen instead of following the cursor
- dismisses the centered prompt after submission and moves visible progress/result feedback into the notch status panel
- submits typed prompt text through the local-app command pipeline while keeping model parsing, task validation, and live input outside the SwiftUI rendering path
@@ -58,7 +58,7 @@ This is a visual, typed-command, and voice-command UI capability. Typed submissi
- The notch status panel should keep its visual language aligned with the `/prototype` route without exposing agent names or implementation roles: a slim arrow-only resting mark beside the physical notch, a minimal one-line task label when collapsed and active, and a compact current-task panel plus command row when expanded.
- SwiftUI notch rendering should consume `PointerPromptNotchLayout` for derived surface/content frames, corner radii, and notch-safe content offsets instead of duplicating screen-geometry constants in the view.
- Hover activation should be bounded to the visible notch surface using controller-side mouse location checks. The transparent host panel and expanded interaction padding must not trigger expansion or keep the notch expanded by themselves.
-- The native status panel should not animate its frame while the SwiftUI notch surface animates. When expansion starts, resize the panel to expanded render bounds with AppKit animations disabled before flipping SwiftUI expansion state; after the short non-spring collapse finishes, resize it back to the resting surface bounds with animations disabled.
+- The native status panel should not animate its frame while the SwiftUI notch surface animates. When expansion starts, resize the panel to expanded render bounds with AppKit animations disabled, render the collapsed notch once in that expanded host, then flip SwiftUI expansion state on the next frame; after the short non-spring collapse finishes, resize it back to the resting surface bounds with animations disabled.
- Expanded notch content must treat the physical notch void as unavailable layout space. The surface may cover the void, but text, buttons, and task rows should start below the detected void height while retaining the normal below-notch content height.
- Notch expansion should reveal from the top edge, growing width and height together so the expanded surface feels attached to the physical notch rather than growing from a lower corner. Use a single rendered surface with the prototype dimensions and a native spring for opening width, height, bottom corner radius, and shadow; use a short ease-out on close so there is no spring tail. Keep collapsed and expanded content inside that clipped surface so layout follows the animated width. Delay the expanded content fade-in so the surface leads the content.
- The expanded notch header may show an update button when `PointerPromptUpdateState` is actionable; clicking it should invoke Sparkle's standard update UI outside the SwiftUI view.