diff --git a/osdep/macos/libmpv_helper.swift b/osdep/macos/libmpv_helper.swift index 8b1c697da2be1..afccdcf58a0b0 100644 --- a/osdep/macos/libmpv_helper.swift +++ b/osdep/macos/libmpv_helper.swift @@ -34,10 +34,9 @@ class LibmpvHelper { mpvHandle = mpv log = LogHelper(mpLog) - guard let app = NSApp as? Application, - let ptr = mp_get_config_group(nil, + guard let ptr = mp_get_config_group(nil, mp_client_get_global(mpvHandle), - app.getMacOSConf()) else + Application.getMacOSConf()) else { log.sendError("macOS config group couldn't be retrieved'") exit(1) diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift index 3b2a7162cb83b..c330680841a3b 100644 --- a/osdep/macos/mpv_helper.swift +++ b/osdep/macos/mpv_helper.swift @@ -42,8 +42,7 @@ class MPVHelper { self.vo = vo self.log = log - guard let app = NSApp as? Application, - let cache = m_config_cache_alloc(vo, vo.pointee.global, app.getVoSubConf()) else + guard let cache = m_config_cache_alloc(vo, vo.pointee.global, Application.getVoSubConf()) else { log.sendError("NSApp couldn't be retrieved") exit(1) @@ -54,7 +53,7 @@ class MPVHelper { guard let macCache = m_config_cache_alloc(vo, vo.pointee.global, - app.getMacOSConf()) else + Application.getMacOSConf()) else { // will never be hit, mp_get_config_group asserts for invalid groups exit(1) diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index fc1da01d39542..8018f3d51c16a 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -190,12 +190,12 @@ - (void)setMpvHandle:(struct mpv_handle *)ctx #endif } -- (const struct m_sub_options *)getMacOSConf ++ (const struct m_sub_options *)getMacOSConf { return &macos_conf; } -- (const struct m_sub_options *)getVoSubConf ++ (const struct m_sub_options *)getVoSubConf { return &vo_sub_opts; } diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 11959a83eaf12..fab968dba8212 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -31,8 +31,8 @@ struct mpv_handle; - (void)stopMPV:(char *)cmd; - (void)openFiles:(NSArray *)filenames; - (void)setMpvHandle:(struct mpv_handle *)ctx; -- (const struct m_sub_options *)getMacOSConf; -- (const struct m_sub_options *)getVoSubConf; ++ (const struct m_sub_options *)getMacOSConf; ++ (const struct m_sub_options *)getVoSubConf; @property(nonatomic, retain) MenuBar *menuBar; @property(nonatomic, assign) size_t openCount; diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 03b263cf9914c..a872e04bb35e1 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -73,11 +73,22 @@ class CocoaCB: Common { } func initBackend(_ vo: UnsafeMutablePointer) { - let previousActiveApp = getActiveApp() - initApp() - initWindow(vo, previousActiveApp) - updateICCProfile() - initWindowState() + if (mpv?.opts.WinID ?? -1) != -1 { + guard let view = self.view else { + log.sendError("Something went wrong, no View was initialized") + exit(1) + } + + let cView: View = unsafeBitCast(mpv!.opts.WinID, to: View.self) + cView.addSubview(view) + view.frame = cView.frame + } else { + let previousActiveApp = getActiveApp() + initApp() + initWindow(vo, previousActiveApp) + updateICCProfile() + initWindowState() + } backendState = .initialized } diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift index aff0566c755bc..bc144cb812dca 100644 --- a/video/out/mac_common.swift +++ b/video/out/mac_common.swift @@ -42,27 +42,48 @@ class MacCommon: Common { mpv?.vo = vo DispatchQueue.main.sync { - let previousActiveApp = getActiveApp() - initApp() - - let (_, _, wr) = getInitProperties(vo) - guard let layer = self.layer else { log.sendError("Something went wrong, no MetalLayer was initialized") exit(1) } - if window == nil { - initView(vo, layer) - initWindow(vo, previousActiveApp) - initWindowState() - } - if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) { - window?.updateSize(wr.size) + if (mpv?.opts.WinID ?? -1) != -1 { + if view == nil { + let cView: View = unsafeBitCast(mpv!.opts.WinID, to: View.self) + + view = View(frame: cView.frame, common: self) + guard let view = self.view else { + log.sendError("Something went wrong, no View was initialized") + exit(1) + } + + view.layer = layer + view.wantsLayer = true + view.layerContentsPlacement = .scaleProportionallyToFit + + cView.addSubview(view) + view.frame = cView.frame + } + } else { + let previousActiveApp = getActiveApp() + initApp() + + let (_, _, wr) = getInitProperties(vo) + + if window == nil { + initView(vo, layer) + initWindow(vo, previousActiveApp) + initWindowState() + } + + if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) { + window?.updateSize(wr.size) + } + + windowDidResize() } - windowDidResize() needsICCUpdate = true }