Skip to content

Open source CapCut alternative.

TypeScript

feat(app): resize recording windows and show live dimensions [rebuild]

David Le4885e6537ba9
diff --git a/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift b/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift
index ebfda1d4..3e20586d 100644
--- a/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift
+++ b/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift
@@ -32,7 +32,7 @@ final class RecordingControlBarController {
hostingView.wantsLayer = true
hostingView.layer?.backgroundColor = NSColor.clear.cgColor
- let panel = NSPanel(
+ let panel = RecordingControlPanel(
contentRect: frame(for: size, on: screen),
styleMask: [.borderless, .nonactivatingPanel],
backing: .buffered,
@@ -79,3 +79,7 @@ final class RecordingControlBarController {
return CGRect(x: x, y: y, width: size.width, height: size.height)
}
}
+
+private final class RecordingControlPanel: NSPanel {
+ override var canBecomeKey: Bool { true }
+}
diff --git a/apps/Donkey/Sources/Donkey/ScreenRecordingController.swift b/apps/Donkey/Sources/Donkey/ScreenRecordingController.swift
index c82b540d..d8597d01 100644
--- a/apps/Donkey/Sources/Donkey/ScreenRecordingController.swift
+++ b/apps/Donkey/Sources/Donkey/ScreenRecordingController.swift
@@ -1,4 +1,5 @@
import AppKit
+@preconcurrency import ApplicationServices
import AVFoundation
import DonkeyRuntime
import DonkeyUI
@@ -28,12 +29,14 @@ final class ScreenRecordingController {
private let regionOverlay = RegionSelectionOverlayController()
private let windowPicker = WindowPickerOverlayController()
private let recordingDim = RecordingRegionDimOverlayController()
+ private let windowResizer = RecordingWindowResizer()
private var recorder: (any ScreenRecording)?
private var phase: Phase = .idle
private var armScreen: NSScreen?
private var selectedRegion: (rect: CGRect, displayID: CGDirectDisplayID)?
private var selectedWindowID: CGWindowID?
+ private var windowSizeTask: Task<Void, Never>?
private var recordingStart: Date?
private var timer: Timer?
@@ -44,6 +47,8 @@ final class ScreenRecordingController {
model.onRecord = { [weak self] in self?.startRecording() }
model.onStop = { [weak self] in self?.stopRecording() }
model.onClose = { [weak self] in self?.cancel() }
+ model.onRefreshWindowSize = { [weak self] in self?.refreshWindowSize() }
+ model.onResizeWindow = { [weak self] width, height in self?.resizeWindow(width: width, height: height) }
regionOverlay.onSelect = { [weak self] rect, displayID in self?.handleRegionSelected(rect, displayID) }
regionOverlay.onCancel = { [weak self] in self?.handlePickerCancel() }
@@ -51,6 +56,10 @@ final class ScreenRecordingController {
windowPicker.onCancel = { [weak self] in self?.handlePickerCancel() }
}
+ deinit {
+ windowSizeTask?.cancel()
+ }
+
// MARK: - Menu bar routing
/// The "Record Screen" item's title and matching record/stop glyph for the Donkey menu, or `nil`
@@ -87,6 +96,8 @@ final class ScreenRecordingController {
phase = .armed
selectedRegion = nil
selectedWindowID = nil
+ model.windowWidth = nil
+ model.windowHeight = nil
model.mode = .fullScreen
model.isRecording = false
model.isBusy = false
@@ -105,6 +116,8 @@ final class ScreenRecordingController {
}
private func cancel() {
+ guard !model.isBusy else { return }
+ stopWindowSizeUpdates()
teardownOverlays()
recordingDim.close()
controlBar.close()
@@ -116,6 +129,24 @@ final class ScreenRecordingController {
// MARK: - Mode selection
private func selectMode(_ mode: RecordingCaptureMode) {
+ guard phase == .armed, !model.isBusy else { return }
+ if mode != .fullScreen, SystemPermissionCoordinator.status(.screenRecording) != .granted {
+ model.isBusy = true
+ Task {
+ let granted = await ensurePermission(.screenRecording, hint: "Allow Screen Recording in System Settings, then select a window or region.")
+ model.isBusy = false
+ if granted, SystemPermissionCoordinator.status(.screenRecording) == .granted {
+ selectMode(mode)
+ } else {
+ if granted { model.statusMessage = "Restart Donkey to finish enabling Screen Recording." }
+ openScreenRecordingSettings()
+ }
+ }
+ return
+ }
+ stopWindowSizeUpdates()
+ model.windowWidth = nil
+ model.windowHeight = nil
model.mode = mode
model.statusMessage = nil
teardownOverlays()
@@ -140,11 +171,93 @@ final class ScreenRecordingController {
private func handleWindowSelected(_ windowID: CGWindowID) {
selectedWindowID = windowID
windowPicker.close()
+ refreshWindowSize()
+ startWindowSizeUpdates(windowID: windowID)
refreshCanRecord()
}
+ private func refreshWindowSize() {
+ let size = selectedWindowID.flatMap { RecordingWindowResizer.frame(windowID: $0)?.size }
+ setWindowSize(size)
+ }
+
+ private func setWindowSize(_ size: CGSize?) {
+ let width = size.map { Int($0.width.rounded()) }
+ let height = size.map { Int($0.height.rounded()) }
+ if model.windowWidth != width { model.windowWidth = width }
+ if model.windowHeight != height { model.windowHeight = height }
+ if model.mode == .window, model.canRecord != (size != nil) {
+ model.canRecord = size != nil
+ }
+ }
+
+ private func startWindowSizeUpdates(windowID: CGWindowID) {
+ stopWindowSizeUpdates()
+ // Read only the selected window off the main thread. Window-server geometry also works
+ // before Accessibility permission is granted and follows manual resizing in other apps.
+ windowSizeTask = Task.detached(priority: .utility) { [weak self] in
+ while !Task.isCancelled {
+ let size = RecordingWindowResizer.frame(windowID: windowID)?.size
+ guard await self?.updateWindowSize(size, windowID: windowID) == true else { return }
+ do {
+ try await Task.sleep(for: .milliseconds(200))
+ } catch {
+ return
+ }
+ }
+ }
+ }
+
+ private func updateWindowSize(_ size: CGSize?, windowID: CGWindowID) -> Bool {
+ guard !Task.isCancelled, phase == .armed, model.mode == .window, selectedWindowID == windowID else {
+ return false
+ }
+ setWindowSize(size)
+ return true
+ }
+
+ private func stopWindowSizeUpdates() {
+ windowSizeTask?.cancel()
+ windowSizeTask = nil
+ }
+
+ private func resizeWindow(width: Int, height: Int) {
+ guard phase == .armed, !model.isBusy, model.mode == .window,
+ let selectedWindowID, width > 0, height > 0 else { return }
+ let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary
+ guard AXIsProcessTrustedWithOptions(options) else {
+ model.statusMessage = "Allow Donkey in System Settings → Privacy & Security → Accessibility, then apply the size again."
+ return
+ }
+ let primaryHeight = NSScreen.screens.first?.frame.height ?? 0
+ let visibleFrames = NSScreen.screens.map { screen in
+ let frame = screen.visibleFrame
+ return CGRect(x: frame.minX, y: primaryHeight - frame.maxY, width: frame.width, height: frame.height)
+ }
+ model.isBusy = true
+ model.statusMessage = nil
+ Task {
+ defer { model.isBusy = false }
+ do {
+ let actual = try await windowResizer.resize(
+ windowID: selectedWindowID,
+ size: CGSize(width: width, height: height),
+ visibleFrames: visibleFrames
+ )
+ refreshWindowSize()
+ if abs(actual.width - CGFloat(width)) >= 1 || abs(actual.height - CGFloat(height)) >= 1 {
+ model.statusMessage = "The app adjusted the size to \(Int(actual.width.rounded())) × \(Int(actual.height.rounded())) pt. Try a larger preset or custom size."
+ }
+ } catch {
+ refreshWindowSize()
+ model.statusMessage = error.localizedDescription
+ }
+ }
+ }
+
/// Escape / dismiss from a picker returns to full-screen, keeping the control bar up.
private func handlePickerCancel() {
+ stopWindowSizeUpdates()
teardownOverlays()
model.mode = .fullScreen
selectedRegion = nil
@@ -156,21 +269,25 @@ final class ScreenRecordingController {
switch model.mode {
case .fullScreen: model.canRecord = true
case .region: model.canRecord = selectedRegion != nil
- case .window: model.canRecord = selectedWindowID != nil
+ case .window: model.canRecord = selectedWindowID != nil && model.windowWidth != nil && model.windowHeight != nil
}
}
// MARK: - Recording
private func startRecording() {
- guard phase == .armed else { return }
+ guard phase == .armed, !model.isBusy else { return }
guard #available(macOS 15.0, *) else {
model.statusMessage = "Screen recording requires macOS 15 or later."
return
}
guard let target = resolveTarget() else { return }
- Task { await beginCapture(target: target) }
+ model.isBusy = true
+ Task {
+ defer { model.isBusy = false }
+ await beginCapture(target: target)
+ }
}
@available(macOS 15.0, *)
@@ -213,6 +330,7 @@ final class ScreenRecordingController {
do {
try await recorder.start(configuration)
+ stopWindowSizeUpdates()
phase = .recording
recordingStart = Date()
model.isRecording = true
diff --git a/apps/Donkey/Sources/DonkeyRuntime/RecordingWindowResizer.swift b/apps/Donkey/Sources/DonkeyRuntime/RecordingWindowResizer.swift
new file mode 100644
index 00000000..df4bc907
--- /dev/null
+++ b/apps/Donkey/Sources/DonkeyRuntime/RecordingWindowResizer.swift
@@ -0,0 +1,135 @@
+import ApplicationServices
+import Foundation
+
+public enum RecordingWindowResizeError: LocalizedError {
+ case unavailable
+ case ambiguous
+ case fixedSize
+ case tooLarge
+ case failed
+
+ public var errorDescription: String? {
+ switch self {
+ case .unavailable: return "The selected window is unavailable. Select it again."
+ case .ambiguous: return "Move the selected window away from overlapping windows, then try again."
+ case .fixedSize: return "This window cannot be resized. Exit full screen or select a resizable window."
+ case .tooLarge: return "Enter a size that fits on the window’s display."
+ case .failed: return "The app could not resize its window. Try again."
+ }
+ }
+}
+
+/// Accessibility calls run off the main thread and only when a size is applied.
+public actor RecordingWindowResizer {
+ public init() {}
+
+ public nonisolated static func frame(windowID: CGWindowID) -> CGRect? {
+ windowInfo(windowID: windowID)?.frame
+ }
+
+ public func resize(windowID: CGWindowID, size: CGSize, visibleFrames: [CGRect]) async throws -> CGSize {
+ guard let info = Self.windowInfo(windowID: windowID) else {
+ throw RecordingWindowResizeError.unavailable
+ }
+ let target = try Self.targetFrame(current: info.frame, size: size, visibleFrames: visibleFrames)
+ let app = AXUIElementCreateApplication(info.pid)
+ AXUIElementSetMessagingTimeout(app, 1)
+ var value: CFTypeRef?
+ guard AXUIElementCopyAttributeValue(app, kAXWindowsAttribute as CFString, &value) == .success,
+ let windows = value as? [AXUIElement] else {
+ throw RecordingWindowResizeError.unavailable
+ }
+ // Public Accessibility APIs identify windows by geometry. Require a unique match so
+ // identical stacked windows never cause us to resize a different capture target.
+ let matches = windows.filter { window in
+ guard let frame = Self.axFrame(window) else { return false }
+ return Self.matches(frame, info.frame)
+ }
+ guard let window = matches.first else { throw RecordingWindowResizeError.unavailable }
+ guard matches.count == 1 else { throw RecordingWindowResizeError.ambiguous }
+ var resizable = DarwinBoolean(false)
+ guard AXUIElementIsAttributeSettable(window, kAXSizeAttribute as CFString, &resizable) == .success,
+ resizable.boolValue else { throw RecordingWindowResizeError.fixedSize }
+ var fullScreen: CFTypeRef?
+ if AXUIElementCopyAttributeValue(window, "AXFullScreen" as CFString, &fullScreen) == .success,
+ (fullScreen as? Bool) == true {
+ throw RecordingWindowResizeError.fixedSize
+ }
+ try Task.checkCancellation()
+ // Position first so the destination has room for the requested dimensions.
+ if target.origin != info.frame.origin {
+ var origin = target.origin
+ guard let position = AXValueCreate(.cgPoint, &origin),
+ AXUIElementSetAttributeValue(window, kAXPositionAttribute as CFString, position) == .success else {
+ throw RecordingWindowResizeError.failed
+ }
+ }
+ var requestedSize = size
+ guard let axSize = AXValueCreate(.cgSize, &requestedSize),
+ AXUIElementSetAttributeValue(window, kAXSizeAttribute as CFString, axSize) == .success else {
+ throw RecordingWindowResizeError.failed
+ }
+ // Apps can animate or enforce minimum dimensions. Read the window server's resulting
+ // geometry, which is also the geometry ScreenCaptureKit uses when recording starts.
+ for _ in 0..<5 {
+ try await Task.sleep(for: .milliseconds(100))
+ guard let actual = Self.frame(windowID: windowID) else {
+ throw RecordingWindowResizeError.unavailable
+ }
+ if abs(actual.width - size.width) < 1, abs(actual.height - size.height) < 1 {
+ return actual.size
+ }
+ }
+ guard let actual = Self.frame(windowID: windowID) else { throw RecordingWindowResizeError.unavailable }
+ return actual.size
+ }
+
+ static func targetFrame(current: CGRect, size: CGSize, visibleFrames: [CGRect]) throws -> CGRect {
+ guard size.width.isFinite, size.height.isFinite, size.width > 0, size.height > 0,
+ let screen = visibleFrames.max(by: { intersectionArea(current, $0) < intersectionArea(current, $1) }),
+ intersectionArea(current, screen) > 0,
+ size.width <= screen.width, size.height <= screen.height else {
+ throw RecordingWindowResizeError.tooLarge
+ }
+ return CGRect(
+ x: min(max(current.minX, screen.minX), screen.maxX - size.width),
+ y: min(max(current.minY, screen.minY), screen.maxY - size.height),
+ width: size.width,
+ height: size.height
+ )
+ }
+
+ private static func intersectionArea(_ a: CGRect, _ b: CGRect) -> CGFloat {
+ let rect = a.intersection(b)
+ return rect.isNull ? 0 : rect.width * rect.height
+ }
+
+ private nonisolated static func windowInfo(windowID: CGWindowID) -> (pid: pid_t, frame: CGRect)? {
+ guard let entries = CGWindowListCopyWindowInfo(.optionIncludingWindow, windowID) as? [[String: Any]],
+ let entry = entries.first(where: { ($0[kCGWindowNumber as String] as? CGWindowID) == windowID }),
+ let pid = entry[kCGWindowOwnerPID as String] as? pid_t,
+ let bounds = entry[kCGWindowBounds as String] as? NSDictionary,
+ let frame = CGRect(dictionaryRepresentation: bounds) else { return nil }
+ return (pid, frame)
+ }
+
+ private static func axFrame(_ window: AXUIElement) -> CGRect? {
+ var positionValue: CFTypeRef?
+ var sizeValue: CFTypeRef?
+ guard AXUIElementCopyAttributeValue(window, kAXPositionAttribute as CFString, &positionValue) == .success,
+ AXUIElementCopyAttributeValue(window, kAXSizeAttribute as CFString, &sizeValue) == .success,
+ let positionValue, let sizeValue,
+ CFGetTypeID(positionValue) == AXValueGetTypeID(),
+ CFGetTypeID(sizeValue) == AXValueGetTypeID() else { return nil }
+ var origin = CGPoint.zero
+ var size = CGSize.zero
+ guard AXValueGetValue(positionValue as! AXValue, .cgPoint, &origin),
+ AXValueGetValue(sizeValue as! AXValue, .cgSize, &size) else { return nil }
+ return CGRect(origin: origin, size: size)
+ }
+
+ private static func matches(_ a: CGRect, _ b: CGRect) -> Bool {
+ abs(a.minX - b.minX) < 1 && abs(a.minY - b.minY) < 1
+ && abs(a.width - b.width) < 1 && abs(a.height - b.height) < 1
+ }
+}
diff --git a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
index e7b2a008..d8b4dff4 100644
--- a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift
@@ -54,6 +54,8 @@ public final class RecordingControlBarModel: ObservableObject {
@Published public var isBusy = false
@Published public var elapsedText = "0:00"
@Published public var canRecord = true
+ @Published public var windowWidth: Int?
+ @Published public var windowHeight: Int?
/// An inline hint under the bar (e.g. a permission prompt); `nil` hides it.
@Published public var statusMessage: String?
@@ -62,6 +64,8 @@ public final class RecordingControlBarModel: ObservableObject {
public var onRecord: (() -> Void)?
public var onStop: (() -> Void)?
public var onClose: (() -> Void)?
+ public var onRefreshWindowSize: (() -> Void)?
+ public var onResizeWindow: ((Int, Int) -> Void)?
public init() {}
@@ -85,7 +89,7 @@ public final class RecordingControlBarModel: ObservableObject {
public struct RecordingControlBarView: View {
/// Fixed panel size — the controller owns framing (`hostingView.sizingOptions = []`), so the bar
/// paints to a known rect rather than pushing its content size back to the window.
- public static let contentSize = CGSize(width: 500, height: 96)
+ public static let contentSize = CGSize(width: 620, height: 116)
/// The lane above the bar that holds the hovered control's name, plus the stack spacing under
/// it. The controller drops the panel by this much so the bar itself stays put.
@@ -93,6 +97,7 @@ public struct RecordingControlBarView: View {
@ObservedObject private var model: RecordingControlBarModel
@State private var hint: String?
+ @State private var showsWindowSize = false
public init(model: RecordingControlBarModel) {
self.model = model
@@ -106,7 +111,8 @@ public struct RecordingControlBarView: View {
Text(statusMessage)
.font(.system(size: 11))
.foregroundStyle(.secondary)
- .lineLimit(1)
+ .multilineTextAlignment(.center)
+ .lineLimit(2)
}
}
.frame(width: Self.contentSize.width, height: Self.contentSize.height, alignment: .top)
@@ -146,6 +152,7 @@ public struct RecordingControlBarView: View {
private var controls: some View {
HStack(spacing: 10) {
iconButton(symbol: "xmark", help: "Close") { model.onClose?() }
+ .disabled(model.isBusy)
Divider().frame(height: 22)
@@ -157,6 +164,9 @@ public struct RecordingControlBarView: View {
}
Divider().frame(height: 22)
audioInputPicker
+ if model.mode == .window {
+ windowSizeButton
+ }
}
Spacer(minLength: 4)
@@ -165,6 +175,32 @@ public struct RecordingControlBarView: View {
.padding(.horizontal, 14)
}
+ private var windowSizeButton: some View {
+ Button {
+ model.onRefreshWindowSize?()
+ showsWindowSize = true
+ } label: {
+ Label {
+ if let width = model.windowWidth, let height = model.windowHeight {
+ Text("\(width) × \(height)")
+ } else {
+ Text("— × —")
+ }
+ } icon: {
+ Image(systemName: "arrow.up.left.and.arrow.down.right")
+ }
+ .font(.system(size: 13))
+ .monospacedDigit()
+ .fixedSize()
+ }
+ .buttonStyle(.plain)
+ .disabled(model.isBusy || !model.canRecord)
+ .popover(isPresented: $showsWindowSize, arrowEdge: .top) {
+ RecordingWindowSizeView(model: model)
+ }
+ .hoverHint("Window Dimensions in Points · Click to Resize", into: $hint)
+ }
+
private var recordingStatus: some View {
HStack(spacing: 8) {
Circle()
@@ -190,6 +226,7 @@ public struct RecordingControlBarView: View {
.foregroundStyle(isActive ? Color.white : Color.primary)
}
.buttonStyle(.plain)
+ .disabled(model.isBusy)
.hoverHint(mode.tooltip, into: $hint)
}
diff --git a/apps/Donkey/Sources/DonkeyUI/RecordingWindowSizeView.swift b/apps/Donkey/Sources/DonkeyUI/RecordingWindowSizeView.swift
new file mode 100644
index 00000000..f95d03a1
--- /dev/null
+++ b/apps/Donkey/Sources/DonkeyUI/RecordingWindowSizeView.swift
@@ -0,0 +1,90 @@
+import SwiftUI
+
+struct RecordingWindowSizeView: View {
+ @ObservedObject var model: RecordingControlBarModel
+ @State private var width = ""
+ @State private var height = ""
+
+ private struct Preset: Identifiable {
+ let id: String
+ let width: Int
+ let height: Int
+ }
+
+ private static let presets = [
+ Preset(id: "9:16 · Portrait", width: 540, height: 960),
+ Preset(id: "3:4 · Portrait with sidebar", width: 720, height: 960),
+ Preset(id: "1:1 · Square", width: 800, height: 800),
+ Preset(id: "4:3 · Landscape", width: 960, height: 720),
+ Preset(id: "16:9 · Widescreen", width: 1280, height: 720)
+ ]
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ Text("Window size").font(.headline)
+ Text("Dimensions include the title bar and use screen points. Retina recordings have more pixels.")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ ForEach(Self.presets) { preset in
+ Button {
+ width = String(preset.width)
+ height = String(preset.height)
+ model.onResizeWindow?(preset.width, preset.height)
+ } label: {
+ HStack {
+ Text(preset.id)
+ Spacer()
+ Text("\(preset.width) × \(preset.height)").monospacedDigit()
+ }
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .disabled(model.isBusy)
+ }
+ Divider()
+ HStack(alignment: .bottom, spacing: 8) {
+ dimensionField("Width", text: $width)
+ dimensionField("Height", text: $height)
+ Button("Apply") { applyCustomSize() }
+ .disabled(model.isBusy || customSize == nil)
+ }
+ if let width = model.windowWidth, let height = model.windowHeight {
+ Text("Current: \(width) × \(height) pt")
+ .font(.caption.monospacedDigit())
+ }
+ if model.isBusy {
+ ProgressView().controlSize(.small)
+ }
+ if let message = model.statusMessage {
+ Text(message).font(.caption).foregroundStyle(.secondary)
+ }
+ }
+ .padding(16)
+ .frame(width: 340)
+ .onAppear {
+ width = model.windowWidth.map(String.init) ?? "720"
+ height = model.windowHeight.map(String.init) ?? "960"
+ }
+ }
+
+ private var customSize: (Int, Int)? {
+ guard let width = Int(width), let height = Int(height), width > 0, height > 0 else { return nil }
+ return (width, height)
+ }
+
+ private func dimensionField(_ label: String, text: Binding<String>) -> some View {
+ VStack(alignment: .leading, spacing: 4) {
+ Text(label).font(.caption).foregroundStyle(.secondary)
+ TextField(label, text: text)
+ .textFieldStyle(.roundedBorder)
+ .accessibilityLabel("Window \(label.lowercased()) in points")
+ .onSubmit { applyCustomSize() }
+ .disabled(model.isBusy)
+ }
+ }
+
+ private func applyCustomSize() {
+ guard !model.isBusy, let (width, height) = customSize else { return }
+ model.onResizeWindow?(width, height)
+ }
+}
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingWindowResizerTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingWindowResizerTests.swift
new file mode 100644
index 00000000..c4cb08df
--- /dev/null
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/RecordingWindowResizerTests.swift
@@ -0,0 +1,46 @@
+import CoreGraphics
+import Testing
+@testable import DonkeyRuntime
+
+struct RecordingWindowResizerTests {
+ @Test func movesWindowInsideDisplayBeforeGrowing() throws {
+ let result = try RecordingWindowResizer.targetFrame(
+ current: CGRect(x: 1200, y: 700, width: 300, height: 300),
+ size: CGSize(width: 720, height: 960),
+ visibleFrames: [CGRect(x: 0, y: 25, width: 1728, height: 1050)]
+ )
+ #expect(result == CGRect(x: 1008, y: 115, width: 720, height: 960))
+ }
+
+ @Test func usesSelectedWindowsDisplayWithNegativeCoordinates() throws {
+ let result = try RecordingWindowResizer.targetFrame(
+ current: CGRect(x: -1200, y: -700, width: 900, height: 700),
+ size: CGSize(width: 540, height: 960),
+ visibleFrames: [
+ CGRect(x: 0, y: 25, width: 1728, height: 1050),
+ CGRect(x: -1440, y: -900, width: 1440, height: 1100)
+ ]
+ )
+ #expect(result == CGRect(x: -1200, y: -760, width: 540, height: 960))
+ }
+
+ @Test func keepsOriginWhenRequestedSizeFits() throws {
+ let result = try RecordingWindowResizer.targetFrame(
+ current: CGRect(x: 100, y: 100, width: 1200, height: 800),
+ size: CGSize(width: 720, height: 960),
+ visibleFrames: [CGRect(x: 0, y: 25, width: 1728, height: 1050)]
+ )
+ #expect(result == CGRect(x: 100, y: 100, width: 720, height: 960))
+ }
+
+ @Test(arguments: [CGSize(width: 540, height: 1920), CGSize(width: 0, height: 960), CGSize(width: -1, height: 960)])
+ func rejectsInvalidOrOversizedDimensions(size: CGSize) {
+ #expect(throws: RecordingWindowResizeError.self) {
+ try RecordingWindowResizer.targetFrame(
+ current: CGRect(x: 100, y: 100, width: 900, height: 700),
+ size: size,
+ visibleFrames: [CGRect(x: 0, y: 25, width: 1728, height: 1050)]
+ )
+ }
+ }
+}
diff --git a/docs/guides/swift.md b/docs/guides/swift.md
index 11367a78..a8107a84 100644
--- a/docs/guides/swift.md
+++ b/docs/guides/swift.md
@@ -23,12 +23,9 @@ the recorder. Name files after their MVC role when a feature grows past one
screen: `FeatureModel.swift`, `FeatureRootView.swift`,
`FeatureController.swift`.
-Screen recording follows this split: the recorder and its destination types
-hold the capture state; the control bar view renders it; controllers own the
-AppKit-only work such as the control bar panel, the region and window pickers,
-and screen positioning; the app delegate bootstraps the feature and the menu
-bar without owning product behavior. The stream draws the pointer straight
-into the video.
+Recording controllers own pickers and window geometry; the runtime captures
+video and the pointer. Window mode offers preset and custom sizes in screen
+points through Accessibility; app minimum sizes appear in the controls.
## Language