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)
This commit is contained in:
Vaxry 2024-05-05 22:18:10 +01:00 committed by Vaxry
parent e4e84064f2
commit ed411f53bd
51 changed files with 1550 additions and 496 deletions

View file

@ -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)}};
}

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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};

View file

@ -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 {

View file

@ -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;