From 6d0f0546ee851f4106438c5b92c8d1d152937ea7 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 29 Sep 2019 18:35:12 +0200 Subject: cocoa-cb: remove get_property_* usages and split up mpv helper all the get_property_* usages were removed because in some circumstances they can lead to deadlocks. they were replaced by accessing the vo and mp_vo_opts structs directly, like on other vos. additionally the mpv helper was split into a mpv and libmpv helper, to differentiate between private and public APIs and for future changes like a macOS vulkan context for vo=gpu. --- video/out/cocoa-cb/window.swift | 48 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'video/out/cocoa-cb/window.swift') diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift index 2f87711d22..1ac0e2bc78 100644 --- a/video/out/cocoa-cb/window.swift +++ b/video/out/cocoa-cb/window.swift @@ -20,7 +20,8 @@ import Cocoa class Window: NSWindow, NSWindowDelegate { weak var cocoaCB: CocoaCB! = nil - var mpv: MPVHelper { get { return cocoaCB.mpv } } + var mpv: MPVHelper? { get { return cocoaCB.mpv } } + var libmpv: LibmpvHelper { get { return cocoaCB.libmpv } } var targetScreen: NSScreen? var previousScreen: NSScreen? @@ -134,7 +135,7 @@ class Window: NSWindow, NSWindowDelegate { setFrame(frame, display: true) } - if mpv.getBoolProperty("native-fs") { + if Bool(mpv?.opts.native_fs ?? 1) { super.toggleFullScreen(sender) } else { if !isInFullscreen { @@ -245,48 +246,35 @@ class Window: NSWindow, NSWindowDelegate { cocoaCB.layer?.update() } - func getFsAnimationDuration(_ def: Double) -> Double{ - let duration = mpv.getStringProperty("macos-fs-animation-duration") ?? "default" - if duration == "default" { + func getFsAnimationDuration(_ def: Double) -> Double { + let duration = libmpv.macOpts.macos_fs_animation_duration + if duration < 0 { return def } else { - return (Double(duration) ?? 0.2)/1000 + return Double(duration)/1000 } } - func setOnTop(_ state: Bool, _ ontopLevel: Any) { - let stdLevel: NSWindow.Level = .normal - + func setOnTop(_ state: Bool, _ ontopLevel: Int) { if state { - if ontopLevel is Int { - switch ontopLevel as? Int { - case .some(-1): - level = .floating - case .some(-2): - level = .statusBar + 1 - default: - level = NSWindow.Level(ontopLevel as? Int ?? stdLevel.rawValue) - } - } else { - switch ontopLevel as? String { - case .some("window"): - level = .floating - case .some("system"): - level = .statusBar + 1 - default: - level = NSWindow.Level(Int(ontopLevel as? String ?? "") ?? stdLevel.rawValue) - } + switch ontopLevel { + case -1: + level = .floating + case -2: + level = .statusBar + 1 + default: + level = NSWindow.Level(ontopLevel) } collectionBehavior.remove(.transient) collectionBehavior.insert(.managed) } else { - level = stdLevel + level = .normal } } func updateMovableBackground(_ pos: NSPoint) { if !isInFullscreen { - isMovableByWindowBackground = mpv.canBeDraggedAt(pos) + isMovableByWindowBackground = mpv?.canBeDraggedAt(pos) ?? true } else { isMovableByWindowBackground = false } @@ -448,7 +436,7 @@ class Window: NSWindow, NSWindowDelegate { @objc func setDoubleWindowSize() { setWindowScale(2.0) } func setWindowScale(_ scale: Double) { - mpv.commandAsync(["osd-auto", "set", "window-scale", "\(scale)"]) + mpv?.command("set window-scale \(scale)") } func windowDidChangeScreen(_ notification: Notification) { -- cgit v1.2.3