Skip to content

Commit

Permalink
protocols: ensure PointerConstraints activation occurs only after att…
Browse files Browse the repository at this point in the history
…ched to InputManager
  • Loading branch information
bk304 committed Feb 17, 2025
1 parent 59c615c commit 40cbcbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/protocols/PointerConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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{};
Expand All @@ -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();
Expand Down Expand Up @@ -244,6 +259,10 @@ void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> 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,
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/PointerConstraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CPointerConstraint {
void activate();
bool isActive();

void setAttached();
bool isActivationPending();

SP<CWLSurface> owner();

CRegion logicConstraintRegion();
Expand All @@ -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;
Expand Down Expand Up @@ -76,4 +81,4 @@ class CPointerConstraintsProtocol : public IWaylandProtocol {

namespace PROTO {
inline UP<CPointerConstraintsProtocol> constraints;
};
};

0 comments on commit 40cbcbf

Please sign in to comment.