From 18a35f17e2f36a9af0f647f04f08b6b5b56e10e4 Mon Sep 17 00:00:00 2001 From: der richter Date: Mon, 14 Sep 2020 17:27:43 +0200 Subject: mac: add an option to prevent focusing of the window on open on macOS 10.15 setting the activation policy behaves quite weirdly. the call changes the current active App to a nameless process, which probably also the reason that prevents the not focusing to work. a workaround for that, is to refocus the previous active app. Fixes #7725 --- video/out/cocoa_cb_common.swift | 3 ++- video/out/mac/common.swift | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'video/out') diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 6cea9a60c3..476b4820bc 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -73,8 +73,9 @@ class CocoaCB: Common { } func initBackend(_ vo: UnsafeMutablePointer) { + let previousActiveApp = getActiveApp() initApp() - initWindow(vo) + initWindow(vo, previousActiveApp) updateICCProfile() initWindowState() diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index fb52b80610..95a0113c80 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -82,7 +82,7 @@ class Common: NSObject { setAppIcon() } - func initWindow(_ vo: UnsafeMutablePointer) { + func initWindow(_ vo: UnsafeMutablePointer, _ previousActiveApp: NSRunningApplication?) { let (mpv, targetScreen, wr) = getInitProperties(vo) guard let view = self.view else { @@ -115,7 +115,12 @@ class Common: NSObject { window.orderFront(nil) } - NSApp.activate(ignoringOtherApps: true) + NSApp.activate(ignoringOtherApps: mpv.opts.focus_on_open) + + // workaround for macOS 10.15 to refocus the previous App + if (!mpv.opts.focus_on_open) { + previousActiveApp?.activate(options: .activateAllWindows) + } } func initView(_ vo: UnsafeMutablePointer, _ layer: CALayer) { @@ -419,6 +424,11 @@ class Common: NSObject { return (mpv, targetScreen, wr) } + // call before initApp, because on macOS +10.15 it changes the active App + func getActiveApp() -> NSRunningApplication? { + return NSWorkspace.shared.runningApplications.first(where: {$0.isActive}) + } + func flagEvents(_ ev: Int) { eventsLock.lock() events |= ev -- cgit v1.2.3