Skip to content

Open source CapCut alternative.

TypeScript

Fix pointer

David Le28e9348cb3ca
diff --git a/apps/Donkey/README.md b/apps/Donkey/README.md
index 3d9af671..8a048162 100644
--- a/apps/Donkey/README.md
+++ b/apps/Donkey/README.md
@@ -2,7 +2,7 @@
SwiftUI macOS app for the production pointer prompt UI.
-This slice renders a floating screenshot-style pointer and ChatGPT-style `Make this so` composer. Command-click anywhere to activate Donkey, show the agent pointer, and focus the prompt input. The composer includes a text area plus room for controls such as add context, voice, and send. The overlay follows the mouse at the bottom right by default, flips around an invisible cursor-centered box near screen edges, and clamps itself inside the visible screen.
+This slice renders a floating native-cursor-sized agent arrowhead and ChatGPT-style `Make this so` composer. Donkey starts in an inactive pointer-only state that follows the main pointer. Command-click anywhere to show and focus the composer at the current pointer location, where the pointer and composer stay pinned until dismissed or dragged. The composer includes a top-left close button, a text area, and controls such as add context, voice, and send; the blue pointer shadow appears only while active. The overlay follows the mouse on a 45-degree bottom-right diagonal by default, flips around an invisible cursor-centered box near screen edges, and clamps itself inside the visible screen.
It does not request Accessibility, Screen Recording, model access, capture-loop, or input-control permissions.
@@ -17,9 +17,3 @@ swift run Donkey
```
Customize the pointer colors in [Sources/Donkey/Resources/theme.json](Sources/Donkey/Resources/theme.json). The app supports `#RRGGBB` and `rgba(r, g, b, a)` color strings.
-
-For one-off local runs, the accent can also be overridden with a six-digit hex value:
-
-```sh
-DONKEY_POINTER_ACCENT=0A84FF swift run Donkey
-```
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
index f1f5d092..befa5754 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayController.swift
@@ -4,10 +4,9 @@ import SwiftUI
@MainActor
final class PointerPromptOverlayController {
- static let contentSize = CGSize(width: 448, height: 166)
+ static let contentSize = PointerPromptLayout.contentSize
private let model: PointerPromptOverlayModel
- private let pointerGap: CGFloat = 18
private let screenPadding: CGFloat = 8
private let routeStepInterval: TimeInterval = 0.15
private let followSmoothing: CGFloat = 0.34
@@ -47,6 +46,10 @@ final class PointerPromptOverlayController {
panel.hasShadow = false
panel.hidesOnDeactivate = false
panel.isReleasedWhenClosed = false
+ panel.ignoresMouseEvents = true
+ panel.dragRegionProvider = { [weak self] in
+ self?.composerDragRegions() ?? []
+ }
panel.level = .floating
panel.collectionBehavior = [
.canJoinAllSpaces,
@@ -56,8 +59,9 @@ final class PointerPromptOverlayController {
]
self.panel = panel
- panel.orderOut(nil)
startCommandClickMonitoring()
+ positionAtCurrentMouseLocation()
+ panel.orderFrontRegardless()
startTimer()
}
@@ -107,6 +111,14 @@ final class PointerPromptOverlayController {
activate(at: NSEvent.mouseLocation)
}
+ private func positionAtCurrentMouseLocation() {
+ currentFrame = nil
+ displayPlacement = .bottomRight
+ finalPlacement = .bottomRight
+ pendingPlacements = []
+ tick(mouseLocation: NSEvent.mouseLocation)
+ }
+
private func activate(at mouseLocation: CGPoint) {
guard let panel else { return }
@@ -134,7 +146,12 @@ final class PointerPromptOverlayController {
private func tick(mouseLocation explicitMouseLocation: CGPoint? = nil) {
guard let panel else { return }
- guard model.promptState.isActive else { return }
+
+ updateMouseEventPassthrough(for: panel)
+ if model.promptState.isActive, explicitMouseLocation == nil {
+ currentFrame = panel.frame
+ return
+ }
let mouseLocation = explicitMouseLocation ?? NSEvent.mouseLocation
guard let screen = screen(containing: mouseLocation) else { return }
@@ -144,16 +161,28 @@ final class PointerPromptOverlayController {
for: mouseLocation,
visibleFrame: screen.visibleFrame
)
- updateRoute(to: targetPlacement, now: now)
- advanceRoute(now: now)
+ if explicitMouseLocation == nil {
+ updateRoute(to: targetPlacement, now: now)
+ advanceRoute(now: now)
+ } else {
+ displayPlacement = targetPlacement
+ finalPlacement = targetPlacement
+ pendingPlacements = []
+ }
let targetFrame = clampedFrame(
frame(for: displayPlacement, mouseLocation: mouseLocation),
+ placement: displayPlacement,
+ in: screen.visibleFrame
+ )
+ let nextFrame = smoothedFrame(
+ toward: targetFrame,
+ placement: displayPlacement,
in: screen.visibleFrame
)
- let nextFrame = smoothedFrame(toward: targetFrame, in: screen.visibleFrame)
currentFrame = nextFrame
panel.setFrame(nextFrame, display: true)
+ updateMouseEventPassthrough(for: panel)
if model.placement != displayPlacement {
model.placement = displayPlacement
@@ -199,8 +228,12 @@ final class PointerPromptOverlayController {
visibleFrame: CGRect
) -> PointerPromptPlacement {
let preferredFrame = frame(for: .bottomRight, mouseLocation: mouseLocation)
- let overflowsRight = preferredFrame.maxX > visibleFrame.maxX - screenPadding
- let overflowsBottom = preferredFrame.minY < visibleFrame.minY + screenPadding
+ let preferredContentFrame = screenContentFrame(
+ for: preferredFrame,
+ placement: .bottomRight
+ )
+ let overflowsRight = preferredContentFrame.maxX > visibleFrame.maxX - screenPadding
+ let overflowsBottom = preferredContentFrame.minY < visibleFrame.minY + screenPadding
let preferredPlacement = placement(left: overflowsRight, above: overflowsBottom)
let candidates = [
@@ -213,6 +246,7 @@ final class PointerPromptOverlayController {
for candidate in candidates where fits(
frame(for: candidate, mouseLocation: mouseLocation),
+ placement: candidate,
in: visibleFrame
) {
return candidate
@@ -239,71 +273,252 @@ final class PointerPromptOverlayController {
mouseLocation: CGPoint
) -> CGRect {
let size = Self.contentSize
+ let anchor = agentPointerTipAnchor(for: placement)
+ let agentPointerTipLocation = agentPointerTipLocation(
+ for: placement,
+ mouseLocation: mouseLocation
+ )
- switch placement {
- case .bottomRight:
- return CGRect(
- x: mouseLocation.x + pointerGap,
- y: mouseLocation.y - size.height - pointerGap,
- width: size.width,
- height: size.height
- )
- case .bottomLeft:
- return CGRect(
- x: mouseLocation.x - size.width - pointerGap,
- y: mouseLocation.y - size.height - pointerGap,
- width: size.width,
- height: size.height
- )
- case .topLeft:
- return CGRect(
- x: mouseLocation.x - size.width - pointerGap,
- y: mouseLocation.y + pointerGap,
- width: size.width,
- height: size.height
- )
- case .topRight:
- return CGRect(
- x: mouseLocation.x + pointerGap,
- y: mouseLocation.y + pointerGap,
- width: size.width,
- height: size.height
+ return CGRect(
+ x: agentPointerTipLocation.x - anchor.x,
+ y: agentPointerTipLocation.y - anchor.y,
+ width: size.width,
+ height: size.height
+ )
+ }
+
+ private func agentPointerTipLocation(
+ for placement: PointerPromptPlacement,
+ mouseLocation: CGPoint
+ ) -> CGPoint {
+ let xDirection: CGFloat = placement.placesContentOnLeft ? -1 : 1
+ let yDirection: CGFloat = placement.placesContentAbovePointer ? 1 : -1
+
+ return CGPoint(
+ x: mouseLocation.x + PointerPromptLayout.pointerDiagonalComponent * xDirection,
+ y: mouseLocation.y + PointerPromptLayout.pointerDiagonalComponent * yDirection
+ )
+ }
+
+ private func agentPointerTipAnchor(for placement: PointerPromptPlacement) -> CGPoint {
+ let pointerSlotX: CGFloat
+ if placement.placesContentOnLeft {
+ pointerSlotX = stageHorizontalInset +
+ PointerPromptLayout.stageHorizontalPadding +
+ PointerPromptLayout.composerSize.width +
+ PointerPromptLayout.pointerComposerSpacing
+ } else {
+ pointerSlotX = stageHorizontalInset + PointerPromptLayout.stageHorizontalPadding
+ }
+ let pointerVisualX = pointerSlotX + pointerVisualInsetX(for: placement)
+ let pointerTipX = pointerVisualX +
+ PointerPromptLayout.pointerVisualSize.width *
+ PointerPromptLayout.pointerTipUnitPoint.x
+
+ return CGPoint(
+ x: pointerTipX,
+ y: Self.contentSize.height - pointerTipYFromTop
+ )
+ }
+
+ private func pointerVisualInsetX(for placement: PointerPromptPlacement) -> CGFloat {
+ placement.placesContentOnLeft ? 0 :
+ PointerPromptLayout.pointerSlotSize.width - PointerPromptLayout.pointerVisualSize.width
+ }
+
+ private func pointerVisualFrame(for placement: PointerPromptPlacement) -> CGRect {
+ let pointerSlotX: CGFloat
+ if placement.placesContentOnLeft {
+ pointerSlotX = stageHorizontalInset +
+ PointerPromptLayout.stageHorizontalPadding +
+ PointerPromptLayout.composerSize.width +
+ PointerPromptLayout.pointerComposerSpacing
+ } else {
+ pointerSlotX = stageHorizontalInset + PointerPromptLayout.stageHorizontalPadding
+ }
+
+ return CGRect(
+ x: pointerSlotX + pointerVisualInsetX(for: placement),
+ y: Self.contentSize.height - pointerVisualTopFromPanelTop - PointerPromptLayout.pointerVisualSize.height,
+ width: PointerPromptLayout.pointerVisualSize.width,
+ height: PointerPromptLayout.pointerVisualSize.height
+ ).insetBy(
+ dx: -PointerPromptLayout.pointerStrokeWidth,
+ dy: -PointerPromptLayout.pointerStrokeWidth
+ )
+ }
+
+ private var stageHorizontalInset: CGFloat {
+ (Self.contentSize.width - stageContentWidth) / 2
+ }
+
+ private var stageVerticalInset: CGFloat {
+ (Self.contentSize.height - stageContentHeight) / 2
+ }
+
+ private var stageContentWidth: CGFloat {
+ PointerPromptLayout.stageHorizontalPadding * 2 +
+ PointerPromptLayout.pointerSlotSize.width +
+ PointerPromptLayout.pointerComposerSpacing +
+ PointerPromptLayout.composerSize.width
+ }
+
+ private var stageContentHeight: CGFloat {
+ PointerPromptLayout.stageVerticalPadding * 2 +
+ PointerPromptLayout.composerSize.height
+ }
+
+ private var pointerCenterYFromTop: CGFloat {
+ stageVerticalInset +
+ PointerPromptLayout.stageVerticalPadding +
+ PointerPromptLayout.composerSize.height / 2
+ }
+
+ private var pointerTipYFromTop: CGFloat {
+ pointerCenterYFromTop -
+ PointerPromptLayout.pointerVisualSize.height / 2 +
+ PointerPromptLayout.pointerVisualSize.height *
+ PointerPromptLayout.pointerTipUnitPoint.y
+ }
+
+ private var pointerVisualTopFromPanelTop: CGFloat {
+ pointerCenterYFromTop - PointerPromptLayout.pointerVisualSize.height / 2
+ }
+
+ private func composerDragRegions() -> [CGRect] {
+ guard model.promptState.isActive else { return [] }
+
+ let composerFrame = composerFrame(for: displayPlacement)
+ let dragThickness = PointerPromptLayout.composerDragBorderThickness
+ let closeButtonClearance = PointerPromptLayout.closeButtonInset * 2 +
+ PointerPromptLayout.closeButtonSize
+
+ return [
+ CGRect(
+ x: composerFrame.minX + closeButtonClearance,
+ y: composerFrame.maxY - dragThickness,
+ width: composerFrame.width - closeButtonClearance,
+ height: dragThickness
+ ),
+ CGRect(
+ x: composerFrame.minX,
+ y: composerFrame.minY,
+ width: composerFrame.width,
+ height: dragThickness
+ ),
+ CGRect(
+ x: composerFrame.minX,
+ y: composerFrame.minY + dragThickness,
+ width: dragThickness,
+ height: composerFrame.height - dragThickness - closeButtonClearance
+ ),
+ CGRect(
+ x: composerFrame.maxX - dragThickness,
+ y: composerFrame.minY + dragThickness,
+ width: dragThickness,
+ height: composerFrame.height - dragThickness * 2
)
+ ]
+ }
+
+ private func composerFrame(for placement: PointerPromptPlacement) -> CGRect {
+ let x: CGFloat
+ if placement.placesContentOnLeft {
+ x = stageHorizontalInset + PointerPromptLayout.stageHorizontalPadding
+ } else {
+ x = stageHorizontalInset +
+ PointerPromptLayout.stageHorizontalPadding +
+ PointerPromptLayout.pointerSlotSize.width +
+ PointerPromptLayout.pointerComposerSpacing
}
+
+ return CGRect(
+ x: x,
+ y: Self.contentSize.height - composerTopFromPanelTop - PointerPromptLayout.composerSize.height,
+ width: PointerPromptLayout.composerSize.width,
+ height: PointerPromptLayout.composerSize.height
+ )
}
- private func fits(_ frame: CGRect, in visibleFrame: CGRect) -> Bool {
- frame.minX >= visibleFrame.minX + screenPadding &&
- frame.maxX <= visibleFrame.maxX - screenPadding &&
- frame.minY >= visibleFrame.minY + screenPadding &&
- frame.maxY <= visibleFrame.maxY - screenPadding
+ private var composerTopFromPanelTop: CGFloat {
+ stageVerticalInset + PointerPromptLayout.stageVerticalPadding
}
- private func clampedFrame(_ frame: CGRect, in visibleFrame: CGRect) -> CGRect {
+ private func visibleContentBounds(for placement: PointerPromptPlacement) -> CGRect {
+ let pointerFrame = pointerVisualFrame(for: placement)
+ guard model.promptState.isActive else {
+ return pointerFrame
+ }
+
+ return pointerFrame.union(composerFrame(for: placement))
+ }
+
+ private func screenContentFrame(
+ for panelFrame: CGRect,
+ placement: PointerPromptPlacement
+ ) -> CGRect {
+ visibleContentBounds(for: placement).offsetBy(
+ dx: panelFrame.minX,
+ dy: panelFrame.minY
+ )
+ }
+
+ private func updateMouseEventPassthrough(for panel: NSPanel) {
+ guard model.promptState.isActive else {
+ panel.ignoresMouseEvents = true
+ return
+ }
+
+ let mouseLocationInPanel = panel.convertPoint(fromScreen: NSEvent.mouseLocation)
+ panel.ignoresMouseEvents = !composerFrame(for: displayPlacement).contains(mouseLocationInPanel)
+ }
+
+ private func fits(
+ _ frame: CGRect,
+ placement: PointerPromptPlacement,
+ in visibleFrame: CGRect
+ ) -> Bool {
+ let contentFrame = screenContentFrame(for: frame, placement: placement)
+ return contentFrame.minX >= visibleFrame.minX + screenPadding &&
+ contentFrame.maxX <= visibleFrame.maxX - screenPadding &&
+ contentFrame.minY >= visibleFrame.minY + screenPadding &&
+ contentFrame.maxY <= visibleFrame.maxY - screenPadding
+ }
+
+ private func clampedFrame(
+ _ frame: CGRect,
+ placement: PointerPromptPlacement,
+ in visibleFrame: CGRect
+ ) -> CGRect {
var origin = frame.origin
let size = frame.size
+ let contentBounds = visibleContentBounds(for: placement)
- let minX = visibleFrame.minX + screenPadding
- let maxX = visibleFrame.maxX - size.width - screenPadding
- let minY = visibleFrame.minY + screenPadding
- let maxY = visibleFrame.maxY - size.height - screenPadding
+ let minX = visibleFrame.minX + screenPadding - contentBounds.minX
+ let maxX = visibleFrame.maxX - screenPadding - contentBounds.maxX
+ let minY = visibleFrame.minY + screenPadding - contentBounds.minY
+ let maxY = visibleFrame.maxY - screenPadding - contentBounds.maxY
if minX <= maxX {
origin.x = min(max(origin.x, minX), maxX)
} else {
- origin.x = visibleFrame.midX - size.width / 2
+ origin.x = visibleFrame.midX - contentBounds.midX
}
if minY <= maxY {
origin.y = min(max(origin.y, minY), maxY)
} else {
- origin.y = visibleFrame.midY - size.height / 2
+ origin.y = visibleFrame.midY - contentBounds.midY
}
return CGRect(origin: origin, size: size)
}
- private func smoothedFrame(toward targetFrame: CGRect, in visibleFrame: CGRect) -> CGRect {
+ private func smoothedFrame(
+ toward targetFrame: CGRect,
+ placement: PointerPromptPlacement,
+ in visibleFrame: CGRect
+ ) -> CGRect {
guard let currentFrame else { return targetFrame }
let smoothing = pendingPlacements.isEmpty ? followSmoothing : flipSmoothing
@@ -311,7 +526,11 @@ final class PointerPromptOverlayController {
x: currentFrame.origin.x + (targetFrame.origin.x - currentFrame.origin.x) * smoothing,
y: currentFrame.origin.y + (targetFrame.origin.y - currentFrame.origin.y) * smoothing
)
- return clampedFrame(CGRect(origin: origin, size: targetFrame.size), in: visibleFrame)
+ return clampedFrame(
+ CGRect(origin: origin, size: targetFrame.size),
+ placement: placement,
+ in: visibleFrame
+ )
}
private func screen(containing point: CGPoint) -> NSScreen? {
@@ -322,6 +541,8 @@ final class PointerPromptOverlayController {
}
private final class PointerPromptPanel: NSPanel {
+ var dragRegionProvider: (() -> [CGRect])?
+
override var canBecomeKey: Bool {
true
}
@@ -329,4 +550,14 @@ private final class PointerPromptPanel: NSPanel {
override var canBecomeMain: Bool {
true
}
+
+ override func sendEvent(_ event: NSEvent) {
+ if event.type == .leftMouseDown,
+ dragRegionProvider?().contains(where: { $0.contains(event.locationInWindow) }) == true {
+ performDrag(with: event)
+ return
+ }
+
+ super.sendEvent(event)
+ }
}
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
index e0968c93..e55082d2 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
@@ -16,17 +16,16 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
init(
runtimeProvider: any RuntimeStatusProviding = OffTheShelfRunLoopBoundary(),
aiProvider: any AIHarnessSnapshotProviding = AIHarnessBoundary(),
- theme: PointerPromptTheme = PointerPromptOverlayModel.configuredTheme()
+ theme: PointerPromptTheme = PointerPromptOverlayModel.bundledTheme()
) {
self.runtimeProvider = runtimeProvider
self.aiProvider = aiProvider
- let runtimeSnapshot = runtimeProvider.snapshot()
let aiSnapshot = aiProvider.snapshot()
promptState = PointerPromptState(
promptText: aiSnapshot.suggestedPromptText,
isPrimaryActionEnabled: true,
- leadingSignalLevel: runtimeSnapshot.isReady ? .ready : .idle,
+ leadingSignalLevel: .idle,
isActive: false,
theme: theme
)
@@ -58,15 +57,6 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
}
}
- private static func configuredTheme() -> PointerPromptTheme {
- guard let hexColor = ProcessInfo.processInfo.environment["DONKEY_POINTER_ACCENT"],
- let color = PointerPromptColor(hexRGB: hexColor) else {
- return bundledTheme()
- }
-
- return .accent(color)
- }
-
private static func bundledTheme() -> PointerPromptTheme {
guard let themeURL = Bundle.module.url(forResource: "theme", withExtension: "json"),
let themeData = try? Data(contentsOf: themeURL),
@@ -78,13 +68,3 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
return theme
}
}
-
-private extension PointerPromptColor {
- init?(hexRGB: String) {
- guard let color = PointerPromptColor(cssString: hexRGB) else {
- return nil
- }
-
- self = color
- }
-}
diff --git a/apps/Donkey/Sources/Donkey/Resources/theme.json b/apps/Donkey/Sources/Donkey/Resources/theme.json
index b7cad6f7..6a1aae6d 100644
--- a/apps/Donkey/Sources/Donkey/Resources/theme.json
+++ b/apps/Donkey/Sources/Donkey/Resources/theme.json
@@ -1,6 +1,6 @@
{
- "accent": "#0D6ED9",
+ "accent": "#0D6CD8",
"fill": "#E0F0FF",
- "pointerFill": "#D1EDFF",
+ "pointerFill": "#FFFFFF",
"activeShadow": "rgba(0, 36, 82, 0.26)"
}
diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
index 9bf06b53..7e4ee534 100644
--- a/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptContracts.swift
@@ -47,9 +47,14 @@ public struct PointerPromptTheme: Equatable, Sendable {
}
public static let defaultBlue = PointerPromptTheme(
- accent: PointerPromptColor(red: 0.05, green: 0.43, blue: 0.85, alpha: 1),
+ accent: PointerPromptColor(
+ red: 13.0 / 255.0,
+ green: 108.0 / 255.0,
+ blue: 216.0 / 255.0,
+ alpha: 1
+ ),
fill: PointerPromptColor(red: 0.88, green: 0.94, blue: 1.0, alpha: 1),
- pointerFill: PointerPromptColor(red: 0.82, green: 0.93, blue: 1.0, alpha: 1),
+ pointerFill: .white,
activeShadow: PointerPromptColor(red: 0.0, green: 0.14, blue: 0.32, alpha: 0.26)
)
diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift
new file mode 100644
index 00000000..ba71784d
--- /dev/null
+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptLayout.swift
@@ -0,0 +1,19 @@
+import CoreGraphics
+
+public enum PointerPromptLayout {
+ public static let contentSize = CGSize(width: 448, height: 166)
+ public static let stageHorizontalPadding: CGFloat = 8
+ public static let stageVerticalPadding: CGFloat = 10
+ public static let pointerSlotSize = CGSize(width: 58, height: 68)
+ public static let pointerVisualSize = CGSize(width: 24, height: 24)
+ public static let pointerTipUnitPoint = CGPoint(x: 0.16914, y: 0.05641)
+ public static let pointerStrokeWidth: CGFloat = 1.6
+ public static let pointerDistanceFromCursor: CGFloat = 32
+ public static let pointerDiagonalComponent = pointerDistanceFromCursor / CGFloat(2).squareRoot()
+ public static let pointerComposerSpacing: CGFloat = 16
+ public static let composerSize = CGSize(width: 350, height: 142)
+ public static let composerCornerRadius: CGFloat = 12
+ public static let composerDragBorderThickness: CGFloat = 14
+ public static let closeButtonSize: CGFloat = 20
+ public static let closeButtonInset: CGFloat = 12
+}
diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
index ec0fd044..27f234ea 100644
--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptStageView.swift
@@ -21,8 +21,8 @@ public struct PointerPromptStageView: View {
public var body: some View {
promptContent
- .padding(.horizontal, 8)
- .padding(.vertical, 10)
+ .padding(.horizontal, PointerPromptLayout.stageHorizontalPadding)
+ .padding(.vertical, PointerPromptLayout.stageVerticalPadding)
.background(Color.clear)
.accessibilityElement(children: .contain)
}
@@ -30,14 +30,14 @@ public struct PointerPromptStageView: View {
@ViewBuilder
private var promptContent: some View {
if placement.placesContentOnLeft {
- HStack(alignment: .bottom, spacing: 16) {
- composer
+ HStack(alignment: .center, spacing: PointerPromptLayout.pointerComposerSpacing) {
+ activeComposer
pointer
}
} else {
- HStack(alignment: .bottom, spacing: 16) {
+ HStack(alignment: .center, spacing: PointerPromptLayout.pointerComposerSpacing) {
pointer
- composer
+ activeComposer
}
}
}
@@ -48,8 +48,10 @@ public struct PointerPromptStageView: View {
theme: state.theme,
isActive: state.isActive
)
- .frame(width: 58, height: 68)
- .offset(y: placement.placesContentAbovePointer ? 20 : -22)
+ .frame(
+ width: PointerPromptLayout.pointerSlotSize.width,
+ height: PointerPromptLayout.pointerSlotSize.height
+ )
}
private var composer: some View {
@@ -62,11 +64,24 @@ public struct PointerPromptStageView: View {
voiceInput: {
intentSink?.handle(.voiceInputRequested)
},
+ dismiss: {
+ intentSink?.handle(.dismissed)
+ },
submit: {
intentSink?.handle(.messageSubmitted(text: messageText))
}
)
- .frame(width: 350, height: 142)
+ .frame(
+ width: PointerPromptLayout.composerSize.width,
+ height: PointerPromptLayout.composerSize.height
+ )
+ }
+
+ private var activeComposer: some View {
+ composer
+ .opacity(state.isActive ? 1 : 0)
+ .allowsHitTesting(state.isActive)
+ .accessibilityHidden(!state.isActive)
}
}
@@ -75,21 +90,27 @@ private struct PointerPromptComposer: View {
@Binding var messageText: String
let addContext: @MainActor () -> Void
let voiceInput: @MainActor () -> Void
+ let dismiss: @MainActor () -> Void
let submit: @MainActor () -> Void
@FocusState private var isFocused: Bool
var body: some View {
VStack(spacing: 13) {
- TextField(state.promptText, text: $messageText)
- .textFieldStyle(.plain)
- .font(.system(size: 26, weight: .semibold, design: .rounded))
- .foregroundStyle(Color(promptColor: state.theme.accent))
- .lineLimit(1)
- .minimumScaleFactor(0.7)
- .focused($isFocused)
- .onSubmit(submit)
- .accessibilityLabel("Message for Donkey")
- .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
+ HStack(spacing: 12) {
+ ComposerCloseButton(action: dismiss)
+
+ TextField(state.promptText, text: $messageText)
+ .textFieldStyle(.plain)
+ .font(.system(size: 26, weight: .semibold, design: .rounded))
+ .foregroundStyle(Color(promptColor: state.theme.accent))
+ .lineLimit(1)
+ .minimumScaleFactor(0.7)
+ .focused($isFocused)
+ .onSubmit(submit)
+ .accessibilityLabel("Message for Donkey")
+ .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
+ }
+ .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
HStack(spacing: 10) {
ComposerIconButton(
@@ -117,18 +138,18 @@ private struct PointerPromptComposer: View {
)
}
}
- .padding(.leading, 24)
+ .padding(.leading, 14)
.padding(.trailing, 18)
- .padding(.top, 24)
+ .padding(.top, 16)
.padding(.bottom, 16)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background {
- RoundedRectangle(cornerRadius: 38, style: .continuous)
+ RoundedRectangle(cornerRadius: PointerPromptLayout.composerCornerRadius, style: .continuous)
.fill(Color(promptColor: state.theme.fill))
}
.overlay {
- RoundedRectangle(cornerRadius: 38, style: .continuous)
- .stroke(Color(promptColor: state.theme.accent), lineWidth: 2.4)
+ RoundedRectangle(cornerRadius: PointerPromptLayout.composerCornerRadius, style: .continuous)
+ .stroke(Color(promptColor: state.theme.accent), lineWidth: 1.4)
}
.shadow(
color: Color(promptColor: state.theme.accent).opacity(state.isActive ? 0.13 : 0.08),
@@ -136,14 +157,17 @@ private struct PointerPromptComposer: View {
x: 0,
y: state.isActive ? 5 : 3
)
- .onAppear(perform: focusIfActive)
+ .onAppear(perform: syncFocusWithActiveState)
.onChange(of: state.isActive) { _, _ in
- focusIfActive()
+ syncFocusWithActiveState()
}
}
- private func focusIfActive() {
- guard state.isActive else { return }
+ private func syncFocusWithActiveState() {
+ guard state.isActive else {
+ isFocused = false
+ return
+ }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
isFocused = true
@@ -151,6 +175,32 @@ private struct PointerPromptComposer: View {
}
}
+private struct ComposerCloseButton: View {
+ let action: @MainActor () -> Void
+
+ var body: some View {
+ Button(action: action) {
+ Image(systemName: "xmark")
+ .font(.system(size: 9, weight: .bold))
+ .foregroundStyle(Color.white)
+ .frame(
+ width: PointerPromptLayout.closeButtonSize,
+ height: PointerPromptLayout.closeButtonSize
+ )
+ .background {
+ Circle()
+ .fill(Color.red)
+ }
+ .overlay {
+ Circle()
+ .stroke(Color.black.opacity(0.16), lineWidth: 0.5)
+ }
+ }
+ .buttonStyle(.plain)
+ .accessibilityLabel("Close prompt")
+ }
+}
+
private struct ComposerIconButton: View {
let systemName: String
let label: String
@@ -239,37 +289,45 @@ private struct AgentPointerView: View {
let isActive: Bool
var body: some View {
- ZStack(alignment: .bottom) {
+ ZStack(alignment: shapeAlignment) {
if isActive {
Ellipse()
.fill(Color(promptColor: theme.activeShadow))
- .frame(width: 42, height: 13)
- .blur(radius: 4)
- .offset(y: 2)
+ .frame(width: 17, height: 5)
+ .blur(radius: 2)
+ .offset(y: 11)
}
AgentPointerShape()
.fill(Color(promptColor: theme.pointerFill))
.overlay {
AgentPointerShape()
- .stroke(Color(promptColor: theme.accent), lineWidth: 2.3)
+ .stroke(
+ Color(promptColor: theme.accent),
+ style: StrokeStyle(
+ lineWidth: PointerPromptLayout.pointerStrokeWidth,
+ lineCap: .round,
+ lineJoin: .round
+ )
+ )
}
.shadow(
- color: Color(promptColor: theme.accent).opacity(isActive ? 0.18 : 0.08),
- radius: isActive ? 8 : 4,
+ color: Color(promptColor: theme.accent).opacity(isActive ? 0.12 : 0),
+ radius: isActive ? 3 : 0,
x: 0,
- y: isActive ? 4 : 2
+ y: isActive ? 2 : 0
+ )
+ .frame(
+ width: PointerPromptLayout.pointerVisualSize.width,
+ height: PointerPromptLayout.pointerVisualSize.height
)
- .frame(width: 48, height: 58)
- .rotationEffect(rotation)
- .scaleEffect(x: placement.placesContentOnLeft ? -1 : 1, y: 1)
- .offset(y: -7)
}
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: shapeAlignment)
.accessibilityHidden(true)
}
- private var rotation: Angle {
- placement.placesContentAbovePointer ? .degrees(18) : .degrees(-14)
+ private var shapeAlignment: Alignment {
+ placement.placesContentOnLeft ? .leading : .trailing
}
}
@@ -279,17 +337,42 @@ private struct AgentPointerShape: Shape {
let w = rect.width
let h = rect.height
- path.move(to: CGPoint(x: w * 0.12, y: h * 0.04))
- path.addLine(to: CGPoint(x: w * 0.86, y: h * 0.55))
- path.addLine(to: CGPoint(x: w * 0.52, y: h * 0.62))
- path.addLine(to: CGPoint(x: w * 0.68, y: h * 0.95))
- path.addLine(to: CGPoint(x: w * 0.49, y: h * 1.0))
- path.addLine(to: CGPoint(x: w * 0.34, y: h * 0.69))
- path.addLine(to: CGPoint(x: w * 0.12, y: h * 0.88))
+ path.move(to: svgPoint(x: 83.086, y: 5.6406, width: w, height: h))
+ path.addLine(to: svgPoint(x: 10.453, y: 34.6836, width: w, height: h))
+ path.addCurve(
+ to: svgPoint(x: 11.13269, y: 51.0276, width: w, height: h),
+ control1: svgPoint(x: 2.8514, y: 37.7227, width: w, height: h),
+ control2: svgPoint(x: 3.3085, y: 48.6326, width: w, height: h)
+ )
+ path.addLine(to: svgPoint(x: 35.69469, y: 58.5471, width: w, height: h))
+ path.addCurve(
+ to: svgPoint(x: 41.44859, y: 64.301, width: w, height: h),
+ control1: svgPoint(x: 38.44859, y: 59.39085, width: w, height: h),
+ control2: svgPoint(x: 40.60489, y: 61.5471, width: w, height: h)
+ )
+ path.addLine(to: svgPoint(x: 48.96809, y: 88.863, width: w, height: h))
+ path.addCurve(
+ to: svgPoint(x: 65.31209, y: 89.54269, width: w, height: h),
+ control1: svgPoint(x: 51.36649, y: 96.6911, width: w, height: h),
+ control2: svgPoint(x: 62.27309, y: 97.1442, width: w, height: h)
+ )
+ path.addLine(to: svgPoint(x: 94.35509, y: 16.90969, width: w, height: h))
+ path.addCurve(
+ to: svgPoint(x: 83.08209, y: 5.63669, width: w, height: h),
+ control1: svgPoint(x: 97.18709, y: 9.83159, width: w, height: h),
+ control2: svgPoint(x: 90.15979, y: 2.80769, width: w, height: h)
+ )
path.closeSubpath()
return path
}
+
+ private func svgPoint(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) -> CGPoint {
+ CGPoint(
+ x: (100 - x) / 100 * width,
+ y: y / 100 * height
+ )
+ }
}
private extension Color {
diff --git a/docs/guides/pointer-prompt-overlay.md b/docs/guides/pointer-prompt-overlay.md
index d2fdddb6..807758e0 100644
--- a/docs/guides/pointer-prompt-overlay.md
+++ b/docs/guides/pointer-prompt-overlay.md
@@ -4,10 +4,15 @@
Donkey supports a floating macOS pointer prompt overlay:
-- command-click anywhere to activate the agent pointer and focus the prompt composer
-- shows a cursor-style agent pointer and rounded ChatGPT-style `Make this so` composer
-- includes a text input area plus room for controls such as add context, voice, and send
-- follows the user mouse at bottom right by default while active
+- shows a small inactive agent pointer that follows the user pointer immediately when Donkey starts
+- command-click anywhere to activate and focus the prompt composer at the current pointer location
+- shows a native-cursor-sized agent arrowhead and rounded ChatGPT-style `Make this so` composer
+- shows the text input, add context, voice, send controls, and active pointer shadow only while active
+- keeps the pointer and composer pinned where activation happened until the user closes or drags the composer
+- closes the active composer with a top-left close button and returns to the inactive following pointer
+- supports dragging the active composer by its border areas
+- lets normal clicks pass through the inactive pointer-only overlay and transparent active overlay space
+- follows the user mouse at a 45-degree bottom-right diagonal by default
- stays fully inside the current screen visible frame
- flips to the left, top, or top-left side when the default position would leave the screen
- animates side changes along an invisible box around the user pointer
@@ -25,10 +30,12 @@ This is a visual UI capability. It does not capture the screen, send input, call
- Treat the composer like a ChatGPT input box: one surface can contain typed text, submission, and adjacent controls.
- Composer controls should emit typed `PointerPromptIntent` values instead of reaching into runtime, AI, or controller code.
- Pointer colors load from JSON into `PointerPromptTheme`; views must not hard-code product colors.
+- The active composer should use a normal system-window corner radius, expose a top-left close control, and keep controls/content areas interactive while only border regions drag the window. Transparent active overlay space must pass clicks through to windows underneath.
+- The agent pointer should remain close to native cursor size, use the mirrored SVG cursor silhouette from the Noun Project pointer asset, point in the same up-left direction as the native macOS cursor, and keep its tip 32px from the real pointer on an equal x/y diagonal.
- Placement is one of `bottomRight`, `bottomLeft`, `topLeft`, or `topRight`.
-- The controller must clamp the final panel frame to `NSScreen.visibleFrame` before applying it.
+- The controller must clamp visible pointer/composer bounds to `NSScreen.visibleFrame` before applying the panel frame, because inactive mode uses a larger transparent panel than its visible pointer.
- Diagonal placement changes should route through a side placement first, so bottom-right overflow can animate to left and then top-left.
-- Command-click handling belongs in `PointerPromptOverlayController`, not the SwiftUI view.
+- Launch positioning and command-click focus handling belong in `PointerPromptOverlayController`, not the SwiftUI view.
- Keep the overlay non-invasive: no capture loop, input execution, Accessibility prompt, or LLM call in this feature.
## Verification
@@ -40,13 +47,9 @@ swift build
swift run Donkey
```
-Command-click anywhere and confirm the composer appears with keyboard focus. Type a message, confirm the send control enables, and move the mouse near the bottom-right screen edge to confirm the prompt moves left, then top-left if needed, without clipping off screen.
+Launch Donkey and confirm only the small agent pointer appears and follows the main pointer. Command-click anywhere to show the composer with keyboard focus, then move the mouse and confirm the active pointer and composer stay pinned. Click through transparent overlay space into another desktop window, drag the composer from border areas, close it with the top-left close button, and confirm the inactive pointer resumes following the main pointer. Type a message, confirm the send control enables, and activate near the bottom-right screen edge to confirm the prompt chooses a non-clipping placement.
-To verify color customization, edit `apps/Donkey/Sources/Donkey/Resources/theme.json`, rebuild, and run Donkey. For one-off local runs, the accent can also be overridden:
-
-```sh
-DONKEY_POINTER_ACCENT=FF375F swift run Donkey
-```
+To verify color customization, edit `apps/Donkey/Sources/Donkey/Resources/theme.json`, rebuild, and run Donkey.
## Source Entry Points