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 bd69cb1
Show file tree
Hide file tree
Showing 2 changed files with 21 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
15 changes: 15 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

0 comments on commit bd69cb1

Please sign in to comment.