summaryrefslogtreecommitdiffstats
path: root/video/out/w32_common.c
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-11-05 04:57:19 +0100
committerDudemanguy <random342@airmail.cc>2023-11-07 16:42:28 +0000
commit6dafc44ed039ffb4a441fc6a2853db0408a48875 (patch)
treee41fb1866e1ad2ffdfde50bb6c646879c6a63f29 /video/out/w32_common.c
parent242066a5ef9a9e53588bcf6ae8613386552ef89f (diff)
downloadmpv-6dafc44ed039ffb4a441fc6a2853db0408a48875.tar.bz2
mpv-6dafc44ed039ffb4a441fc6a2853db0408a48875.tar.xz
win32: fix hit test using client rc instead window
windowrc in vo_w32_state is actually client size, for hit test we need proper window size. When border is disabled those sizes are the same, but when only title bar is disabled it is not. Reduce the hit area to more sane values when the border is not drawn to minimize amount of covered client area in borderless mode.
Diffstat (limited to 'video/out/w32_common.c')
-rw-r--r--video/out/w32_common.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index 121748ce9e..e6a4670d2d 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -222,38 +222,42 @@ static LRESULT borderless_nchittest(struct vo_w32_state *w32, int x, int y)
if (IsMaximized(w32->window))
return HTCLIENT;
- POINT mouse = { x, y };
- ScreenToClient(w32->window, &mouse);
+ RECT rc;
+ if (!GetWindowRect(w32->window, &rc))
+ return HTNOWHERE;
- // The horizontal frame should be the same size as the vertical frame,
- // since the NONCLIENTMETRICS structure does not distinguish between them
- int frame_size = GetSystemMetrics(SM_CXFRAME) +
- GetSystemMetrics(SM_CXPADDEDBORDER);
- // The diagonal size handles are slightly wider than the side borders
- int diagonal_width = frame_size * 2 + GetSystemMetrics(SM_CXBORDER);
+ POINT frame = {GetSystemMetrics(SM_CXSIZEFRAME),
+ GetSystemMetrics(SM_CYSIZEFRAME)};
+ if (w32->opts->border) {
+ frame.x += GetSystemMetrics(SM_CXPADDEDBORDER);
+ frame.y += GetSystemMetrics(SM_CXPADDEDBORDER);
+ if (!w32->opts->title_bar)
+ rc.top -= GetSystemMetrics(SM_CXPADDEDBORDER);
+ }
+ InflateRect(&rc, -frame.x, -frame.y);
// Hit-test top border
- if (mouse.y < frame_size) {
- if (mouse.x < diagonal_width)
+ if (y < rc.top) {
+ if (x < rc.left)
return HTTOPLEFT;
- if (mouse.x >= rect_w(w32->windowrc) - diagonal_width)
+ if (x > rc.right)
return HTTOPRIGHT;
return HTTOP;
}
// Hit-test bottom border
- if (mouse.y >= rect_h(w32->windowrc) - frame_size) {
- if (mouse.x < diagonal_width)
+ if (y > rc.bottom) {
+ if (x < rc.left)
return HTBOTTOMLEFT;
- if (mouse.x >= rect_w(w32->windowrc) - diagonal_width)
+ if (x > rc.right)
return HTBOTTOMRIGHT;
return HTBOTTOM;
}
// Hit-test side borders
- if (mouse.x < frame_size)
+ if (x < rc.left)
return HTLEFT;
- if (mouse.x >= rect_w(w32->windowrc) - frame_size)
+ if (x > rc.right)
return HTRIGHT;
return HTCLIENT;
}