Open source CapCut alternative.
TypeScript
feat(app): drag the screen recording bar from its background [rebuild]
David Le863e4e281e3f
diff --git a/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift b/apps/Donkey/Sources/Donkey/RecordingControlBarController.swiftindex 0ca6023b..ebfda1d4 100644--- a/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift+++ b/apps/Donkey/Sources/Donkey/RecordingControlBarController.swift@@ -2,9 +2,9 @@ import AppKitimport DonkeyUIimport SwiftUI-/// The floating QuickTime-style control bar, pinned center-bottom of a screen. A borderless,-/// non-activating panel so its buttons click without stealing focus from the app being recorded. The-/// controller owns framing (`hostingView.sizingOptions = []`) to avoid the SwiftUI layout re-entrancy+/// The floating QuickTime-style control bar, opening center-bottom of a screen and dragged anywhere+/// from its background. A borderless, non-activating panel so its buttons click without stealing+/// focus from the app being recorded. The controller owns framing (`hostingView.sizingOptions = []`) to avoid the SwiftUI layout re-entrancy/// crash the other overlays document.@MainActorfinal class RecordingControlBarController {@@ -58,8 +58,10 @@ final class RecordingControlBarController {self.hostingView = hostingView}+ /// Bring the bar to `screen`. On the screen it already sits on, it stays where the person+ /// dragged it.func reposition(on screen: NSScreen) {- guard let panel else { return }+ guard let panel, panel.screen != screen else { return }panel.setFrame(frame(for: panel.frame.size, on: screen), display: true)}diff --git a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swiftindex 4da65d69..e7b2a008 100644--- a/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift+++ b/apps/Donkey/Sources/DonkeyUI/RecordingControlBarView.swift@@ -128,6 +128,22 @@ public struct RecordingControlBarView: View {}private var bar: some View {+ // The drag area sits under the controls in the stack: a press off a control lands on it,+ // and the controls above keep their own clicks.+ ZStack {+ WindowDragArea()+ controls+ }+ .frame(height: 48)+ .background(+ Capsule().fill(.ultraThinMaterial)+ )+ .overlay(+ Capsule().strokeBorder(Color.white.opacity(0.08), lineWidth: 1)+ )+ }++ private var controls: some View {HStack(spacing: 10) {iconButton(symbol: "xmark", help: "Close") { model.onClose?() }@@ -147,13 +163,6 @@ public struct RecordingControlBarView: View {recordButton}.padding(.horizontal, 14)- .frame(height: 48)- .background(- Capsule().fill(.ultraThinMaterial)- )- .overlay(- Capsule().strokeBorder(Color.white.opacity(0.08), lineWidth: 1)- )}private var recordingStatus: some View {@@ -270,6 +279,23 @@ private extension View {}}+/// The bar's background moves its window: a press anywhere off a control drags the bar around the+/// screen. It takes the first click, so the drag works while Donkey sits inactive behind the app+/// being recorded.+private struct WindowDragArea: NSViewRepresentable {+ func makeNSView(context: Context) -> DragView { DragView() }++ func updateNSView(_ view: DragView, context: Context) {}++ final class DragView: NSView {+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }++ override func mouseDown(with event: NSEvent) {+ window?.performDrag(with: event)+ }+ }+}+/// Pointer enter/exit that fires with Donkey inactive. SwiftUI's `onHover` and AppKit's tooltips/// both wait on the active app; the tracking area asks for `.activeAlways` instead. The view hands/// every click straight through, so it reports on top of a button without taking its taps.