win32: add option to change backdrop style

This commit is contained in:
DeadSix 2023-09-22 15:35:39 +02:00 committed by Dudemanguy
parent 5638fcabfd
commit f19ada7b58
4 changed files with 40 additions and 3 deletions

View File

@ -7110,6 +7110,16 @@ Miscellaneous
This is a key/value list option. See `List Options`_ for details.
``--backdrop-type=<auto|none|mica|acrylic|mica-alt>``
(Windows only)
Controls the backdrop/border style.
:auto: Default Windows behavior
:none: The backdrop will be black or white depending on the system's theme settings.
:mica: Enables the Mica style, which is the default on Windows 11.
:acrylic: Enables the Acrylic style (frosted glass look).
:mica-alt: Same as Mica, except reversed.
``--window-affinity=<default|excludefromcmcapture|monitor>``
(Windows only)
Controls the window affinity behavior of mpv.

View File

@ -190,14 +190,23 @@ 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)},
// For old MinGW-w64 compatibility
#define DWMWCP_DEFAULT 0
#define DWMWCP_DONOTROUND 1
#define DWMWCP_ROUND 2
#define DWMWCP_ROUNDSMALL 3
#define DWMSBT_AUTO 0
#define DWMSBT_NONE 1
#define DWMSBT_MAINWINDOW 2
#define DWMSBT_TRANSIENTWINDOW 3
#define DWMSBT_TABBEDWINDOW 4
{"backdrop-type", OPT_CHOICE(backdrop_type, {"auto", DWMSBT_AUTO}, {"none", DWMSBT_NONE},
{"mica", DWMSBT_MAINWINDOW}, {"acrylic", DWMSBT_TRANSIENTWINDOW}, {"mica-alt", DWMSBT_TABBEDWINDOW})},
{"window-affinity", OPT_CHOICE(window_affinity, {"default", WDA_NONE},
{"excludefromcapture", WDA_EXCLUDEFROMCAPTURE}, {"monitor", WDA_MONITOR})},
{"vo-mmcss-profile", OPT_STRING(mmcss_profile)},
{"window-corners", OPT_CHOICE(window_corners,
{"default", DWMWCP_DEFAULT},
{"donotround", DWMWCP_DONOTROUND},

View File

@ -64,6 +64,7 @@ typedef struct mp_vo_opts {
bool force_render;
bool force_window_position;
int backdrop_type;
int window_affinity;
char *mmcss_profile;
int window_corners;

View File

@ -58,7 +58,10 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
//Older MinGW compatibility
#define DWMWA_WINDOW_CORNER_PREFERENCE 33
#define DWMWA_SYSTEMBACKDROP_TYPE 38
#ifndef DPI_ENUMS_DECLARED
typedef enum MONITOR_DPI_TYPE {
@ -1096,6 +1099,16 @@ static void update_dark_mode(const struct vo_w32_state *w32)
&use_dark_mode, sizeof(use_dark_mode));
}
static void update_backdrop(const struct vo_w32_state *w32)
{
if (w32->parent)
return;
int backdropType = w32->opts->backdrop_type;
DwmSetWindowAttribute(w32->window, DWMWA_SYSTEMBACKDROP_TYPE,
&backdropType, sizeof(backdropType));
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
@ -1674,6 +1687,8 @@ static void *gui_thread(void *ptr)
update_corners_pref(w32);
if (w32->opts->window_affinity)
update_affinity(w32);
if (w32->opts->backdrop_type)
update_backdrop(w32);
if (SUCCEEDED(OleInitialize(NULL))) {
ole_ok = true;
@ -1852,6 +1867,8 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
update_affinity(w32);
} else if (changed_option == &vo_opts->ontop) {
update_window_state(w32);
} else if (changed_option == &vo_opts->backdrop_type) {
update_backdrop(w32);
} else if (changed_option == &vo_opts->border ||
changed_option == &vo_opts->title_bar)
{