fix(panel): drag the window manually and make the whole header a drag bar
performDrag did nothing while the app was inactive (verified: mouseDown reached the drag view, performDrag returned, the frame never changed). Move the window from the screen-space mouse delta in mouseDown/mouseDragged instead. Make the header a full-width 56 pt bar flush with the panel top, with the drag view behind it and the language/gear buttons above, so the whole top area moves the panel. Verified: make verify green; synthetic drags from the title, top edge, empty header and grip moved the panel by the full delta while Finder was frontmost; body drag does not move it.
This commit is contained in:
1 parent
f8064ac430
commit
d126124f97
4 files changed
+75
-44
No files matched your search
@@ -2,7 +2,8 @@ import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// An AppKit drag surface for the non-activating panel. SwiftUI's hosting view consumes mouse
|
||||
/// events, so this view starts a native window drag on the first click.
|
||||
/// events, and `performDrag` is unreliable while the app is inactive, so the view moves the
|
||||
/// window itself from the screen-space mouse delta.
|
||||
struct WindowDragArea: NSViewRepresentable {
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
DragView()
|
||||
@@ -12,8 +13,11 @@ struct WindowDragArea: NSViewRepresentable {
|
||||
}
|
||||
|
||||
private final class DragView: NSView {
|
||||
private var startMouse = NSPoint.zero
|
||||
private var startOrigin = NSPoint.zero
|
||||
|
||||
override var mouseDownCanMoveWindow: Bool {
|
||||
true
|
||||
false
|
||||
}
|
||||
|
||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
|
||||
@@ -21,7 +25,25 @@ private final class DragView: NSView {
|
||||
}
|
||||
|
||||
override func mouseDown(with event: NSEvent) {
|
||||
window?.performDrag(with: event)
|
||||
guard let window else { return }
|
||||
startMouse = NSEvent.mouseLocation
|
||||
startOrigin = window.frame.origin
|
||||
NSCursor.closedHand.push()
|
||||
}
|
||||
|
||||
override func mouseDragged(with event: NSEvent) {
|
||||
guard let window else { return }
|
||||
let mouse = NSEvent.mouseLocation
|
||||
window.setFrameOrigin(
|
||||
NSPoint(
|
||||
x: startOrigin.x + mouse.x - startMouse.x,
|
||||
y: startOrigin.y + mouse.y - startMouse.y
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override func mouseUp(with event: NSEvent) {
|
||||
NSCursor.pop()
|
||||
}
|
||||
|
||||
override func resetCursorRects() {
|
||||
|
||||
Reference in new issue
Block a user