From 639ef09807cf77977a0f0767d2379d767ae56180 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 24 Nov 2024 20:29:46 +0100 Subject: [PATCH] mac: implement VOCTRL_BEGIN_DRAGGING this removes the old isMovableByWindowBackground mechanism with the newer performDrag(with:) function. --- DOCS/man/input.rst | 5 +++-- video/out/mac/common.swift | 5 +++-- video/out/mac/view.swift | 3 ++- video/out/mac/window.swift | 12 +++++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 45f0e4c9fa..69ccb2db81 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1558,8 +1558,9 @@ Miscellaneous Commands Begin window dragging if supported by the current VO. This command should only be called while a mouse button is being pressed, otherwise it will be ignored. The exact effect of this command depends on the VO implementation - of window dragging. For example, on Windows only the left mouse button can - begin window dragging, while X11 and Wayland allow other mouse buttons. + of window dragging. For example, on Windows and macOS only the left mouse + button can begin window dragging, while X11 and Wayland allow other mouse + buttons. ``context-menu`` Show context menu on the video window. See `Context Menu`_ section for details. diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 9b123b9cdd..1eaee3b233 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -139,8 +139,6 @@ class Common: NSObject { DispatchQueue.main.async { self.window?.toggleFullScreen(nil) } - } else { - window?.isMovableByWindowBackground = true } } @@ -647,6 +645,9 @@ class Common: NSObject { self.title = title } return VO_TRUE + case VOCTRL_BEGIN_DRAGGING: + self.window?.startDragging() + return VO_TRUE default: return VO_NOTIMPL } diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift index b82151ba96..f303c84c06 100644 --- a/video/out/mac/view.swift +++ b/video/out/mac/view.swift @@ -23,6 +23,7 @@ class View: NSView, CALayerDelegate { var tracker: NSTrackingArea? var hasMouseDown: Bool = false + var lastMouseDownEvent: NSEvent? override var isFlipped: Bool { return true } override var acceptsFirstResponder: Bool { return true } @@ -137,6 +138,7 @@ class View: NSView, CALayerDelegate { override func mouseDown(with event: NSEvent) { hasMouseDown = event.clickCount <= 1 input?.processMouse(event: event) + lastMouseDownEvent = event } override func mouseUp(with event: NSEvent) { @@ -176,7 +178,6 @@ class View: NSView, CALayerDelegate { point = convertToBacking(point) point.y = -point.y - common.window?.updateMovableBackground(point) if !(common.window?.isMoving ?? false) { input?.setMouse(position: point) } diff --git a/video/out/mac/window.swift b/video/out/mac/window.swift index 6ca5d2128d..e5b0abf66a 100644 --- a/video/out/mac/window.swift +++ b/video/out/mac/window.swift @@ -332,11 +332,13 @@ class Window: NSWindow, NSWindowDelegate { zoom(self) } - func updateMovableBackground(_ pos: NSPoint) { - if !isInFullscreen { - isMovableByWindowBackground = input?.draggable(at: pos) ?? true - } else { - isMovableByWindowBackground = false + func startDragging() { + guard let view = common.view, let event = view.lastMouseDownEvent else { return } + var pos = view.convert(event.locationInWindow, from: nil) + pos = convertPointToBacking(pos) + + if input?.draggable(at: pos) ?? true { + performDrag(with: event) } }