From 0ec385bc763567cbab4532b3579cd24b07958802 Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 10 Mar 2024 13:44:40 +0100 Subject: options: remove --focus-on-open and add --focus-on replaces the old focus-on-open option with a more generic focus-on options that can be extended. adjust the only platform that uses that option. Fixes #8337 --- DOCS/interface-changes.rst | 1 + DOCS/man/options.rst | 9 ++++++--- options/options.c | 5 +++-- options/options.h | 2 +- video/out/cocoa_cb_common.swift | 3 +++ video/out/mac/common.swift | 6 +++--- video/out/mac_common.swift | 4 ++++ 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 14557de1b5..5852aeb709 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -63,6 +63,7 @@ Interface changes - add `--border-background` option - add `video-target-params` property - add `hdr10plus` sub-parameter to `format` video filter + - remove `--focus-on-open` and add replacement `--focus-on` --- mpv 0.37.0 --- - `--save-position-on-quit` and its associated commands now store state files in %LOCALAPPDATA% instead of %APPDATA% directory by default on Windows. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 6a09cf3884..100fc0482b 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3227,10 +3227,13 @@ Window :desktop: On top of the Desktop behind windows and Desktop icons. :level: A level as integer. -``--focus-on-open``, ``--no-focus-on-open`` +``--focus-on=``, (macOS only) - Focus the video window on creation and makes it the front most window. This - is on by default. + Focus the video window and make it the front most window on specific events (default: open). + + :never: Never focus the window on open or new file load events. + :open: Focus the window on creation, eg when a vo is initialised. + :all: Focus the window on open and new file load event. ``--window-corners=`` (Windows only) diff --git a/options/options.c b/options/options.c index 796a6c668b..3db965a3f7 100644 --- a/options/options.c +++ b/options/options.c @@ -131,7 +131,8 @@ static const m_option_t mp_vo_opt_list[] = { {"window-scale", OPT_DOUBLE(window_scale), M_RANGE(0.001, 100)}, {"window-minimized", OPT_BOOL(window_minimized)}, {"window-maximized", OPT_BOOL(window_maximized)}, - {"focus-on-open", OPT_BOOL(focus_on_open)}, + {"focus-on-open", OPT_REMOVED("Replaced by --focus-on")}, + {"focus-on", OPT_CHOICE(focus_on, {"never", 0}, {"open", 1}, {"all", 2})}, {"force-render", OPT_BOOL(force_render)}, {"force-window-position", OPT_BOOL(force_window_position)}, {"x11-name", OPT_STRING(winname)}, @@ -254,7 +255,7 @@ const struct m_sub_options vo_sub_opts = { .ontop_level = -1, .timing_offset = 0.050, .swapchain_depth = 3, - .focus_on_open = true, + .focus_on = 1, }, }; diff --git a/options/options.h b/options/options.h index 1b7c3e3583..4d3d988789 100644 --- a/options/options.h +++ b/options/options.h @@ -20,7 +20,7 @@ typedef struct mp_vo_opts { bool all_workspaces; bool window_minimized; bool window_maximized; - bool focus_on_open; + int focus_on; int screen_id; char *screen_name; diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 094dab1a55..2b260a2999 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -68,6 +68,9 @@ class CocoaCB: Common { DispatchQueue.main.async { self.updateWindowSize(vo) self.layer?.update(force: true) + if self.mpv?.opts.focus_on ?? 1 == 2 { + NSApp.activate(ignoringOtherApps: true) + } } } } diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 7b6fa48b5d..5790d3b844 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -122,11 +122,11 @@ class Common: NSObject { window.orderFront(nil) } - NSApp.activate(ignoringOtherApps: mpv.opts.focus_on_open) + NSApp.activate(ignoringOtherApps: mpv.opts.focus_on >= 1) // workaround for macOS 10.15 to refocus the previous App - if (!mpv.opts.focus_on_open) { - previousActiveApp?.activate(options: .activateAllWindows) + if mpv.opts.focus_on == 0 { + previousActiveApp?.activate() } } diff --git a/video/out/mac_common.swift b/video/out/mac_common.swift index 71659de8e5..f7b07596d3 100644 --- a/video/out/mac_common.swift +++ b/video/out/mac_common.swift @@ -62,6 +62,10 @@ class MacCommon: Common { window?.updateSize(wr.size) } + if mpv?.opts.focus_on ?? 1 == 2 { + NSApp.activate(ignoringOtherApps: true) + } + windowDidResize() updateICCProfile() } -- cgit v1.2.3