summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2023-12-09 17:23:45 +0100
committerder richter <der.richter@gmx.de>2023-12-15 16:59:52 +0100
commitc661435648fe36aa4b516fac9f5faf745630ebc5 (patch)
tree111181a94ce326eb684db2651467bac900e38a8c /osdep
parent8ceaec174237bb033ec1ea599beeda9fbd373c2e (diff)
downloadmpv-c661435648fe36aa4b516fac9f5faf745630ebc5.tar.bz2
mpv-c661435648fe36aa4b516fac9f5faf745630ebc5.tar.xz
mac: add support for drag-and-drop option
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macOS_swift_bridge.h1
-rw-r--r--osdep/macos/mpv_helper.swift14
2 files changed, 15 insertions, 0 deletions
diff --git a/osdep/macOS_swift_bridge.h b/osdep/macOS_swift_bridge.h
index 9407b6fc9b..72be85274a 100644
--- a/osdep/macOS_swift_bridge.h
+++ b/osdep/macOS_swift_bridge.h
@@ -27,6 +27,7 @@
#include "options/m_config.h"
#include "player/core.h"
#include "input/input.h"
+#include "input/event.h"
#include "video/out/win_state.h"
#include "osdep/macosx_application_objc.h"
diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift
index 532a5f723c..53ef4cb521 100644
--- a/osdep/macos/mpv_helper.swift
+++ b/osdep/macos/mpv_helper.swift
@@ -75,6 +75,20 @@ class MPVHelper {
return m_config_cache_get_next_changed(optsCachePtr, &property)
}
+ func open(files: [String]) {
+ if opts.drag_and_drop == -2 { return }
+
+ var action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE
+ if opts.drag_and_drop >= 0 {
+ action = mp_dnd_action(UInt32(opts.drag_and_drop))
+ }
+
+ let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }
+ var filesPtr = filesClean.map { UnsafeMutablePointer<CChar>(strdup($0)) }
+ mp_event_drop_files(input, Int32(files.count), &filesPtr, action)
+ for charPtr in filesPtr { free(UnsafeMutablePointer(mutating: charPtr)) }
+ }
+
func setOption(fullscreen: Bool) {
optsPtr.pointee.fullscreen = fullscreen
_ = withUnsafeMutableBytes(of: &optsPtr.pointee.fullscreen) { (ptr: UnsafeMutableRawBufferPointer) in