diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-03-19 21:27:45 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-09-21 23:13:19 +0000 |
commit | fac2b31df70710316860c55d2c31af8cdb58e1a3 (patch) | |
tree | 46df522a2a8c9e3f7e8a45d71510f01b8e471c0a /video/out/w32_common.c | |
parent | ee24dd04194aadfda882fd73553cba8d1e734567 (diff) | |
download | mpv-fac2b31df70710316860c55d2c31af8cdb58e1a3.tar.bz2 mpv-fac2b31df70710316860c55d2c31af8cdb58e1a3.tar.xz |
win32: reduce top border thickness to imitate DWM invisible borders
DWM makes part of left, right and bottom border invisible.
Diffstat (limited to 'video/out/w32_common.c')
-rw-r--r-- | video/out/w32_common.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/video/out/w32_common.c b/video/out/w32_common.c index a8794b89c9..a26c56e8da 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -164,6 +164,8 @@ struct vo_w32_state { int snap_dx; int snap_dy; + LONG top_border_reduce; + HANDLE avrt_handle; }; @@ -176,6 +178,8 @@ static void add_window_borders(struct vo_w32_state *w32, HWND hwnd, RECT *rc) } else { AdjustWindowRect(rc, GetWindowLongPtrW(hwnd, GWL_STYLE), 0); } + if (w32->opts->border && !w32->opts->title_bar && !w32->current_fs) + rc->top += w32->top_border_reduce; } // basically a reverse AdjustWindowRect (win32 doesn't appear to have this) @@ -811,6 +815,20 @@ static DWORD update_style(struct vo_w32_state *w32, DWORD style) return style; } +static LONG get_invisible_border_size(struct vo_w32_state *w32) +{ + RECT rect, frame; + if (GetWindowRect(w32->window, &rect) && + SUCCEEDED(DwmGetWindowAttribute(w32->window, DWMWA_EXTENDED_FRAME_BOUNDS, + &frame, sizeof(RECT)))) + { + return frame.left - rect.left; + } + + return 0; +} + + static void update_window_style(struct vo_w32_state *w32) { if (w32->parent) @@ -822,6 +840,8 @@ static void update_window_style(struct vo_w32_state *w32) const DWORD style = GetWindowLongPtrW(w32->window, GWL_STYLE); SetWindowLongPtrW(w32->window, GWL_STYLE, update_style(w32, style)); w32->windowrc = wr; + w32->top_border_reduce = (w32->opts->border && !w32->opts->title_bar && + !w32->current_fs) ? get_invisible_border_size(w32) : 0; } // If rc is wider/taller than n_w/n_h, shrink rc size while keeping the center. @@ -1353,6 +1373,16 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, case WM_SETTINGCHANGE: update_dark_mode(w32); break; + case WM_NCCALCSIZE: + // DWM makes part of left, right and bottom border invisible. Reduce the + // top border width to have the same look all around the window. + if (wParam && lParam && w32->opts->border && !w32->opts->title_bar && + !w32->current_fs && !w32->parent) + { + w32->top_border_reduce = get_invisible_border_size(w32); + ((LPNCCALCSIZE_PARAMS) lParam)->rgrc[0].top -= w32->top_border_reduce; + } + break; } if (message == w32->tbtnCreatedMsg) { |