Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac: implement VOCTRL_BEGIN_DRAGGING #15377

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions video/out/mac/common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ class Common: NSObject {
DispatchQueue.main.async {
self.window?.toggleFullScreen(nil)
}
} else {
window?.isMovableByWindowBackground = true
}
}

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion video/out/mac/view.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 7 additions & 5 deletions video/out/mac/window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down