summaryrefslogtreecommitdiff
path: root/randr
diff options
context:
space:
mode:
authorDavid Ung <davidu@nvidia.com>2014-07-29 15:01:39 -0700
committerKeith Packard <keithp@keithp.com>2014-07-30 14:40:17 -0700
commitb063a185ab9d2c54669fb6e036fdbae3707c9e4b (patch)
tree7edb6aa4a72dcb1ea8611236c00e46b8fb82e238 /randr
parent90803042bcbb9dc6261b5d112acf5613829d9f70 (diff)
randr: Fix logic in RRPointerToNearestCrtc
RRPointerToNearestCrtc is suppose to snap to the nearest Crtc, but best_x and best_y is always positive, hence when calling SetCursorPosition it will make the cursor even further away. Correct delta x/y to allow negative values and also use "width/height -1" in the calculation. Also choose the closest Crtc by setting the "best" value. Signed-off-by: David Ung <davidu@nvidia.com> Reviewed-by: Keith Packard <keithp@keithp.com> Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'randr')
-rw-r--r--randr/rrpointer.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/randr/rrpointer.c b/randr/rrpointer.c
index eb6b6770c..b301d050d 100644
--- a/randr/rrpointer.c
+++ b/randr/rrpointer.c
@@ -77,21 +77,22 @@ RRPointerToNearestCrtc(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
if (x < crtc->x)
dx = crtc->x - x;
- else if (x > crtc->x + scan_width)
- dx = x - (crtc->x + scan_width);
+ else if (x > crtc->x + scan_width - 1)
+ dx = crtc->x + (scan_width - 1) - x;
else
dx = 0;
if (y < crtc->y)
dy = crtc->y - y;
- else if (y > crtc->y + scan_height)
- dy = y - (crtc->y + scan_height);
+ else if (y > crtc->y + scan_height - 1)
+ dy = crtc->y + (scan_height - 1) - y;
else
dy = 0;
- dist = dx + dy;
+ dist = dx * dx + dy * dy;
if (!nearest || dist < best) {
nearest = crtc;
best_dx = dx;
best_dy = dy;
+ best = dist;
}
}
if (best_dx || best_dy)