From 304ab65dbf0f143df5c92923c3b93cbeecb40d1a Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Thu, 12 Dec 2013 16:49:44 -0600 Subject: [PATCH] user32: Fix distance calculation for MONITOR_DEFAULTTONEAREST. If the target rect is outside a monitor rect but is between its extremes in one dimension, that dimension should contribute 0 to the distance, rather than some arbitrary amount. --- dlls/user32/misc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dlls/user32/misc.c b/dlls/user32/misc.c index 732d11c9f61..eb2631f3ddc 100644 --- a/dlls/user32/misc.c +++ b/dlls/user32/misc.c @@ -321,12 +321,14 @@ static BOOL CALLBACK monitor_enum( HMONITOR monitor, HDC hdc, LPRECT rect, LPARA else if (!info->max_area) /* if not intersecting, check for min distance */ { UINT distance; - INT x, y; - - if (rect->left >= info->rect.right) x = info->rect.right - rect->left; - else x = rect->right - info->rect.left; - if (rect->top >= info->rect.bottom) y = info->rect.bottom - rect->top; - else y = rect->bottom - info->rect.top; + UINT x, y; + + if (info->rect.right <= rect->left) x = rect->left - info->rect.right; + else if (rect->right <= info->rect.left) x = info->rect.left - rect->right; + else x = 0; + if (info->rect.bottom <= rect->top) y = rect->top - info->rect.bottom; + else if (rect->bottom <= info->rect.top) y = info->rect.top - rect->bottom; + else y = 0; distance = x * x + y * y; if (distance < info->min_distance) { -- 2.11.4.GIT