Files
Sprachmittler/App/Panel/WindowDragArea.swift
schihei d126124f97 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.
2026-11-26 15:03:31 +01:00

53 lines
1.4 KiB
Swift

import AppKit
import SwiftUI
/// An AppKit drag surface for the non-activating panel. SwiftUI's hosting view consumes mouse
/// 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()
}
func updateNSView(_ nsView: NSView, context: Context) {}
}
private final class DragView: NSView {
private var startMouse = NSPoint.zero
private var startOrigin = NSPoint.zero
override var mouseDownCanMoveWindow: Bool {
false
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
true
}
override func mouseDown(with event: NSEvent) {
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() {
addCursorRect(bounds, cursor: .openHand)
}
}