From 5a158952d507653ac8b900764a633afdb7e922f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 22 Aug 2023 00:12:33 +0200 Subject: [PATCH] win32: add --window-corners Allows to set preference for window corners rounding for DWM. --- DOCS/interface-changes.rst | 1 + DOCS/man/options.rst | 9 +++++++++ options/options.c | 11 +++++++++++ options/options.h | 1 + video/out/w32_common.c | 11 +++++++++++ 5 files changed, 33 insertions(+) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index ad0e059ef1697..b44b452b94071 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -88,6 +88,7 @@ Interface changes - `--drm-connector` no longer allows selecting the card number (use `--drm-device` instead) - add `--title-bar` option + - add `--window-corners` option --- mpv 0.36.0 --- - add `--target-contrast` - Target luminance value is now also applied when ICC profile is used. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 8e59ac1dbc742..20ba4f8552685 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3131,6 +3131,15 @@ Window Focus the video window on creation and makes it the front most window. This is on by default. +``--window-corners=`` + (Windows only) + Set the preference for window corner rounding. + + :default: Let the system decide whether or not to round window corners + :donotround: Never round window corners + :round: Round the corners if appropriate + :roundsmall: Round the corners if appropriate, with a small radius + ``--border``, ``--no-border`` Play video with window border and decorations. Since this is on by default, use ``--no-border`` to disable the standard window decorations. diff --git a/options/options.c b/options/options.c index 357f043404187..40f1f6ff83f2d 100644 --- a/options/options.c +++ b/options/options.c @@ -32,6 +32,7 @@ #ifdef _WIN32 #include +#include #endif #include "options.h" @@ -190,6 +191,16 @@ static const m_option_t mp_vo_opt_list[] = { {"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 + {"window-corners", OPT_CHOICE(window_corners, + {"default", DWMWCP_DEFAULT}, + {"donotround", DWMWCP_DONOTROUND}, + {"round", DWMWCP_ROUND}, + {"roundsmall", DWMWCP_ROUNDSMALL})}, #endif #if HAVE_EGL_ANDROID {"android-surface-size", OPT_SIZE_BOX(android_surface_size)}, diff --git a/options/options.h b/options/options.h index ce676840edc5e..339acda38c1a2 100644 --- a/options/options.h +++ b/options/options.h @@ -66,6 +66,7 @@ typedef struct mp_vo_opts { int window_affinity; char *mmcss_profile; + int window_corners; double override_display_fps; double timing_offset; diff --git a/video/out/w32_common.c b/video/out/w32_common.c index ee00972ba3ded..b288adf253e42 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -58,6 +58,8 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase; #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 #endif +#define DWMWA_WINDOW_CORNER_PREFERENCE 33 + #ifndef DPI_ENUMS_DECLARED typedef enum MONITOR_DPI_TYPE { MDT_EFFECTIVE_DPI = 0, @@ -1090,6 +1092,12 @@ static void update_dark_mode(const struct vo_w32_state *w32) &use_dark_mode, sizeof(use_dark_mode)); } +static void update_corners_pref(const struct vo_w32_state *w32) { + DwmSetWindowAttribute(w32->window, DWMWA_WINDOW_CORNER_PREFERENCE, + &w32->opts->window_corners, + sizeof(w32->opts->window_corners)); +} + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -1666,6 +1674,7 @@ static void *gui_thread(void *ptr) } update_dark_mode(w32); + update_corners_pref(w32); if (w32->opts->window_affinity) update_affinity(w32); @@ -1855,6 +1864,8 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg) update_minimized_state(w32); } else if (changed_option == &vo_opts->window_maximized) { update_maximized_state(w32); + } else if (changed_option == &vo_opts->window_corners) { + update_corners_pref(w32); } }