From b81aa11c8b17cedf6a961073adb1b93cf889de8d Mon Sep 17 00:00:00 2001 From: drendog <53359960+drendog@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:09:59 +0200 Subject: [PATCH] fix: adjusting clamp after getting closest point to fix getting off limit point --- src/managers/PointerManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 973b7e27..bd92b1fa 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -635,7 +635,11 @@ Vector2D CPointerManager::closestValid(const Vector2D& pos) { float distanceSq = __FLT_MAX__; for (auto& b : currentMonitorLayout.monitorBoxes) { - auto p = b.closestPoint(vec); + auto p = b.closestPoint(vec); + + // because closestPoint does clamp up to x + w and y + h + p = Vector2D{std::clamp(p.x, b.x, b.x + b.w - 1), std::clamp(p.y, b.y, b.y + b.h - 1)}; + auto distSq = p.distanceSq(vec); if (distSq < distanceSq) {