mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 05:50:27 +00:00
macos: use preference key to detect self dragging
This commit is contained in:
@@ -92,6 +92,7 @@ fileprivate struct TerminalSplitLeaf: View {
|
||||
let action: (TerminalSplitOperation) -> Void
|
||||
|
||||
@State private var dropState: DropState = .idle
|
||||
@State private var isSelfDragging: Bool = false
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
@@ -105,11 +106,15 @@ fileprivate struct TerminalSplitLeaf: View {
|
||||
action: action
|
||||
))
|
||||
.overlay {
|
||||
if case .dropping(let zone) = dropState {
|
||||
if !isSelfDragging, case .dropping(let zone) = dropState {
|
||||
zone.overlay(in: geometry)
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
.onPreferenceChange(Ghostty.DraggingSurfaceKey.self) { value in
|
||||
Ghostty.logger.warning("BABY WE DRAGGING \(String(describing: value))")
|
||||
isSelfDragging = value == surfaceView.id
|
||||
}
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel("Terminal pane")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
extension Ghostty {
|
||||
/// A preference key that propagates the ID of the SurfaceView currently being dragged,
|
||||
/// or nil if no surface is being dragged.
|
||||
struct DraggingSurfaceKey: PreferenceKey {
|
||||
static var defaultValue: SurfaceView.ID? = nil
|
||||
|
||||
static func reduce(value: inout SurfaceView.ID?, nextValue: () -> SurfaceView.ID?) {
|
||||
value = nextValue() ?? value
|
||||
}
|
||||
}
|
||||
|
||||
/// A grab handle overlay at the top of the surface for dragging the window.
|
||||
/// Only appears when hovering in the top region of the surface.
|
||||
struct SurfaceGrabHandle: View {
|
||||
@@ -38,6 +48,7 @@ extension Ghostty {
|
||||
.draggable(surfaceView) {
|
||||
SurfaceDragPreview(surfaceView: surfaceView, scale: previewScale)
|
||||
}
|
||||
.preference(key: DraggingSurfaceKey.self, value: isDragging ? surfaceView.id : nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user