summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-04 17:34:19 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2023-09-04 17:34:19 +0200
commitd9937fcdba978af4f36be6cb20311e08f43841f5 (patch)
treefa6eabe334287e4d7149bcdc0d66d88a52e62965 /src/helpers
parente3c83ab2e000e2d4fd01f5ada5e9eae91237bb41 (diff)
input: minor constraint fixes
fixes the confined region, warping issues, etc. Closes #3158
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Region.cpp31
-rw-r--r--src/helpers/Region.hpp1
-rw-r--r--src/helpers/WLClasses.hpp4
3 files changed, 34 insertions, 2 deletions
diff --git a/src/helpers/Region.cpp b/src/helpers/Region.cpp
index 38a3760b..644bd5d4 100644
--- a/src/helpers/Region.cpp
+++ b/src/helpers/Region.cpp
@@ -104,3 +104,34 @@ bool CRegion::containsPoint(const Vector2D& vec) {
bool CRegion::empty() {
return !pixman_region32_not_empty(&m_rRegion);
}
+
+Vector2D CRegion::closestPoint(const Vector2D& vec) {
+ double bestDist = __FLT_MAX__;
+ Vector2D leader = vec;
+
+ for (auto& box : getRects()) {
+ double x = 0, y = 0;
+
+ if (vec.x >= box.x2)
+ x = box.x2 - 1;
+ else if (vec.x < box.x1)
+ x = box.x1;
+ else
+ x = vec.x;
+
+ if (vec.y >= box.y2)
+ y = box.y2 - 1;
+ else if (vec.y < box.y1)
+ y = box.y1;
+ else
+ y = vec.y;
+
+ double distance = sqrt(pow(x, 2) + pow(y, 2));
+ if (distance < bestDist) {
+ bestDist = distance;
+ leader = {x, y};
+ }
+ }
+
+ return leader;
+} \ No newline at end of file
diff --git a/src/helpers/Region.hpp b/src/helpers/Region.hpp
index 42458234..e5a99da2 100644
--- a/src/helpers/Region.hpp
+++ b/src/helpers/Region.hpp
@@ -45,6 +45,7 @@ class CRegion {
wlr_box getExtents();
bool containsPoint(const Vector2D& vec);
bool empty();
+ Vector2D closestPoint(const Vector2D& vec);
std::vector<pixman_box32_t> getRects() const;
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index dca7f1e0..84f6d898 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -168,8 +168,8 @@ struct SConstraint {
bool active = false;
- bool hintSet = false;
- Vector2D positionHint; // the position hint, but will be set to the current cursor pos if not set.
+ bool hintSet = false;
+ Vector2D positionHint = {-1, -1}; // the position hint, but will be set to the current cursor pos if not set.
DYNLISTENER(setConstraintRegion);
DYNLISTENER(destroyConstraint);