Skip to content

Commit

Permalink
options: remove --focus-on-open and add --focus-on
Browse files Browse the repository at this point in the history
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 mpv-player#8337
  • Loading branch information
Akemi committed Mar 10, 2024
1 parent a56d8ff commit 0ec385b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<never|open|all>``,
(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=<default|donotround|round|roundsmall>``
(Windows only)
Expand Down
5 changes: 3 additions & 2 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down Expand Up @@ -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,
},
};

Expand Down
2 changes: 1 addition & 1 deletion options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions video/out/cocoa_cb_common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions video/out/mac/common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
4 changes: 4 additions & 0 deletions video/out/mac_common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class MacCommon: Common {
window?.updateSize(wr.size)
}

if mpv?.opts.focus_on ?? 1 == 2 {
NSApp.activate(ignoringOtherApps: true)
}

windowDidResize()
updateICCProfile()
}
Expand Down

0 comments on commit 0ec385b

Please sign in to comment.