summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-03-10 00:51:46 +0100
committerder richter <der.richter@gmx.de>2024-03-14 23:33:15 +0100
commit055e9cd93e96b4310618a25e990221d73f4efb03 (patch)
treee5fefd48928f9e9aec90a51e0109752515f3bf83 /video/out
parentf3e5fea4f55e21f2f29874552a547fd5c75e629d (diff)
downloadmpv-055e9cd93e96b4310618a25e990221d73f4efb03.tar.bz2
mpv-055e9cd93e96b4310618a25e990221d73f4efb03.tar.xz
mac/helper: move input ctx related functionality into new input helper
also make functions thread safe.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/cocoa_cb_common.swift1
-rw-r--r--video/out/mac/common.swift1
-rw-r--r--video/out/mac/view.swift31
-rw-r--r--video/out/mac/window.swift7
-rw-r--r--video/out/mac_common.swift1
5 files changed, 23 insertions, 18 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift
index 2b260a2999..46e999fbb2 100644
--- a/video/out/cocoa_cb_common.swift
+++ b/video/out/cocoa_cb_common.swift
@@ -40,6 +40,7 @@ class CocoaCB: Common {
func preinit(_ vo: UnsafeMutablePointer<vo>) {
mpv = MPVHelper(vo, log)
+ input = InputHelper(vo.pointee.input_ctx, mpv)
if backendState == .uninitialized {
backendState = .needsInit
diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift
index 5790d3b844..e0ea5f1164 100644
--- a/video/out/mac/common.swift
+++ b/video/out/mac/common.swift
@@ -20,6 +20,7 @@ import IOKit.pwr_mgt
class Common: NSObject {
var mpv: MPVHelper?
+ var input: InputHelper?
var log: LogHelper
let queue: DispatchQueue = DispatchQueue(label: "io.mpv.queue")
diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift
index 89a2bc88ea..433284188c 100644
--- a/video/out/mac/view.swift
+++ b/video/out/mac/view.swift
@@ -20,6 +20,7 @@ import Cocoa
class View: NSView, CALayerDelegate {
unowned var common: Common
var mpv: MPVHelper? { get { return common.mpv } }
+ var input: InputHelper? { get { return common.input } }
var tracker: NSTrackingArea?
var hasMouseDown: Bool = false
@@ -81,7 +82,7 @@ class View: NSView, CALayerDelegate {
if types.contains(.fileURL) || types.contains(.URL) {
if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] {
let files = urls.map { $0.absoluteString }
- mpv?.open(files: files)
+ input?.open(files: files)
return true
}
} else if types.contains(.string) {
@@ -97,7 +98,7 @@ class View: NSView, CALayerDelegate {
filesArray.append(path)
}
}
- mpv?.open(files: filesArray)
+ input?.open(files: filesArray)
return true
}
return false
@@ -116,14 +117,14 @@ class View: NSView, CALayerDelegate {
}
override func mouseEntered(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_ENTER, 0)
}
common.updateCursorVisibility()
}
override func mouseExited(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
cocoa_put_key_with_modifiers(SWIFT_KEY_MOUSE_LEAVE, 0)
}
common.titleBar?.hide()
@@ -131,51 +132,51 @@ class View: NSView, CALayerDelegate {
}
override func mouseMoved(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseMovement(event)
}
common.titleBar?.show()
}
override func mouseDragged(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseMovement(event)
}
}
override func mouseDown(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func mouseUp(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseUp(event)
}
common.window?.isMoving = false
}
override func rightMouseDown(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func rightMouseUp(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseUp(event)
}
}
override func otherMouseDown(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseDown(event)
}
}
override func otherMouseUp(with event: NSEvent) {
- if mpv?.mouseEnabled() ?? true {
+ if input?.mouseEnabled() ?? true {
signalMouseUp(event)
}
}
@@ -211,7 +212,7 @@ class View: NSView, CALayerDelegate {
common.window?.updateMovableBackground(point)
if !(common.window?.isMoving ?? false) {
- mpv?.setMousePosition(point)
+ input?.setMouse(position: point)
}
}
@@ -227,11 +228,11 @@ class View: NSView, CALayerDelegate {
cmd = delta > 0 ? SWIFT_WHEEL_LEFT : SWIFT_WHEEL_RIGHT
}
- mpv?.putAxis(cmd, modifiers: event.modifierFlags, delta: abs(delta))
+ input?.putAxis(cmd, modifiers: event.modifierFlags, delta: abs(delta))
}
override func scrollWheel(with event: NSEvent) {
- if !(mpv?.mouseEnabled() ?? true) {
+ if !(input?.mouseEnabled() ?? true) {
return
}
diff --git a/video/out/mac/window.swift b/video/out/mac/window.swift
index 1fbb2374ec..26c0a44d83 100644
--- a/video/out/mac/window.swift
+++ b/video/out/mac/window.swift
@@ -20,6 +20,7 @@ import Cocoa
class Window: NSWindow, NSWindowDelegate {
weak var common: Common! = nil
var mpv: MPVHelper? { get { return common.mpv } }
+ var input: InputHelper? { get { return common.input } }
var targetScreen: NSScreen?
var previousScreen: NSScreen?
@@ -335,7 +336,7 @@ class Window: NSWindow, NSWindowDelegate {
func updateMovableBackground(_ pos: NSPoint) {
if !isInFullscreen {
- isMovableByWindowBackground = mpv?.canBeDraggedAt(pos) ?? true
+ isMovableByWindowBackground = input?.draggable(at: pos) ?? true
} else {
isMovableByWindowBackground = false
}
@@ -503,12 +504,12 @@ class Window: NSWindow, NSWindowDelegate {
@objc func setDoubleWindowSize() { setWindowScale(2.0) }
func setWindowScale(_ scale: Double) {
- mpv?.command("set window-scale \(scale)")
+ input?.command("set window-scale \(scale)")
}
func addWindowScale(_ scale: Double) {
if !isInFullscreen {
- mpv?.command("add window-scale \(scale)")
+ input?.command("add window-scale \(scale)")
}
}
diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift
index f7b07596d3..00328ccad1 100644
--- a/video/out/mac_common.swift
+++ b/video/out/mac_common.swift
@@ -28,6 +28,7 @@ class MacCommon: Common {
let newlog = mp_log_new(vo, vo.pointee.log, "mac")
super.init(newlog)
mpv = MPVHelper(vo, log)
+ input = InputHelper(vo.pointee.input_ctx, mpv)
timer = PreciseTimer(common: self)
DispatchQueue.main.sync {