summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-05-05 22:18:10 +0100
committerVaxry <43317083+vaxerski@users.noreply.github.com>2024-05-09 13:37:39 +0100
commited411f53bdcf8d455f9e6ca769693aa84dc8372f (patch)
treeaacedb349acdd1022975d7b622dc7cfe11388223 /src/helpers
parente4e84064f2d07810e0c150bce1369a0a00503e9a (diff)
cursor: move to a hyprland impl
This moves wlr_cursor to a completely new impl mostly under CPointerManager Also adds beginSimple to OpenGL for simple render passes (e.g. cursor)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/Box.cpp20
-rw-r--r--src/helpers/Box.hpp5
-rw-r--r--src/helpers/Monitor.cpp36
-rw-r--r--src/helpers/Monitor.hpp4
-rw-r--r--src/helpers/Region.cpp5
-rw-r--r--src/helpers/Vector2D.cpp8
-rw-r--r--src/helpers/Vector2D.hpp1
7 files changed, 58 insertions, 21 deletions
diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp
index 8470b509..77406ecf 100644
--- a/src/helpers/Box.cpp
+++ b/src/helpers/Box.cpp
@@ -121,7 +121,7 @@ CBox& CBox::noNegativeSize() {
return *this;
}
-CBox CBox::intersection(const CBox other) const {
+CBox CBox::intersection(const CBox& other) const {
const float newX = std::max(x, other.x);
const float newY = std::max(y, other.y);
const float newBottom = std::min(y + h, other.y + other.h);
@@ -137,6 +137,14 @@ CBox CBox::intersection(const CBox other) const {
return {newX, newY, newW, newH};
}
+bool CBox::overlaps(const CBox& other) const {
+ return (other.x + other.w >= x) && (x + w >= other.x) && (other.y + other.h >= y) && (y + h >= other.y);
+}
+
+bool CBox::inside(const CBox& bound) const {
+ return bound.x < x && bound.y < y && x + w < bound.x + bound.w && y + h < bound.y + bound.h;
+}
+
CBox CBox::roundInternal() {
float newW = x + w - std::floor(x);
float newH = y + h - std::floor(y);
@@ -156,6 +164,16 @@ Vector2D CBox::size() const {
return {w, h};
}
+Vector2D CBox::closestPoint(const Vector2D& vec) const {
+ if (containsPoint(vec))
+ return vec;
+
+ Vector2D nv = vec;
+ nv.x = std::clamp(nv.x, x, x + w);
+ nv.y = std::clamp(nv.y, y, y + h);
+ return nv;
+}
+
SWindowDecorationExtents CBox::extentsFrom(const CBox& small) {
return {{small.x - x, small.y - y}, {w - small.w - (small.x - x), h - small.h - (small.y - y)}};
}
diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp
index 98ba8d47..57df2154 100644
--- a/src/helpers/Box.hpp
+++ b/src/helpers/Box.hpp
@@ -54,13 +54,16 @@ class CBox {
CBox& noNegativeSize();
CBox copy() const;
- CBox intersection(const CBox other) const;
+ CBox intersection(const CBox& other) const;
+ bool overlaps(const CBox& other) const;
+ bool inside(const CBox& bound) const;
SWindowDecorationExtents extentsFrom(const CBox&); // this is the big box
Vector2D middle() const;
Vector2D pos() const;
Vector2D size() const;
+ Vector2D closestPoint(const Vector2D& vec) const;
bool containsPoint(const Vector2D& vec) const;
bool empty() const;
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 3c489d4b..d0e777ed 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -149,14 +149,14 @@ void CMonitor::onConnect(bool noRule) {
for (const auto& PTOUCHDEV : g_pInputManager->m_vTouches) {
if (matchesStaticSelector(PTOUCHDEV->boundOutput)) {
Debug::log(LOG, "Binding touch device {} to output {}", PTOUCHDEV->hlName, szName);
- wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, &PTOUCHDEV->wlr()->base, output);
+ // wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, &PTOUCHDEV->wlr()->base, output);
}
}
for (const auto& PTABLET : g_pInputManager->m_lTablets) {
if (matchesStaticSelector(PTABLET.boundOutput)) {
Debug::log(LOG, "Binding tablet {} to output {}", PTABLET.name, szName);
- wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, PTABLET.wlrDevice, output);
+ // wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, PTABLET.wlrDevice, output);
}
}
@@ -203,7 +203,7 @@ void CMonitor::onConnect(bool noRule) {
// verify last mon valid
bool found = false;
for (auto& m : g_pCompositor->m_vMonitors) {
- if (m.get() == g_pCompositor->m_pLastMonitor) {
+ if (m == g_pCompositor->m_pLastMonitor) {
found = true;
break;
}
@@ -219,6 +219,7 @@ void CMonitor::onConnect(bool noRule) {
PROTO::gamma->applyGammaToState(this);
events.connect.emit();
+ updateGlobal();
}
void CMonitor::onDisconnect(bool destroy) {
@@ -285,10 +286,11 @@ void CMonitor::onDisconnect(bool destroy) {
m_bEnabled = false;
m_bRenderingInitPassed = false;
+ updateGlobal();
+
if (BACKUPMON) {
// snap cursor
- wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f,
- BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f);
+ g_pCompositor->warpCursorTo(BACKUPMON->vecPosition + BACKUPMON->vecTransformedSize / 2.F, true);
// move workspaces
std::deque<PHLWORKSPACE> wspToMove;
@@ -306,22 +308,19 @@ void CMonitor::onDisconnect(bool destroy) {
} else {
g_pCompositor->m_pLastFocus = nullptr;
g_pCompositor->m_pLastWindow.reset();
- g_pCompositor->m_pLastMonitor = nullptr;
+ g_pCompositor->m_pLastMonitor.reset();
}
if (activeWorkspace)
activeWorkspace->m_bVisible = false;
activeWorkspace.reset();
- if (!destroy)
- wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output);
-
wlr_output_state_set_enabled(state.wlr(), false);
if (!state.commit())
Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onDisconnect");
- if (g_pCompositor->m_pLastMonitor == this)
+ if (g_pCompositor->m_pLastMonitor.get() == this)
g_pCompositor->setActiveMonitor(BACKUPMON ? BACKUPMON : g_pCompositor->m_pUnsafeOutput);
if (g_pHyprRenderer->m_pMostHzMonitor == this) {
@@ -508,8 +507,6 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
activeWorkspace.reset();
- wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output);
-
vecPosition = PMIRRORMON->vecPosition;
pMirrorOf = PMIRRORMON;
@@ -728,9 +725,6 @@ void CMonitor::setSpecialWorkspace(const int& id) {
void CMonitor::moveTo(const Vector2D& pos) {
vecPosition = pos;
-
- if (!isMirror())
- wlr_output_layout_add(g_pCompositor->m_sWLROutputLayout, output, (int)vecPosition.x, (int)vecPosition.y);
}
Vector2D CMonitor::middle() {
@@ -749,10 +743,22 @@ void CMonitor::updateMatrix() {
int64_t CMonitor::activeWorkspaceID() {
return activeWorkspace ? activeWorkspace->m_iID : 0;
}
+
int64_t CMonitor::activeSpecialWorkspaceID() {
return activeSpecialWorkspace ? activeSpecialWorkspace->m_iID : 0;
}
+CBox CMonitor::logicalBox() {
+ return {vecPosition, vecSize};
+}
+
+void CMonitor::updateGlobal() {
+ if (output->width > 0 && output->height > 0 && m_bEnabled)
+ wlr_output_create_global(output, g_pCompositor->m_sWLDisplay);
+ else
+ wlr_output_destroy_global(output);
+}
+
CMonitorState::CMonitorState(CMonitor* owner) {
m_pOwner = owner;
wlr_output_state_init(&m_state);
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index a93d23af..2d49aeb3 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -114,6 +114,8 @@ class CMonitor {
SMonitorRule activeMonitorRule;
+ WP<CMonitor> self;
+
// mirroring
CMonitor* pMirrorOf = nullptr;
std::vector<CMonitor*> mirrors;
@@ -167,6 +169,8 @@ class CMonitor {
void updateMatrix();
int64_t activeWorkspaceID();
int64_t activeSpecialWorkspaceID();
+ CBox logicalBox();
+ void updateGlobal();
bool m_bEnabled = false;
bool m_bRenderingInitPassed = false;
diff --git a/src/helpers/Region.cpp b/src/helpers/Region.cpp
index bcbf672d..20eaf452 100644
--- a/src/helpers/Region.cpp
+++ b/src/helpers/Region.cpp
@@ -142,6 +142,9 @@ bool CRegion::empty() const {
}
Vector2D CRegion::closestPoint(const Vector2D& vec) const {
+ if (containsPoint(vec))
+ return vec;
+
double bestDist = __FLT_MAX__;
Vector2D leader = vec;
@@ -162,7 +165,7 @@ Vector2D CRegion::closestPoint(const Vector2D& vec) const {
else
y = vec.y;
- double distance = sqrt(pow(x, 2) + pow(y, 2));
+ double distance = pow(x, 2) + pow(y, 2);
if (distance < bestDist) {
bestDist = distance;
leader = {x, y};
diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp
index c74da0b1..6f96d686 100644
--- a/src/helpers/Vector2D.cpp
+++ b/src/helpers/Vector2D.cpp
@@ -42,9 +42,11 @@ Vector2D Vector2D::clamp(const Vector2D& min, const Vector2D& max) const {
}
double Vector2D::distance(const Vector2D& other) const {
- double dx = x - other.x;
- double dy = y - other.y;
- return std::sqrt(dx * dx + dy * dy);
+ return std::sqrt(distanceSq(other));
+}
+
+double Vector2D::distanceSq(const Vector2D& other) const {
+ return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y);
}
double Vector2D::size() const {
diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp
index 309ed3bc..0f1440c3 100644
--- a/src/helpers/Vector2D.hpp
+++ b/src/helpers/Vector2D.hpp
@@ -89,6 +89,7 @@ class Vector2D {
}
double distance(const Vector2D& other) const;
+ double distanceSq(const Vector2D& other) const;
double size() const;
Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D{-1, -1}) const;