protocols: refactor class member vars (n-t) (#10273)

This commit is contained in:
davc0n
2025-05-04 19:21:36 +02:00
committed by GitHub
parent adbae0f74d
commit 2626f89ea6
41 changed files with 1507 additions and 1511 deletions

View File

@@ -9,38 +9,38 @@
#include "../helpers/Monitor.hpp"
CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
resourceL(resource_), locked(true), lifetime(lifetime_) {
m_resourceLocked(resource_), m_locked(true), m_lifetime(lifetime_) {
if UNLIKELY (!resource_->resource())
return;
resource_->setOnDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
resource_->setDestroy([this](CZwpLockedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
pHLSurface = CWLSurface::fromResource(surf);
m_hlSurface = CWLSurface::fromResource(surf);
if (!pHLSurface)
if (!m_hlSurface)
return;
if (region_)
region.set(CWLRegionResource::fromResource(region_)->m_region);
m_region.set(CWLRegionResource::fromResource(region_)->m_region);
resource_->setSetRegion([this](CZwpLockedPointerV1* p, wl_resource* region) { onSetRegion(region); });
resource_->setSetCursorPositionHint([this](CZwpLockedPointerV1* p, wl_fixed_t x, wl_fixed_t y) {
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
if (!pHLSurface)
if (!m_hlSurface)
return;
hintSet = true;
m_hintSet = true;
float scale = 1.f;
const auto PWINDOW = pHLSurface->getWindow();
const auto PWINDOW = m_hlSurface->getWindow();
if (PWINDOW) {
const auto ISXWL = PWINDOW->m_isX11;
scale = ISXWL && *PXWLFORCESCALEZERO ? PWINDOW->m_X11SurfaceScaledBy : 1.f;
}
positionHint = {wl_fixed_to_double(x) / scale, wl_fixed_to_double(y) / scale};
m_positionHint = {wl_fixed_to_double(x) / scale, wl_fixed_to_double(y) / scale};
g_pInputManager->simulateMouseMovement();
});
@@ -48,20 +48,20 @@ CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWL
}
CPointerConstraint::CPointerConstraint(SP<CZwpConfinedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
resourceC(resource_), lifetime(lifetime_) {
m_resourceConfined(resource_), m_lifetime(lifetime_) {
if UNLIKELY (!resource_->resource())
return;
resource_->setOnDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
resource_->setDestroy([this](CZwpConfinedPointerV1* p) { PROTO::constraints->destroyPointerConstraint(this); });
pHLSurface = CWLSurface::fromResource(surf);
m_hlSurface = CWLSurface::fromResource(surf);
if (!pHLSurface)
if (!m_hlSurface)
return;
if (region_)
region.set(CWLRegionResource::fromResource(region_)->m_region);
m_region.set(CWLRegionResource::fromResource(region_)->m_region);
resource_->setSetRegion([this](CZwpConfinedPointerV1* p, wl_resource* region) { onSetRegion(region); });
@@ -74,15 +74,15 @@ CPointerConstraint::~CPointerConstraint() {
return !SHP || SHP.get() == this;
});
if (pHLSurface)
pHLSurface->m_constraint.reset();
if (m_hlSurface)
m_hlSurface->m_constraint.reset();
}
void CPointerConstraint::sharedConstructions() {
if (pHLSurface) {
listeners.destroySurface = pHLSurface->m_events.destroy.registerListener([this](std::any d) {
pHLSurface.reset();
if (active)
if (m_hlSurface) {
m_listeners.destroySurface = m_hlSurface->m_events.destroy.registerListener([this](std::any d) {
m_hlSurface.reset();
if (m_active)
deactivate();
std::erase_if(g_pInputManager->m_constraints, [this](const auto& c) {
@@ -92,26 +92,26 @@ void CPointerConstraint::sharedConstructions() {
});
}
cursorPosOnActivate = g_pInputManager->getMouseCoordsInternal();
m_cursorPosOnActivate = g_pInputManager->getMouseCoordsInternal();
}
bool CPointerConstraint::good() {
return locked ? resourceL->resource() : resourceC->resource();
return m_locked ? m_resourceLocked->resource() : m_resourceConfined->resource();
}
void CPointerConstraint::deactivate() {
if (!active)
if (!m_active)
return;
if (locked)
resourceL->sendUnlocked();
if (m_locked)
m_resourceLocked->sendUnlocked();
else
resourceC->sendUnconfined();
m_resourceConfined->sendUnconfined();
active = false;
m_active = false;
if (lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) {
dead = true;
if (m_lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) {
m_dead = true;
// remove from inputmgr
std::erase_if(g_pInputManager->m_constraints, [this](const auto& c) {
const auto SHP = c.lock();
@@ -121,50 +121,50 @@ void CPointerConstraint::deactivate() {
}
void CPointerConstraint::activate() {
if (dead || active)
if (m_dead || m_active)
return;
// TODO: hack, probably not a super duper great idea
if (g_pSeatManager->m_state.pointerFocus != pHLSurface->resource()) {
const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal();
if (g_pSeatManager->m_state.pointerFocus != m_hlSurface->resource()) {
const auto SURFBOX = m_hlSurface->getSurfaceBoxGlobal();
const auto LOCAL = SURFBOX.has_value() ? logicPositionHint() - SURFBOX->pos() : Vector2D{};
g_pSeatManager->setPointerFocus(pHLSurface->resource(), LOCAL);
g_pSeatManager->setPointerFocus(m_hlSurface->resource(), LOCAL);
}
if (locked)
resourceL->sendLocked();
if (m_locked)
m_resourceLocked->sendLocked();
else
resourceC->sendConfined();
m_resourceConfined->sendConfined();
active = true;
m_active = true;
g_pInputManager->simulateMouseMovement();
}
bool CPointerConstraint::isActive() {
return active;
return m_active;
}
void CPointerConstraint::onSetRegion(wl_resource* wlRegion) {
if (!wlRegion) {
region.clear();
m_region.clear();
return;
}
const auto REGION = region.set(CWLRegionResource::fromResource(wlRegion)->m_region);
const auto REGION = m_region.set(CWLRegionResource::fromResource(wlRegion)->m_region);
region.set(REGION);
positionHint = region.closestPoint(positionHint);
m_region.set(REGION);
m_positionHint = m_region.closestPoint(m_positionHint);
g_pInputManager->simulateMouseMovement(); // to warp the cursor if anything's amiss
}
SP<CWLSurface> CPointerConstraint::owner() {
return pHLSurface.lock();
return m_hlSurface.lock();
}
CRegion CPointerConstraint::logicConstraintRegion() {
CRegion rg = region;
const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal();
CRegion rg = m_region;
const auto SURFBOX = m_hlSurface->getSurfaceBoxGlobal();
// if region wasn't set in pointer-constraints request take surface region
if (rg.empty() && SURFBOX.has_value()) {
@@ -178,17 +178,17 @@ CRegion CPointerConstraint::logicConstraintRegion() {
}
bool CPointerConstraint::isLocked() {
return locked;
return m_locked;
}
Vector2D CPointerConstraint::logicPositionHint() {
if UNLIKELY (!pHLSurface)
if UNLIKELY (!m_hlSurface)
return {};
const auto SURFBOX = pHLSurface->getSurfaceBoxGlobal();
const auto SURFBOX = m_hlSurface->getSurfaceBoxGlobal();
const auto CONSTRAINTPOS = SURFBOX.has_value() ? SURFBOX->pos() : Vector2D{};
return hintSet ? CONSTRAINTPOS + positionHint : cursorPosOnActivate;
return m_hintSet ? CONSTRAINTPOS + m_positionHint : m_cursorPosOnActivate;
}
CPointerConstraintsProtocol::CPointerConstraintsProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@@ -196,7 +196,7 @@ CPointerConstraintsProtocol::CPointerConstraintsProtocol(const wl_interface* ifa
}
void CPointerConstraintsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwpPointerConstraintsV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwpPointerConstraintsV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CZwpPointerConstraintsV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CZwpPointerConstraintsV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@@ -207,18 +207,18 @@ void CPointerConstraintsProtocol::bindManager(wl_client* client, void* data, uin
}
void CPointerConstraintsProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CPointerConstraintsProtocol::destroyPointerConstraint(CPointerConstraint* hyprlandEgg) {
std::erase_if(m_vConstraints, [&](const auto& other) { return other.get() == hyprlandEgg; });
std::erase_if(m_constraints, [&](const auto& other) { return other.get() == hyprlandEgg; });
}
void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> constraint, CZwpPointerConstraintsV1* pMgr) {
if UNLIKELY (!constraint->good()) {
LOGM(ERR, "Couldn't create constraint??");
pMgr->noMemory();
m_vConstraints.pop_back();
m_constraints.pop_back();
return;
}
@@ -229,12 +229,12 @@ void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> constra
const auto OWNER = constraint->owner();
const auto DUPES = std::count_if(m_vConstraints.begin(), m_vConstraints.end(), [OWNER](const auto& c) { return c->owner() == OWNER; });
const auto DUPES = std::count_if(m_constraints.begin(), m_constraints.end(), [OWNER](const auto& c) { return c->owner() == OWNER; });
if UNLIKELY (DUPES > 1) {
LOGM(ERR, "Constraint for surface duped");
pMgr->error(ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, "Surface already confined");
m_vConstraints.pop_back();
m_constraints.pop_back();
return;
}
@@ -249,7 +249,7 @@ void CPointerConstraintsProtocol::onNewConstraint(SP<CPointerConstraint> constra
void CPointerConstraintsProtocol::onLockPointer(CZwpPointerConstraintsV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* pointer, wl_resource* region,
zwpPointerConstraintsV1Lifetime lifetime) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vConstraints.emplace_back(
const auto RESOURCE = m_constraints.emplace_back(
makeShared<CPointerConstraint>(makeShared<CZwpLockedPointerV1>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surface), region, lifetime));
onNewConstraint(RESOURCE, pMgr);
@@ -258,7 +258,7 @@ void CPointerConstraintsProtocol::onLockPointer(CZwpPointerConstraintsV1* pMgr,
void CPointerConstraintsProtocol::onConfinePointer(CZwpPointerConstraintsV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* pointer, wl_resource* region,
zwpPointerConstraintsV1Lifetime lifetime) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vConstraints.emplace_back(
const auto RESOURCE = m_constraints.emplace_back(
makeShared<CPointerConstraint>(makeShared<CZwpConfinedPointerV1>(CLIENT, pMgr->version(), id), CWLSurfaceResource::fromResource(surface), region, lifetime));
onNewConstraint(RESOURCE, pMgr);