surfaceview as transferable

This commit is contained in:
Mitchell Hashimoto
2025-12-26 14:23:55 -08:00
parent 88adffd734
commit 57bb636655
2 changed files with 24 additions and 10 deletions

View File

@@ -0,0 +1,20 @@
import CoreTransferable
import UniformTypeIdentifiers
extension Ghostty.SurfaceView: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(contentType: .ghosttySurfaceId) { surface in
withUnsafeBytes(of: surface.id.uuid) { Data($0) }
} importing: { data in
throw TransferError.importNotSupported
}
}
enum TransferError: Error {
case importNotSupported
}
}
extension UTType {
static let ghosttySurfaceId = UTType(exportedAs: "com.mitchellh.ghosttySurfaceId")
}

View File

@@ -227,7 +227,7 @@ extension Ghostty {
// Grab handle for dragging the window. We want this to appear at the very
// top Z-index os it isn't faded by the unfocused overlay.
SurfaceGrabHandle()
SurfaceGrabHandle(surfaceView: surfaceView)
}
}
@@ -961,6 +961,8 @@ extension Ghostty {
struct SurfaceGrabHandle: View {
private let handleHeight: CGFloat = 10
let surfaceView: SurfaceView
@State private var isHovering: Bool = false
@State private var isDragging: Bool = false
@@ -982,20 +984,12 @@ extension Ghostty {
isHovering = hovering
}
}
.gesture(
DragGesture()
.onChanged { _ in
isDragging = true
}
.onEnded { _ in
isDragging = false
}
)
.backport.pointerStyle(isHovering ? .grabIdle : nil)
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.draggable(surfaceView)
}
}