Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3488,9 +3488,13 @@ Window
:level: A level as integer.

``--focus-on=<never|open|all>``,
(X11 and macOS only)
(Windows, X11 and macOS only)
Focus the video window and make it the front most window on specific events (default: open).

On Windows, due to the system's focus stealing prevention mechanism,
``--force-window=immediate`` is recommended for ``open`` and ``all``
to work reliably.

: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.
Expand Down
5 changes: 4 additions & 1 deletion player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,8 +2052,11 @@ static void play_current_file(struct MPContext *mpctx)
current && current->reloading;
if (current)
current->reloading = false;
if (!reloading)
if (!reloading) {
if (mpctx->video_out)
vo_set_changing_file(mpctx->video_out);
m_config_restore_backups(mpctx->mconfig);
}

TA_FREEP(&mpctx->filter_root);
talloc_free(mpctx->filtered_tags);
Expand Down
28 changes: 26 additions & 2 deletions video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct vo_internal {
bool paused;
bool visible;
bool wakeup_on_done;
bool changing_file;
int queued_events; // event mask for the user
int internal_events; // event mask for us

Expand Down Expand Up @@ -237,18 +238,32 @@ static void read_opts(struct vo *vo)
static void update_opts(void *p)
{
struct vo *vo = p;
struct vo_internal *in = vo->in;

if (m_config_cache_update(vo->opts_cache)) {
read_opts(vo);
if (vo->driver->control) {
vo->driver->control(vo, VOCTRL_VO_OPTS_CHANGED, NULL);
vo->driver->control(vo, VOCTRL_VO_OPTS_CHANGED, NULL);
if (!in->changing_file) {
// "Legacy" update of video position related options.
// Unlike VOCTRL_VO_OPTS_CHANGED, often not propagated to backends.
vo->driver->control(vo, VOCTRL_SET_PANSCAN, NULL);
}
}
}

static void handle_file_change(struct vo *vo)
{
struct vo_internal *in = vo->in;

if (in->changing_file) {
in->changing_file = false;
vo->driver->control(vo, VOCTRL_SET_PANSCAN, NULL);

if (vo->opts->focus_on == 2)
vo->driver->control(vo, VOCTRL_BRING_FRONT, NULL);
}
}

// Does not include thread- and VO uninit.
static void dealloc_vo(struct vo *vo)
{
Expand Down Expand Up @@ -1014,6 +1029,8 @@ static bool render_frame(struct vo *vo)

stats_time_start(in->stats, "video-flip");

handle_file_change(vo);

vo->driver->flip_page(vo);

struct vo_vsync_info vsync = {
Expand Down Expand Up @@ -1071,6 +1088,13 @@ static bool render_frame(struct vo *vo)
return more_frames;
}

void vo_set_changing_file(struct vo *vo)
{
mp_mutex_lock(&vo->in->lock);
vo->in->changing_file = true;
mp_mutex_unlock(&vo->in->lock);
}

static void do_redraw(struct vo *vo)
{
struct vo_internal *in = vo->in;
Expand Down
3 changes: 3 additions & 0 deletions video/out/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ enum mp_voctrl {
// Clipboard
VOCTRL_GET_CLIPBOARD, // struct voctrl_clipboard*
VOCTRL_SET_CLIPBOARD,

VOCTRL_BRING_FRONT,
};

// Helper to expose what kind of content is currently playing to the VO.
Expand Down Expand Up @@ -542,6 +544,7 @@ bool vo_want_redraw(struct vo *vo);
void vo_seek_reset(struct vo *vo);
void vo_destroy(struct vo *vo);
void vo_set_paused(struct vo *vo, bool paused);
void vo_set_changing_file(struct vo *vo);
int64_t vo_get_drop_count(struct vo *vo);
void vo_increment_drop_count(struct vo *vo, int64_t n);
int64_t vo_get_delayed_count(struct vo *vo);
Expand Down
11 changes: 10 additions & 1 deletion video/out/w32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,9 @@ static void window_resize(struct vo_w32_state *w32)
ShowWindow(w32->window, SW_SHOWMINNOACTIVE);
} else if (w32->opts->window_maximized && !w32->current_fs) {
ShowWindow(w32->window, SW_SHOWMAXIMIZED);
} else if (w32->opts->focus_on == 0) {
ShowWindow(w32->window, SW_SHOWNOACTIVATE);
SetWindowPos(w32->window, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
} else {
ShowWindow(w32->window, SW_SHOW);
}
Expand Down Expand Up @@ -2305,6 +2308,7 @@ static bool gui_thread_control_supports(int request)
case VOCTRL_BEGIN_DRAGGING:
case VOCTRL_SHOW_MENU:
case VOCTRL_UPDATE_MENU:
case VOCTRL_BRING_FRONT:
return true;
}

Expand Down Expand Up @@ -2499,12 +2503,17 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
case VOCTRL_SHOW_MENU:
PostMessageW(w32->window, WM_SHOWMENU, 0, 0);
return VO_TRUE;
case VOCTRL_UPDATE_MENU:;
case VOCTRL_UPDATE_MENU:
const m_option_t menu_data_type = {.type = CONF_TYPE_NODE};
m_option_free(&menu_data_type, &w32->menu_data);
m_option_copy(&menu_data_type, &w32->menu_data, arg);
talloc_steal(w32, node_get_alloc(&w32->menu_data));
return VO_TRUE;
case VOCTRL_BRING_FRONT:
if (SetForegroundWindow(w32->window) != FALSE)
return VO_TRUE;

return VO_FALSE;
}

// Keep gui_thread_control_supports() in sync
Expand Down
Loading