summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/man/options.rst5
-rw-r--r--options/options.c2
-rw-r--r--options/options.h1
-rw-r--r--video/out/cocoa_cb_common.swift3
-rw-r--r--video/out/mac/common.swift14
5 files changed, 22 insertions, 3 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index b75e55e48d..e9d5016074 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -2949,6 +2949,11 @@ Window
:desktop: On top of the Dekstop behind windows and Desktop icons.
:level: A level as integer.
+``--focus-on-open``, ``--no-focus-on-open``
+ (macOS only)
+ Focus the video window on creation and makes it the front most window. This
+ is on by default.
+
``--border``, ``--no-border``
Play video with window border and decorations. Since this is on by
default, use ``--no-border`` to disable the standard window decorations.
diff --git a/options/options.c b/options/options.c
index e1bc5a3c47..6da8e7fbef 100644
--- a/options/options.c
+++ b/options/options.c
@@ -121,6 +121,7 @@ static const m_option_t mp_vo_opt_list[] = {
{"window-scale", OPT_DOUBLE(window_scale), M_RANGE(0.001, 100)},
{"window-minimized", OPT_FLAG(window_minimized)},
{"window-maximized", OPT_FLAG(window_maximized)},
+ {"focus-on-open", OPT_BOOL(focus_on_open)},
{"force-window-position", OPT_FLAG(force_window_position)},
{"x11-name", OPT_STRING(winname)},
{"wayland-app-id", OPT_STRING(appid)},
@@ -199,6 +200,7 @@ const struct m_sub_options vo_sub_opts = {
.ontop_level = -1,
.timing_offset = 0.050,
.swapchain_depth = 3,
+ .focus_on_open = true,
},
};
diff --git a/options/options.h b/options/options.h
index 9b93588bec..68f8bed052 100644
--- a/options/options.h
+++ b/options/options.h
@@ -19,6 +19,7 @@ typedef struct mp_vo_opts {
int all_workspaces;
int window_minimized;
int window_maximized;
+ bool focus_on_open;
int screen_id;
int fsscreen_id;
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