diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 50ebfd3c..67d8987d 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -7645,7 +7645,6 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { override func hitTest(_ point: NSPoint) -> NSView? { guard bounds.contains(point) else { return nil } - maybeDisableWindowDraggingEarly(trigger: "hitTest") let hit = super.hitTest(point) #if DEBUG let hitDesc = hit.map { String(describing: type(of: $0)) } ?? "nil" @@ -7685,9 +7684,9 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { override func mouseUp(with event: NSEvent) { super.mouseUp(with: event) - if !hasActiveDragSession { - restoreWindowMovableStateIfNeeded() - } + // Always restore suppression on mouse-up; drag-session callbacks can be + // skipped for non-started drags, which would otherwise leave suppression stuck. + restoreWindowMovableStateIfNeeded() } override func rightMouseDown(with event: NSEvent) { diff --git a/Sources/WindowDragHandleView.swift b/Sources/WindowDragHandleView.swift index ebc62a05..e9ce93f4 100644 --- a/Sources/WindowDragHandleView.swift +++ b/Sources/WindowDragHandleView.swift @@ -51,6 +51,16 @@ func isWindowDragSuppressed(window: NSWindow?) -> Bool { windowDragSuppressionDepth(window: window) > 0 } +@discardableResult +func clearWindowDragSuppression(window: NSWindow?) -> Int { + guard let window else { return 0 } + var depth = windowDragSuppressionDepth(window: window) + while depth > 0 { + depth = endWindowDragSuppression(window: window) + } + return depth +} + /// Temporarily enables window movability for explicit drag-handle drags, then /// restores the previous movability state after `body` finishes. @discardableResult @@ -98,13 +108,24 @@ func windowDragHandleShouldTreatTopHitAsPassiveHost(_ view: NSView) -> Bool { /// controls layered in the titlebar (e.g. proxy folder icon) keep their gestures. func windowDragHandleShouldCaptureHit(_ point: NSPoint, in dragHandleView: NSView) -> Bool { if isWindowDragSuppressed(window: dragHandleView.window) { + // Recover from stale suppression if a prior interaction missed cleanup. + // We only keep suppression active while the left mouse button is down. + if (NSEvent.pressedMouseButtons & 0x1) == 0 { + let clearedDepth = clearWindowDragSuppression(window: dragHandleView.window) + #if DEBUG + dlog( + "titlebar.dragHandle.hitTest suppressionRecovered clearedDepth=\(clearedDepth) point=\(windowDragHandleFormatPoint(point))" + ) + #endif + } else { #if DEBUG - let depth = windowDragSuppressionDepth(window: dragHandleView.window) - dlog( - "titlebar.dragHandle.hitTest capture=false reason=suppressed depth=\(depth) point=\(windowDragHandleFormatPoint(point))" - ) + let depth = windowDragSuppressionDepth(window: dragHandleView.window) + dlog( + "titlebar.dragHandle.hitTest capture=false reason=suppressed depth=\(depth) point=\(windowDragHandleFormatPoint(point))" + ) #endif - return false + return false + } } guard dragHandleView.bounds.contains(point) else {