mac: add support for drag-and-drop option

This commit is contained in:
der richter 2023-12-09 17:23:45 +01:00
parent 8ceaec1742
commit c661435648
4 changed files with 17 additions and 3 deletions

View File

@ -3172,7 +3172,6 @@ Window
(Windows only) Snap the player window to screen edges. (Windows only) Snap the player window to screen edges.
``--drag-and-drop=<no|auto|replace|append>`` ``--drag-and-drop=<no|auto|replace|append>``
(X11, Wayland and Windows only)
Controls the default behavior of drag and drop on platforms that support this. Controls the default behavior of drag and drop on platforms that support this.
``auto`` will obey what the underlying os/platform gives mpv. Typically, holding ``auto`` will obey what the underlying os/platform gives mpv. Typically, holding
shift during the drag and drop will append the item to the playlist. Otherwise, shift during the drag and drop will append the item to the playlist. Otherwise,

View File

@ -27,6 +27,7 @@
#include "options/m_config.h" #include "options/m_config.h"
#include "player/core.h" #include "player/core.h"
#include "input/input.h" #include "input/input.h"
#include "input/event.h"
#include "video/out/win_state.h" #include "video/out/win_state.h"
#include "osdep/macosx_application_objc.h" #include "osdep/macosx_application_objc.h"

View File

@ -75,6 +75,20 @@ class MPVHelper {
return m_config_cache_get_next_changed(optsCachePtr, &property) 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) { func setOption(fullscreen: Bool) {
optsPtr.pointee.fullscreen = fullscreen optsPtr.pointee.fullscreen = fullscreen
_ = withUnsafeMutableBytes(of: &optsPtr.pointee.fullscreen) { (ptr: UnsafeMutableRawBufferPointer) in _ = withUnsafeMutableBytes(of: &optsPtr.pointee.fullscreen) { (ptr: UnsafeMutableRawBufferPointer) in

View File

@ -81,7 +81,7 @@ class View: NSView {
if types.contains(.fileURL) || types.contains(.URL) { if types.contains(.fileURL) || types.contains(.URL) {
if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] { if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] {
let files = urls.map { $0.absoluteString } let files = urls.map { $0.absoluteString }
EventsResponder.sharedInstance().handleFilesArray(files) mpv?.open(files: files)
return true return true
} }
} else if types.contains(.string) { } else if types.contains(.string) {
@ -97,7 +97,7 @@ class View: NSView {
filesArray.append(path) filesArray.append(path)
} }
} }
EventsResponder.sharedInstance().handleFilesArray(filesArray) mpv?.open(files: filesArray)
return true return true
} }
return false return false