summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2020-09-14 17:27:43 +0200
committerder richter <der.richter@gmx.de>2020-09-25 16:48:24 +0200
commit18a35f17e2f36a9af0f647f04f08b6b5b56e10e4 (patch)
tree17485978ca8f1aded38e2b22487d1bcd9137ea8f /video
parentc535dfed6657da738e2df7d83fdc39b8950a3463 (diff)
downloadmpv-18a35f17e2f36a9af0f647f04f08b6b5b56e10e4.tar.bz2
mpv-18a35f17e2f36a9af0f647f04f08b6b5b56e10e4.tar.xz
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
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_cb_common.swift3
-rw-r--r--video/out/mac/common.swift14
2 files changed, 14 insertions, 3 deletions
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<vo>) {
+ 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<vo>) {
+ func initWindow(_ vo: UnsafeMutablePointer<vo>, _ 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<vo>, _ 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