From b7796349b992763d9d5dac21037509b386250a03 Mon Sep 17 00:00:00 2001 From: DeadSix Date: Thu, 21 Sep 2023 23:13:07 +0200 Subject: [PATCH] win32: add an option to change window affinity --- DOCS/man/options.rst | 8 ++++++++ options/options.c | 2 ++ options/options.h | 1 + video/out/w32_common.c | 14 ++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 5f44567b97bfa..5a6af22391198 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3135,6 +3135,14 @@ Window Play video with window border and decorations. Since this is on by default, use ``--no-border`` to disable the standard window decorations. +``--window-affinity=`` + (Windows only) + Controls the window affinity behavior for your program. + + :default: Default Windows behavior + :excludefromcapture: mpv's window will be completely excluded from capture by external applications or screen recording software. + :monitor: Blacks out the mpv window + ``--on-all-workspaces`` (X11 and macOS only) Show the video window on all virtual desktops. diff --git a/options/options.c b/options/options.c index 1fc80ea3d626e..c53183a6ecaae 100644 --- a/options/options.c +++ b/options/options.c @@ -186,6 +186,8 @@ static const m_option_t mp_vo_opt_list[] = { {"photo", 1}, {"video", 2}, {"game", 3})}, #endif #if HAVE_WIN32_DESKTOP + {"window-affinity", OPT_CHOICE(window_affinity, {"default", WDA_NONE}, + {"excludefromcapture", WDA_EXCLUDEFROMCAPTURE}, {"monitor", WDA_MONITOR})}, {"vo-mmcss-profile", OPT_STRING(mmcss_profile)}, #endif #if HAVE_EGL_ANDROID diff --git a/options/options.h b/options/options.h index b7af6efb988d0..a272f46916692 100644 --- a/options/options.h +++ b/options/options.h @@ -63,6 +63,7 @@ typedef struct mp_vo_opts { bool force_render; bool force_window_position; + int window_affinity; char *mmcss_profile; double override_display_fps; diff --git a/video/out/w32_common.c b/video/out/w32_common.c index b3ad94979451f..4861d97cc00cc 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -963,6 +963,16 @@ 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. +static void update_affinity(struct vo_w32_state *w32) +{ + if (!w32 || w32->parent) { + return; + } + SetWindowDisplayAffinity(w32->window, w32->opts->window_affinity); +} + static void update_window_state(struct vo_w32_state *w32) { if (w32->parent) @@ -1612,6 +1622,8 @@ static void *gui_thread(void *ptr) } update_dark_mode(w32); + if (w32->opts->window_affinity) + update_affinity(w32); if (SUCCEEDED(OleInitialize(NULL))) { ole_ok = true; @@ -1786,6 +1798,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); } else if (changed_option == &vo_opts->ontop) { update_window_state(w32); } else if (changed_option == &vo_opts->border) {