Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win32: add option to change backdrop style #12452

Merged
merged 1 commit into from
Sep 27, 2023
Merged
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
10 changes: 10 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7126,6 +7126,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.
Expand Down
15 changes: 12 additions & 3 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,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},
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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 {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down