Skip to content

Commit

Permalink
win32: add an option to change window affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadSix27 committed Sep 13, 2023
1 parent 662650b commit 2521a86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ static const m_option_t mp_vo_opt_list[] = {
{"ontop-level", OPT_CHOICE(ontop_level, {"window", -1}, {"system", -2},
{"desktop", -3}), M_RANGE(0, INT_MAX)},
{"border", OPT_BOOL(border)},
#if HAVE_WIN32_DESKTOP
{"window-affinity", OPT_CHOICE(window_affinity, {"default", WDA_NONE}, {"excludefromcapture", WDA_EXCLUDEFROMCAPTURE}, {"monitor", WDA_MONITOR})},
#endif
{"fit-border", OPT_BOOL(fit_border),
.deprecation_message = "the option is ignored and no longer needed"},
{"on-all-workspaces", OPT_BOOL(all_workspaces)},
Expand Down Expand Up @@ -216,6 +219,9 @@ const struct m_sub_options vo_sub_opts = {
.hidpi_window_scale = true,
.native_fs = true,
.taskbar_progress = true,
#if HAVE_WIN32_DESKTOP
.window_affinity = WDA_NONE,
#endif
.border = true,
.fit_border = true,
.appid = "mpv",
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct mp_vo_opts {
int ontop_level;
bool fullscreen;
bool border;
int window_affinity;
bool fit_border;
bool all_workspaces;
bool window_minimized;
Expand Down
17 changes: 17 additions & 0 deletions video/out/w32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,21 @@ static bool is_visible(HWND window)
return GetWindowLongPtrW(window, GWL_STYLE) & WS_VISIBLE;
}

//Set the mpv window's affinity.
//This will affect how it's displayed on the desktop and in system-level operations like taking screenshots.
//During startup of mpv we want to avoid changing anything when its not needed, that is toggled by handleDefault
static bool update_affinity(struct vo_w32_state *w32, bool handleDefault)
{
bool affinity_result = false;
if (!w32 || w32->parent) {
return affinity_result;
}
if (w32->opts->window_affinity != WDA_NONE || handleDefault) {
affinity_result = SetWindowDisplayAffinity(w32->window, w32->opts->window_affinity);
}
return affinity_result;
}

static void update_window_state(struct vo_w32_state *w32)
{
if (w32->parent)
Expand Down Expand Up @@ -1775,6 +1790,8 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)

if (changed_option == &vo_opts->fullscreen) {
reinit_window_state(w32);
} else if (changed_option == &vo_opts->window_affinity) {
update_affinity(w32, true);
} else if (changed_option == &vo_opts->ontop) {
update_window_state(w32);
} else if (changed_option == &vo_opts->border) {
Expand Down

0 comments on commit 2521a86

Please sign in to comment.