From 40cbcbf2d756c5424a1f3d74601fba78da50edd0 Mon Sep 17 00:00:00 2001 From: xnep1 Date: Mon, 17 Feb 2025 06:33:04 -0300 Subject: [PATCH] protocols: ensure PointerConstraints activation occurs only after attched to InputManager --- src/protocols/PointerConstraints.cpp | 23 +++++++++++++++++++++-- src/protocols/PointerConstraints.hpp | 7 ++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp index 30ab0a55218..e3250e897a9 100644 --- a/src/protocols/PointerConstraints.cpp +++ b/src/protocols/PointerConstraints.cpp @@ -111,7 +111,8 @@ void CPointerConstraint::deactivate() { else resourceC->sendUnconfined(); - active = false; + pendingActivation = false; + active = false; if (lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) { dead = true; @@ -127,7 +128,13 @@ void CPointerConstraint::activate() { if (dead || active) return; - // TODO: hack, probably not a super duper great idea + if (!attached) { + pendingActivation = true; + return; + } + pendingActivation = false; + + //TODO: hack, probably not a super duper great idea if (g_pSeatManager->state.pointerFocus != pHLSurface->resource()) { const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal(); const auto LOCAL = SURFBOX.has_value() ? logicPositionHint() - SURFBOX->pos() : Vector2D{}; @@ -148,6 +155,14 @@ bool CPointerConstraint::isActive() { return active; } +void CPointerConstraint::setAttached() { + attached = true; +} + +bool CPointerConstraint::isActivationPending() { + return pendingActivation; +} + void CPointerConstraint::onSetRegion(wl_resource* wlRegion) { if (!wlRegion) { region.clear(); @@ -244,6 +259,10 @@ void CPointerConstraintsProtocol::onNewConstraint(SP constra OWNER->appendConstraint(constraint); g_pInputManager->m_vConstraints.emplace_back(constraint); + + constraint->setAttached(); + if (constraint->isActivationPending()) + constraint->activate(); } void CPointerConstraintsProtocol::onLockPointer(CZwpPointerConstraintsV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* pointer, wl_resource* region, diff --git a/src/protocols/PointerConstraints.hpp b/src/protocols/PointerConstraints.hpp index 1cd2fca9535..09d77f4070a 100644 --- a/src/protocols/PointerConstraints.hpp +++ b/src/protocols/PointerConstraints.hpp @@ -24,6 +24,9 @@ class CPointerConstraint { void activate(); bool isActive(); + void setAttached(); + bool isActivationPending(); + SP owner(); CRegion logicConstraintRegion(); @@ -42,6 +45,8 @@ class CPointerConstraint { Vector2D positionHint = {-1, -1}; Vector2D cursorPosOnActivate = {-1, -1}; bool active = false; + bool attached = false; + bool pendingActivation = false; bool locked = false; bool dead = false; zwpPointerConstraintsV1Lifetime lifetime = ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT; @@ -76,4 +81,4 @@ class CPointerConstraintsProtocol : public IWaylandProtocol { namespace PROTO { inline UP constraints; -}; \ No newline at end of file +};