mac/option: move option functionality from mpv helper to option helper

delete now empty mpv helper
This commit is contained in:
der richter 2024-03-19 19:50:44 +01:00
parent 283d0877c4
commit dc5059d027
10 changed files with 99 additions and 99 deletions

View File

@ -1520,8 +1520,8 @@ if features['cocoa'] and features['swift']
swift_sources += files('osdep/mac/libmpv_helper.swift', swift_sources += files('osdep/mac/libmpv_helper.swift',
'osdep/mac/input_helper.swift', 'osdep/mac/input_helper.swift',
'osdep/mac/log_helper.swift', 'osdep/mac/log_helper.swift',
'osdep/mac/mpv_helper.swift',
'osdep/mac/menu_bar.swift', 'osdep/mac/menu_bar.swift',
'osdep/mac/option_helper.swift',
'osdep/mac/precise_timer.swift', 'osdep/mac/precise_timer.swift',
'osdep/mac/swift_compat.swift', 'osdep/mac/swift_compat.swift',
'osdep/mac/swift_extensions.swift', 'osdep/mac/swift_extensions.swift',

View File

@ -18,7 +18,7 @@
import Carbon.HIToolbox import Carbon.HIToolbox
class InputHelper: NSObject { class InputHelper: NSObject {
var mpv: MPVHelper? var option: OptionHelper?
var lock = NSCondition() var lock = NSCondition()
private var input: OpaquePointer? private var input: OpaquePointer?
@ -62,10 +62,10 @@ class InputHelper: NSObject {
.init(0, 0) .init(0, 0)
] ]
@objc init(_ input: OpaquePointer? = nil, _ mpv: MPVHelper? = nil) { @objc init(_ input: OpaquePointer? = nil, _ option: OptionHelper? = nil) {
super.init() super.init()
self.input = input self.input = input
self.mpv = mpv self.option = option
} }
@objc func put( @objc func put(
@ -232,11 +232,11 @@ class InputHelper: NSObject {
@objc func open(files: [String]) { @objc func open(files: [String]) {
lock.withLock { lock.withLock {
guard let input = input else { return } guard let input = input else { return }
if (mpv?.opts.drag_and_drop ?? -1) == -2 { return } if (option?.opts.drag_and_drop ?? -1) == -2 { return }
var action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE var action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE
if (mpv?.opts.drag_and_drop ?? -1) >= 0 { if (option?.opts.drag_and_drop ?? -1) >= 0 {
action = mp_dnd_action(UInt32(mpv?.opts.drag_and_drop ?? Int32(DND_REPLACE.rawValue))) action = mp_dnd_action(UInt32(option?.opts.drag_and_drop ?? Int32(DND_REPLACE.rawValue)))
} }
let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 } let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }

View File

@ -19,7 +19,7 @@ import Cocoa
typealias swift_wakeup_cb_fn = (@convention(c) (UnsafeMutableRawPointer?) -> Void)? typealias swift_wakeup_cb_fn = (@convention(c) (UnsafeMutableRawPointer?) -> Void)?
class MPVHelper: NSObject { class OptionHelper: NSObject {
var log: LogHelper var log: LogHelper
var vo: UnsafeMutablePointer<vo> var vo: UnsafeMutablePointer<vo>
var optsCachePtr: UnsafeMutablePointer<m_config_cache> var optsCachePtr: UnsafeMutablePointer<m_config_cache>

View File

@ -24,7 +24,7 @@ struct Timing {
class PreciseTimer { class PreciseTimer {
unowned var common: Common unowned var common: Common
var mpv: MPVHelper? { get { return common.mpv } } var option: OptionHelper? { get { return common.option } }
let nanoPerSecond: Double = 1e+9 let nanoPerSecond: Double = 1e+9
let machToNano: Double = { let machToNano: Double = {

View File

@ -39,8 +39,8 @@ class CocoaCB: Common {
} }
func preinit(_ vo: UnsafeMutablePointer<vo>) { func preinit(_ vo: UnsafeMutablePointer<vo>) {
mpv = MPVHelper(vo, log) option = OptionHelper(vo, log)
input = InputHelper(vo.pointee.input_ctx, mpv) input = InputHelper(vo.pointee.input_ctx, option)
if backendState == .uninitialized { if backendState == .uninitialized {
backendState = .needsInit backendState = .needsInit
@ -58,18 +58,18 @@ class CocoaCB: Common {
func uninit() { func uninit() {
window?.orderOut(nil) window?.orderOut(nil)
window?.close() window?.close()
mpv = nil option = nil
} }
func reconfig(_ vo: UnsafeMutablePointer<vo>) { func reconfig(_ vo: UnsafeMutablePointer<vo>) {
mpv?.vo = vo option?.vo = vo
if backendState == .needsInit { if backendState == .needsInit {
DispatchQueue.main.sync { self.initBackend(vo) } DispatchQueue.main.sync { self.initBackend(vo) }
} else if mpv?.opts.auto_window_resize ?? true { } else if option?.opts.auto_window_resize ?? true {
DispatchQueue.main.async { DispatchQueue.main.async {
self.updateWindowSize(vo) self.updateWindowSize(vo)
self.layer?.update(force: true) self.layer?.update(force: true)
if self.mpv?.opts.focus_on ?? 1 == 2 { if self.option?.opts.focus_on ?? 1 == 2 {
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
} }
} }
@ -204,7 +204,7 @@ class CocoaCB: Common {
func shutdown(_ destroy: Bool = false) { func shutdown(_ destroy: Bool = false) {
isShuttingDown = window?.isAnimating ?? false || isShuttingDown = window?.isAnimating ?? false ||
window?.isInFullscreen ?? false && mpv?.opts.native_fs ?? true window?.isInFullscreen ?? false && option?.opts.native_fs ?? true
if window?.isInFullscreen ?? false && !(window?.isAnimating ?? false) { if window?.isInFullscreen ?? false && !(window?.isAnimating ?? false) {
window?.close() window?.close()
} }

View File

@ -19,7 +19,7 @@ import Cocoa
import IOKit.pwr_mgt import IOKit.pwr_mgt
class Common: NSObject { class Common: NSObject {
var mpv: MPVHelper? var option: OptionHelper?
var input: InputHelper? var input: InputHelper?
var log: LogHelper var log: LogHelper
let queue: DispatchQueue = DispatchQueue(label: "io.mpv.queue") let queue: DispatchQueue = DispatchQueue(label: "io.mpv.queue")
@ -52,8 +52,8 @@ class Common: NSObject {
} }
func initMisc(_ vo: UnsafeMutablePointer<vo>) { func initMisc(_ vo: UnsafeMutablePointer<vo>) {
guard let mpv = mpv else { guard let option = option else {
log.sendError("Something went wrong, no MPVHelper was initialized") log.sendError("Something went wrong, no OptionHelper was initialized")
exit(1) exit(1)
} }
@ -61,17 +61,17 @@ class Common: NSObject {
initLightSensor() initLightSensor()
addDisplayReconfigureObserver() addDisplayReconfigureObserver()
addAppNotifications() addAppNotifications()
mpv.setMacOptionCallback(macOptsWakeupCallback, context: self) option.setMacOptionCallback(macOptsWakeupCallback, context: self)
} }
func initApp() { func initApp() {
guard let mpv = mpv else { guard let option = option else {
log.sendError("Something went wrong, no MPVHelper was initialized") log.sendError("Something went wrong, no OptionHelper was initialized")
exit(1) exit(1)
} }
var policy: NSApplication.ActivationPolicy = .regular var policy: NSApplication.ActivationPolicy = .regular
switch mpv.macOpts.macos_app_activation_policy { switch option.macOpts.macos_app_activation_policy {
case 0: case 0:
policy = .regular policy = .regular
case 1: case 1:
@ -87,7 +87,7 @@ class Common: NSObject {
} }
func initWindow(_ vo: UnsafeMutablePointer<vo>, _ previousActiveApp: NSRunningApplication?) { func initWindow(_ vo: UnsafeMutablePointer<vo>, _ previousActiveApp: NSRunningApplication?) {
let (mpv, targetScreen, wr) = getInitProperties(vo) let (option, targetScreen, wr) = getInitProperties(vo)
guard let view = self.view else { guard let view = self.view else {
log.sendError("Something went wrong, no View was initialized") log.sendError("Something went wrong, no View was initialized")
@ -100,16 +100,16 @@ class Common: NSObject {
exit(1) exit(1)
} }
window.setOnTop(Bool(mpv.opts.ontop), Int(mpv.opts.ontop_level)) window.setOnTop(Bool(option.opts.ontop), Int(option.opts.ontop_level))
window.setOnAllWorkspaces(Bool(mpv.opts.all_workspaces)) window.setOnAllWorkspaces(Bool(option.opts.all_workspaces))
window.keepAspect = Bool(mpv.opts.keepaspect_window) window.keepAspect = Bool(option.opts.keepaspect_window)
window.title = title window.title = title
window.border = Bool(mpv.opts.border) window.border = Bool(option.opts.border)
titleBar = TitleBar(frame: wr, window: window, common: self) titleBar = TitleBar(frame: wr, window: window, common: self)
let maximized = Bool(mpv.opts.window_maximized) let maximized = Bool(option.opts.window_maximized)
let minimized = Bool(mpv.opts.window_minimized) let minimized = Bool(option.opts.window_minimized)
window.isRestorable = false window.isRestorable = false
window.isReleasedWhenClosed = false window.isReleasedWhenClosed = false
window.setMaximized((minimized || !maximized) ? window.isZoomed : maximized) window.setMaximized((minimized || !maximized) ? window.isZoomed : maximized)
@ -123,10 +123,10 @@ class Common: NSObject {
window.orderFront(nil) window.orderFront(nil)
} }
NSApp.activate(ignoringOtherApps: mpv.opts.focus_on >= 1) NSApp.activate(ignoringOtherApps: option.opts.focus_on >= 1)
// workaround for macOS 10.15 to refocus the previous App // workaround for macOS 10.15 to refocus the previous App
if mpv.opts.focus_on == 0 { if option.opts.focus_on == 0 {
previousActiveApp?.activate() previousActiveApp?.activate()
} }
} }
@ -147,7 +147,7 @@ class Common: NSObject {
} }
func initWindowState() { func initWindowState() {
if mpv?.opts.fullscreen ?? false { if option?.opts.fullscreen ?? false {
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.toggleFullScreen(nil) self.window?.toggleFullScreen(nil)
} }
@ -184,7 +184,7 @@ class Common: NSObject {
guard let screen = getTargetScreen(forFullscreen: false) ?? NSScreen.main, guard let screen = getTargetScreen(forFullscreen: false) ?? NSScreen.main,
let link = self.link else let link = self.link else
{ {
log.sendWarning("Couldn't start DisplayLink, no MPVHelper, Screen or DisplayLink available") log.sendWarning("Couldn't start DisplayLink, no OptionHelper, Screen or DisplayLink available")
return return
} }
@ -409,14 +409,14 @@ class Common: NSObject {
} }
func getTargetScreen(forFullscreen fs: Bool) -> NSScreen? { func getTargetScreen(forFullscreen fs: Bool) -> NSScreen? {
guard let mpv = mpv else { guard let option = option else {
log.sendWarning("Unexpected nil value in getTargetScreen") log.sendWarning("Unexpected nil value in getTargetScreen")
return nil return nil
} }
let screenID = fs ? mpv.opts.fsscreen_id : mpv.opts.screen_id let screenID = fs ? option.opts.fsscreen_id : option.opts.screen_id
var name: String? var name: String?
if let screenName = fs ? mpv.opts.fsscreen_name : mpv.opts.screen_name { if let screenName = fs ? option.opts.fsscreen_name : option.opts.screen_name {
name = String(cString: screenName) name = String(cString: screenName)
} }
return getScreenBy(id: Int(screenID)) ?? getScreenBy(name: name) return getScreenBy(id: Int(screenID)) ?? getScreenBy(name: name)
@ -431,7 +431,7 @@ class Common: NSObject {
func getWindowGeometry(forScreen screen: NSScreen, func getWindowGeometry(forScreen screen: NSScreen,
videoOut vo: UnsafeMutablePointer<vo>) -> NSRect { videoOut vo: UnsafeMutablePointer<vo>) -> NSRect {
let r = screen.convertRectToBacking(screen.frame) let r = screen.convertRectToBacking(screen.frame)
let targetFrame = (mpv?.macOpts.macos_geometry_calculation ?? Int32(FRAME_VISIBLE)) == FRAME_VISIBLE let targetFrame = (option?.macOpts.macos_geometry_calculation ?? Int32(FRAME_VISIBLE)) == FRAME_VISIBLE
? screen.visibleFrame : screen.frame ? screen.visibleFrame : screen.frame
let rv = screen.convertRectToBacking(targetFrame) let rv = screen.convertRectToBacking(targetFrame)
@ -458,9 +458,9 @@ class Common: NSObject {
return screen.convertRectFromBacking(NSMakeRect(x, y, width, height)) return screen.convertRectFromBacking(NSMakeRect(x, y, width, height))
} }
func getInitProperties(_ vo: UnsafeMutablePointer<vo>) -> (MPVHelper, NSScreen, NSRect) { func getInitProperties(_ vo: UnsafeMutablePointer<vo>) -> (OptionHelper, NSScreen, NSRect) {
guard let mpv = mpv else { guard let option = option else {
log.sendError("Something went wrong, no MPVHelper was initialized") log.sendError("Something went wrong, no OptionHelper was initialized")
exit(1) exit(1)
} }
guard let targetScreen = getTargetScreen(forFullscreen: false) ?? NSScreen.main else { guard let targetScreen = getTargetScreen(forFullscreen: false) ?? NSScreen.main else {
@ -470,7 +470,7 @@ class Common: NSObject {
let wr = getWindowGeometry(forScreen: targetScreen, videoOut: vo) let wr = getWindowGeometry(forScreen: targetScreen, videoOut: vo)
return (mpv, targetScreen, wr) return (option, targetScreen, wr)
} }
// call before initApp, because on macOS +10.15 it changes the active App // call before initApp, because on macOS +10.15 it changes the active App
@ -483,7 +483,7 @@ class Common: NSObject {
events |= ev events |= ev
eventsLock.unlock() eventsLock.unlock()
guard let vout = mpv?.vo else { guard let vout = option?.vo else {
log.sendWarning("vo nil in flagEvents") log.sendWarning("vo nil in flagEvents")
return return
} }
@ -515,7 +515,7 @@ class Common: NSObject {
request: UInt32, request: UInt32,
data: UnsafeMutableRawPointer?) -> Int32 data: UnsafeMutableRawPointer?) -> Int32
{ {
guard let mpv = mpv else { guard let option = option else {
log.sendWarning("Unexpected nil value in Control Callback") log.sendWarning("Unexpected nil value in Control Callback")
return VO_FALSE return VO_FALSE
} }
@ -526,45 +526,45 @@ class Common: NSObject {
return VO_TRUE return VO_TRUE
case VOCTRL_VO_OPTS_CHANGED: case VOCTRL_VO_OPTS_CHANGED:
var opt: UnsafeMutableRawPointer? var opt: UnsafeMutableRawPointer?
while mpv.nextChangedOption(property: &opt) { while option.nextChangedOption(property: &opt) {
switch opt { switch opt {
case TypeHelper.toPointer(&mpv.optsPtr.pointee.border): case TypeHelper.toPointer(&option.optsPtr.pointee.border):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.border = Bool(mpv.opts.border) self.window?.border = Bool(option.opts.border)
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.fullscreen): case TypeHelper.toPointer(&option.optsPtr.pointee.fullscreen):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.toggleFullScreen(nil) self.window?.toggleFullScreen(nil)
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.ontop): fallthrough case TypeHelper.toPointer(&option.optsPtr.pointee.ontop): fallthrough
case TypeHelper.toPointer(&mpv.optsPtr.pointee.ontop_level): case TypeHelper.toPointer(&option.optsPtr.pointee.ontop_level):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.setOnTop(Bool(mpv.opts.ontop), Int(mpv.opts.ontop_level)) self.window?.setOnTop(Bool(option.opts.ontop), Int(option.opts.ontop_level))
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.all_workspaces): case TypeHelper.toPointer(&option.optsPtr.pointee.all_workspaces):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.setOnAllWorkspaces(Bool(mpv.opts.all_workspaces)) self.window?.setOnAllWorkspaces(Bool(option.opts.all_workspaces))
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.keepaspect_window): case TypeHelper.toPointer(&option.optsPtr.pointee.keepaspect_window):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.keepAspect = Bool(mpv.opts.keepaspect_window) self.window?.keepAspect = Bool(option.opts.keepaspect_window)
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.window_minimized): case TypeHelper.toPointer(&option.optsPtr.pointee.window_minimized):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.setMinimized(Bool(mpv.opts.window_minimized)) self.window?.setMinimized(Bool(option.opts.window_minimized))
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.window_maximized): case TypeHelper.toPointer(&option.optsPtr.pointee.window_maximized):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.setMaximized(Bool(mpv.opts.window_maximized)) self.window?.setMaximized(Bool(option.opts.window_maximized))
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.cursor_passthrough): case TypeHelper.toPointer(&option.optsPtr.pointee.cursor_passthrough):
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.ignoresMouseEvents = mpv.opts.cursor_passthrough self.window?.ignoresMouseEvents = option.opts.cursor_passthrough
} }
case TypeHelper.toPointer(&mpv.optsPtr.pointee.geometry): fallthrough case TypeHelper.toPointer(&option.optsPtr.pointee.geometry): fallthrough
case TypeHelper.toPointer(&mpv.optsPtr.pointee.autofit): fallthrough case TypeHelper.toPointer(&option.optsPtr.pointee.autofit): fallthrough
case TypeHelper.toPointer(&mpv.optsPtr.pointee.autofit_smaller): fallthrough case TypeHelper.toPointer(&option.optsPtr.pointee.autofit_smaller): fallthrough
case TypeHelper.toPointer(&mpv.optsPtr.pointee.autofit_larger): case TypeHelper.toPointer(&option.optsPtr.pointee.autofit_larger):
DispatchQueue.main.async { DispatchQueue.main.async {
let (_, _, wr) = self.getInitProperties(vo) let (_, _, wr) = self.getInitProperties(vo)
self.window?.updateFrame(wr) self.window?.updateFrame(wr)
@ -630,7 +630,7 @@ class Common: NSObject {
let sizeData = data!.assumingMemoryBound(to: Int32.self) let sizeData = data!.assumingMemoryBound(to: Int32.self)
let size = UnsafeMutableBufferPointer(start: sizeData, count: 2) let size = UnsafeMutableBufferPointer(start: sizeData, count: 2)
var rect = window?.unfsContentFrame ?? NSRect(x: 0, y: 0, width: 1280, height: 720) var rect = window?.unfsContentFrame ?? NSRect(x: 0, y: 0, width: 1280, height: 720)
if let screen = window?.currentScreen, !Bool(mpv.opts.hidpi_window_scale) { if let screen = window?.currentScreen, !Bool(option.opts.hidpi_window_scale) {
rect = screen.convertRectToBacking(rect) rect = screen.convertRectToBacking(rect)
} }
@ -642,7 +642,7 @@ class Common: NSObject {
let size = UnsafeBufferPointer(start: sizeData, count: 2) let size = UnsafeBufferPointer(start: sizeData, count: 2)
var rect = NSMakeRect(0, 0, CGFloat(size[0]), CGFloat(size[1])) var rect = NSMakeRect(0, 0, CGFloat(size[0]), CGFloat(size[1]))
DispatchQueue.main.async { DispatchQueue.main.async {
if let screen = self.window?.currentScreen, !Bool(self.mpv?.opts.hidpi_window_scale ?? true) { if let screen = self.window?.currentScreen, !Bool(self.option?.opts.hidpi_window_scale ?? true) {
rect = screen.convertRectFromBacking(rect) rect = screen.convertRectFromBacking(rect)
} }
self.window?.updateSize(rect.size) self.window?.updateSize(rect.size)
@ -692,20 +692,20 @@ class Common: NSObject {
} }
func macOptsUpdate() { func macOptsUpdate() {
guard let mpv = mpv else { guard let option = option else {
log.sendWarning("Unexpected nil value in mac opts update") log.sendWarning("Unexpected nil value in mac opts update")
return return
} }
var opt: UnsafeMutableRawPointer? var opt: UnsafeMutableRawPointer?
while mpv.nextChangedMacOption(property: &opt) { while option.nextChangedMacOption(property: &opt) {
switch opt { switch opt {
case TypeHelper.toPointer(&mpv.macOptsPtr.pointee.macos_title_bar_appearance): case TypeHelper.toPointer(&option.macOptsPtr.pointee.macos_title_bar_appearance):
titleBar?.set(appearance: Int(mpv.macOpts.macos_title_bar_appearance)) titleBar?.set(appearance: Int(option.macOpts.macos_title_bar_appearance))
case TypeHelper.toPointer(&mpv.macOptsPtr.pointee.macos_title_bar_material): case TypeHelper.toPointer(&option.macOptsPtr.pointee.macos_title_bar_material):
titleBar?.set(material: Int(mpv.macOpts.macos_title_bar_material)) titleBar?.set(material: Int(option.macOpts.macos_title_bar_material))
case TypeHelper.toPointer(&mpv.macOptsPtr.pointee.macos_title_bar_color): case TypeHelper.toPointer(&option.macOptsPtr.pointee.macos_title_bar_color):
titleBar?.set(color: mpv.macOpts.macos_title_bar_color) titleBar?.set(color: option.macOpts.macos_title_bar_color)
default: default:
break break
} }

View File

@ -19,7 +19,7 @@ import Cocoa
class TitleBar: NSVisualEffectView { class TitleBar: NSVisualEffectView {
unowned var common: Common unowned var common: Common
var mpv: MPVHelper? { get { return common.mpv } } var option: OptionHelper? { get { return common.option } }
var systemBar: NSView? { var systemBar: NSView? {
get { return common.window?.standardWindowButton(.closeButton)?.superview } get { return common.window?.standardWindowButton(.closeButton)?.superview }
@ -64,9 +64,9 @@ class TitleBar: NSVisualEffectView {
window.contentView?.addSubview(self, positioned: .above, relativeTo: nil) window.contentView?.addSubview(self, positioned: .above, relativeTo: nil)
window.titlebarAppearsTransparent = true window.titlebarAppearsTransparent = true
window.styleMask.insert(.fullSizeContentView) window.styleMask.insert(.fullSizeContentView)
set(appearance: Int(mpv?.macOpts.macos_title_bar_appearance ?? 0)) set(appearance: Int(option?.macOpts.macos_title_bar_appearance ?? 0))
set(material: Int(mpv?.macOpts.macos_title_bar_material ?? 0)) set(material: Int(option?.macOpts.macos_title_bar_material ?? 0))
set(color: mpv?.macOpts.macos_title_bar_color ?? "#00000000") set(color: option?.macOpts.macos_title_bar_color ?? "#00000000")
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -19,7 +19,7 @@ import Cocoa
class View: NSView, CALayerDelegate { class View: NSView, CALayerDelegate {
unowned var common: Common unowned var common: Common
var mpv: MPVHelper? { get { return common.mpv } } var option: OptionHelper? { get { return common.option } }
var input: InputHelper? { get { return common.input } } var input: InputHelper? { get { return common.input } }
var tracker: NSTrackingArea? var tracker: NSTrackingArea?

View File

@ -19,7 +19,7 @@ import Cocoa
class Window: NSWindow, NSWindowDelegate { class Window: NSWindow, NSWindowDelegate {
weak var common: Common! = nil weak var common: Common! = nil
var mpv: MPVHelper? { get { return common.mpv } } var option: OptionHelper? { get { return common.option } }
var input: InputHelper? { get { return common.input } } var input: InputHelper? { get { return common.input } }
var targetScreen: NSScreen? var targetScreen: NSScreen?
@ -92,7 +92,7 @@ class Window: NSWindow, NSWindowDelegate {
title = com.title title = com.title
minSize = NSMakeSize(160, 90) minSize = NSMakeSize(160, 90)
collectionBehavior = .fullScreenPrimary collectionBehavior = .fullScreenPrimary
ignoresMouseEvents = mpv?.opts.cursor_passthrough ?? false ignoresMouseEvents = option?.opts.cursor_passthrough ?? false
delegate = self delegate = self
if let cView = contentView { if let cView = contentView {
@ -143,7 +143,7 @@ class Window: NSWindow, NSWindowDelegate {
setFrame(frame, display: true) setFrame(frame, display: true)
} }
if Bool(mpv?.opts.native_fs ?? true) { if Bool(option?.opts.native_fs ?? true) {
super.toggleFullScreen(sender) super.toggleFullScreen(sender)
} else { } else {
if !isInFullscreen { if !isInFullscreen {
@ -194,7 +194,7 @@ class Window: NSWindow, NSWindowDelegate {
func windowDidEnterFullScreen(_ notification: Notification) { func windowDidEnterFullScreen(_ notification: Notification) {
isInFullscreen = true isInFullscreen = true
mpv?.setOption(fullscreen: isInFullscreen) option?.setOption(fullscreen: isInFullscreen)
common.updateCursorVisibility() common.updateCursorVisibility()
endAnimation(frame) endAnimation(frame)
common.titleBar?.show() common.titleBar?.show()
@ -203,7 +203,7 @@ class Window: NSWindow, NSWindowDelegate {
func windowDidExitFullScreen(_ notification: Notification) { func windowDidExitFullScreen(_ notification: Notification) {
guard let tScreen = targetScreen else { return } guard let tScreen = targetScreen else { return }
isInFullscreen = false isInFullscreen = false
mpv?.setOption(fullscreen: isInFullscreen) option?.setOption(fullscreen: isInFullscreen)
endAnimation(calculateWindowPosition(for: tScreen, withoutBounds: targetScreen == screen)) endAnimation(calculateWindowPosition(for: tScreen, withoutBounds: targetScreen == screen))
common.view?.layerContentsPlacement = .scaleProportionallyToFit common.view?.layerContentsPlacement = .scaleProportionallyToFit
} }
@ -251,7 +251,7 @@ class Window: NSWindow, NSWindowDelegate {
setFrame(targetFrame, display: true) setFrame(targetFrame, display: true)
endAnimation() endAnimation()
isInFullscreen = true isInFullscreen = true
mpv?.setOption(fullscreen: isInFullscreen) option?.setOption(fullscreen: isInFullscreen)
common.windowSetToFullScreen() common.windowSetToFullScreen()
} }
@ -270,7 +270,7 @@ class Window: NSWindow, NSWindowDelegate {
setFrame(newFrame, display: true) setFrame(newFrame, display: true)
endAnimation() endAnimation()
isInFullscreen = false isInFullscreen = false
mpv?.setOption(fullscreen: isInFullscreen) option?.setOption(fullscreen: isInFullscreen)
common.windowSetToWindow() common.windowSetToWindow()
} }
@ -283,7 +283,7 @@ class Window: NSWindow, NSWindowDelegate {
} }
func getFsAnimationDuration(_ def: Double) -> Double { func getFsAnimationDuration(_ def: Double) -> Double {
let duration = mpv?.macOpts.macos_fs_animation_duration ?? -1 let duration = option?.macOpts.macos_fs_animation_duration ?? -1
if duration < 0 { if duration < 0 {
return def return def
} else { } else {
@ -542,7 +542,7 @@ class Window: NSWindow, NSWindowDelegate {
func windowDidEndLiveResize(_ notification: Notification) { func windowDidEndLiveResize(_ notification: Notification) {
common.windowDidEndLiveResize() common.windowDidEndLiveResize()
mpv?.setOption(maximized: isZoomed) option?.setOption(maximized: isZoomed)
if let contentViewFrame = contentView?.frame, if let contentViewFrame = contentView?.frame,
!isAnimating && !isInFullscreen !isAnimating && !isInFullscreen
@ -561,11 +561,11 @@ class Window: NSWindow, NSWindowDelegate {
} }
func windowDidMiniaturize(_ notification: Notification) { func windowDidMiniaturize(_ notification: Notification) {
mpv?.setOption(minimized: true) option?.setOption(minimized: true)
} }
func windowDidDeminiaturize(_ notification: Notification) { func windowDidDeminiaturize(_ notification: Notification) {
mpv?.setOption(minimized: false) option?.setOption(minimized: false)
} }
func windowDidResignKey(_ notification: Notification) { func windowDidResignKey(_ notification: Notification) {
@ -588,6 +588,6 @@ class Window: NSWindow, NSWindowDelegate {
} }
func windowDidMove(_ notification: Notification) { func windowDidMove(_ notification: Notification) {
mpv?.setOption(maximized: isZoomed) option?.setOption(maximized: isZoomed)
} }
} }

View File

@ -27,8 +27,8 @@ class MacCommon: Common {
@objc init(_ vo: UnsafeMutablePointer<vo>) { @objc init(_ vo: UnsafeMutablePointer<vo>) {
let newlog = mp_log_new(vo, vo.pointee.log, "mac") let newlog = mp_log_new(vo, vo.pointee.log, "mac")
super.init(newlog) super.init(newlog)
mpv = MPVHelper(vo, log) option = OptionHelper(vo, log)
input = InputHelper(vo.pointee.input_ctx, mpv) input = InputHelper(vo.pointee.input_ctx, option)
timer = PreciseTimer(common: self) timer = PreciseTimer(common: self)
DispatchQueue.main.sync { DispatchQueue.main.sync {
@ -38,7 +38,7 @@ class MacCommon: Common {
} }
@objc func config(_ vo: UnsafeMutablePointer<vo>) -> Bool { @objc func config(_ vo: UnsafeMutablePointer<vo>) -> Bool {
mpv?.vo = vo option?.vo = vo
DispatchQueue.main.sync { DispatchQueue.main.sync {
let previousActiveApp = getActiveApp() let previousActiveApp = getActiveApp()
@ -58,12 +58,12 @@ class MacCommon: Common {
} }
if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) && if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) &&
mpv?.opts.auto_window_resize ?? true option?.opts.auto_window_resize ?? true
{ {
window?.updateSize(wr.size) window?.updateSize(wr.size)
} }
if mpv?.opts.focus_on ?? 1 == 2 { if option?.opts.focus_on ?? 1 == 2 {
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
} }
@ -88,7 +88,7 @@ class MacCommon: Common {
} }
@objc func swapBuffer() { @objc func swapBuffer() {
if mpv?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK) != RENDER_TIMER_SYSTEM { if option?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK) != RENDER_TIMER_SYSTEM {
swapLock.lock() swapLock.lock()
while(swapTime < 1) { while(swapTime < 1) {
swapLock.wait() swapLock.wait()
@ -104,7 +104,7 @@ class MacCommon: Common {
_ flagsIn: CVOptionFlags, _ flagsIn: CVOptionFlags,
_ flagsOut: UnsafeMutablePointer<CVOptionFlags>) -> CVReturn _ flagsOut: UnsafeMutablePointer<CVOptionFlags>) -> CVReturn
{ {
let frameTimer = mpv?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK) let frameTimer = option?.macOpts.macos_render_timer ?? Int32(RENDER_TIMER_CALLBACK)
let signalSwap = { let signalSwap = {
self.swapLock.lock() self.swapLock.lock()
self.swapTime += 1 self.swapTime += 1