protocols: refactor class member vars (core) (#10259)

This commit is contained in:
davc0n 2025-05-03 16:02:49 +02:00 committed by GitHub
parent 0c736217a7
commit d9cad5e1b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 1160 additions and 1158 deletions

View file

@ -24,129 +24,129 @@ class CDefaultSurfaceRole : public ISurfaceRole {
}
};
CWLCallbackResource::CWLCallbackResource(SP<CWlCallback> resource_) : resource(resource_) {
CWLCallbackResource::CWLCallbackResource(SP<CWlCallback> resource_) : m_resource(resource_) {
;
}
bool CWLCallbackResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLCallbackResource::send(const Time::steady_tp& now) {
resource->sendDone(Time::millis(now));
m_resource->sendDone(Time::millis(now));
}
CWLRegionResource::CWLRegionResource(SP<CWlRegion> resource_) : resource(resource_) {
CWLRegionResource::CWLRegionResource(SP<CWlRegion> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
resource->setDestroy([this](CWlRegion* r) { PROTO::compositor->destroyResource(this); });
resource->setOnDestroy([this](CWlRegion* r) { PROTO::compositor->destroyResource(this); });
m_resource->setDestroy([this](CWlRegion* r) { PROTO::compositor->destroyResource(this); });
m_resource->setOnDestroy([this](CWlRegion* r) { PROTO::compositor->destroyResource(this); });
resource->setAdd([this](CWlRegion* r, int32_t x, int32_t y, int32_t w, int32_t h) { region.add(CBox{x, y, w, h}); });
resource->setSubtract([this](CWlRegion* r, int32_t x, int32_t y, int32_t w, int32_t h) { region.subtract(CBox{x, y, w, h}); });
m_resource->setAdd([this](CWlRegion* r, int32_t x, int32_t y, int32_t w, int32_t h) { m_region.add(CBox{x, y, w, h}); });
m_resource->setSubtract([this](CWlRegion* r, int32_t x, int32_t y, int32_t w, int32_t h) { m_region.subtract(CBox{x, y, w, h}); });
}
bool CWLRegionResource::good() {
return resource->resource();
return m_resource->resource();
}
SP<CWLRegionResource> CWLRegionResource::fromResource(wl_resource* res) {
auto data = (CWLRegionResource*)(((CWlRegion*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(resource_) {
CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
pClient = resource->client();
m_client = m_resource->client();
resource->setData(this);
m_resource->setData(this);
role = makeShared<CDefaultSurfaceRole>();
m_role = makeShared<CDefaultSurfaceRole>();
resource->setDestroy([this](CWlSurface* r) { destroy(); });
resource->setOnDestroy([this](CWlSurface* r) { destroy(); });
m_resource->setDestroy([this](CWlSurface* r) { destroy(); });
m_resource->setOnDestroy([this](CWlSurface* r) { destroy(); });
resource->setAttach([this](CWlSurface* r, wl_resource* buffer, int32_t x, int32_t y) {
pending.updated.buffer = true;
pending.updated.offset = true;
m_resource->setAttach([this](CWlSurface* r, wl_resource* buffer, int32_t x, int32_t y) {
m_pending.updated.buffer = true;
m_pending.updated.offset = true;
pending.offset = {x, y};
m_pending.offset = {x, y};
if (pending.buffer)
pending.buffer.drop();
if (m_pending.buffer)
m_pending.buffer.drop();
auto buf = buffer ? CWLBufferResource::fromResource(buffer) : nullptr;
if (buf && buf->buffer) {
pending.buffer = CHLBufferReference(buf->buffer.lock());
pending.texture = buf->buffer->texture;
pending.size = buf->buffer->size;
pending.bufferSize = buf->buffer->size;
m_pending.buffer = CHLBufferReference(buf->buffer.lock());
m_pending.texture = buf->buffer->texture;
m_pending.size = buf->buffer->size;
m_pending.bufferSize = buf->buffer->size;
} else {
pending.buffer = {};
pending.texture.reset();
pending.size = Vector2D{};
pending.bufferSize = Vector2D{};
m_pending.buffer = {};
m_pending.texture.reset();
m_pending.size = Vector2D{};
m_pending.bufferSize = Vector2D{};
}
if (pending.bufferSize != current.bufferSize) {
pending.updated.damage = true;
pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
if (m_pending.bufferSize != m_current.bufferSize) {
m_pending.updated.damage = true;
m_pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
}
});
resource->setCommit([this](CWlSurface* r) {
if (pending.buffer)
pending.bufferDamage.intersect(CBox{{}, pending.bufferSize});
m_resource->setCommit([this](CWlSurface* r) {
if (m_pending.buffer)
m_pending.bufferDamage.intersect(CBox{{}, m_pending.bufferSize});
if (!pending.buffer)
pending.size = {};
else if (pending.viewport.hasDestination)
pending.size = pending.viewport.destination;
else if (pending.viewport.hasSource)
pending.size = pending.viewport.source.size();
if (!m_pending.buffer)
m_pending.size = {};
else if (m_pending.viewport.hasDestination)
m_pending.size = m_pending.viewport.destination;
else if (m_pending.viewport.hasSource)
m_pending.size = m_pending.viewport.source.size();
else {
Vector2D tfs = pending.transform % 2 == 1 ? Vector2D{pending.bufferSize.y, pending.bufferSize.x} : pending.bufferSize;
pending.size = tfs / pending.scale;
Vector2D tfs = m_pending.transform % 2 == 1 ? Vector2D{m_pending.bufferSize.y, m_pending.bufferSize.x} : m_pending.bufferSize;
m_pending.size = tfs / m_pending.scale;
}
pending.damage.intersect(CBox{{}, pending.size});
m_pending.damage.intersect(CBox{{}, m_pending.size});
events.precommit.emit();
if (pending.rejected) {
pending.rejected = false;
m_events.precommit.emit();
if (m_pending.rejected) {
m_pending.rejected = false;
dropPendingBuffer();
return;
}
if ((!pending.updated.buffer) || // no new buffer attached
(!pending.buffer && !pending.texture) // null buffer attached
if ((!m_pending.updated.buffer) || // no new buffer attached
(!m_pending.buffer && !m_pending.texture) // null buffer attached
) {
commitState(pending);
pending.reset();
commitState(m_pending);
m_pending.reset();
return;
}
// save state while we wait for buffer to become ready to read
const auto& state = pendingStates.emplace(makeUnique<SSurfaceState>(pending));
pending.reset();
const auto& state = m_pendingStates.emplace(makeUnique<SSurfaceState>(m_pending));
m_pending.reset();
auto whenReadable = [this, surf = self, state = WP<SSurfaceState>(pendingStates.back())] {
auto whenReadable = [this, surf = m_self, state = WP<SSurfaceState>(m_pendingStates.back())] {
if (!surf || state.expired())
return;
while (!pendingStates.empty() && pendingStates.front() != state) {
commitState(*pendingStates.front());
pendingStates.pop();
while (!m_pendingStates.empty() && m_pendingStates.front() != state) {
commitState(*m_pendingStates.front());
m_pendingStates.pop();
}
commitState(*pendingStates.front());
pendingStates.pop();
commitState(*m_pendingStates.front());
m_pendingStates.pop();
};
if (state->updated.acquire) {
@ -169,106 +169,106 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : resource(reso
}
});
resource->setDamage([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) {
pending.updated.damage = true;
pending.damage.add(CBox{x, y, w, h});
m_resource->setDamage([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) {
m_pending.updated.damage = true;
m_pending.damage.add(CBox{x, y, w, h});
});
resource->setDamageBuffer([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) {
pending.updated.damage = true;
pending.bufferDamage.add(CBox{x, y, w, h});
m_resource->setDamageBuffer([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) {
m_pending.updated.damage = true;
m_pending.bufferDamage.add(CBox{x, y, w, h});
});
resource->setSetBufferScale([this](CWlSurface* r, int32_t scale) {
if (scale == pending.scale)
m_resource->setSetBufferScale([this](CWlSurface* r, int32_t scale) {
if (scale == m_pending.scale)
return;
pending.updated.scale = true;
pending.updated.damage = true;
m_pending.updated.scale = true;
m_pending.updated.damage = true;
pending.scale = scale;
pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
m_pending.scale = scale;
m_pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
});
resource->setSetBufferTransform([this](CWlSurface* r, uint32_t tr) {
if (tr == pending.transform)
m_resource->setSetBufferTransform([this](CWlSurface* r, uint32_t tr) {
if (tr == m_pending.transform)
return;
pending.updated.transform = true;
pending.updated.damage = true;
m_pending.updated.transform = true;
m_pending.updated.damage = true;
pending.transform = (wl_output_transform)tr;
pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
m_pending.transform = (wl_output_transform)tr;
m_pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
});
resource->setSetInputRegion([this](CWlSurface* r, wl_resource* region) {
pending.updated.input = true;
m_resource->setSetInputRegion([this](CWlSurface* r, wl_resource* region) {
m_pending.updated.input = true;
if (!region) {
pending.input = CBox{{}, {INT32_MAX, INT32_MAX}};
m_pending.input = CBox{{}, {INT32_MAX, INT32_MAX}};
return;
}
auto RG = CWLRegionResource::fromResource(region);
pending.input = RG->region;
auto RG = CWLRegionResource::fromResource(region);
m_pending.input = RG->m_region;
});
resource->setSetOpaqueRegion([this](CWlSurface* r, wl_resource* region) {
pending.updated.opaque = true;
m_resource->setSetOpaqueRegion([this](CWlSurface* r, wl_resource* region) {
m_pending.updated.opaque = true;
if (!region) {
pending.opaque = CBox{{}, {}};
m_pending.opaque = CBox{{}, {}};
return;
}
auto RG = CWLRegionResource::fromResource(region);
pending.opaque = RG->region;
auto RG = CWLRegionResource::fromResource(region);
m_pending.opaque = RG->m_region;
});
resource->setFrame([this](CWlSurface* r, uint32_t id) { callbacks.emplace_back(makeShared<CWLCallbackResource>(makeShared<CWlCallback>(pClient, 1, id))); });
m_resource->setFrame([this](CWlSurface* r, uint32_t id) { m_callbacks.emplace_back(makeShared<CWLCallbackResource>(makeShared<CWlCallback>(m_client, 1, id))); });
resource->setOffset([this](CWlSurface* r, int32_t x, int32_t y) {
pending.updated.offset = true;
pending.offset = {x, y};
m_resource->setOffset([this](CWlSurface* r, int32_t x, int32_t y) {
m_pending.updated.offset = true;
m_pending.offset = {x, y};
});
}
CWLSurfaceResource::~CWLSurfaceResource() {
events.destroy.emit();
m_events.destroy.emit();
}
void CWLSurfaceResource::destroy() {
if (mapped) {
events.unmap.emit();
if (m_mapped) {
m_events.unmap.emit();
unmap();
}
events.destroy.emit();
m_events.destroy.emit();
releaseBuffers(false);
PROTO::compositor->destroyResource(this);
}
void CWLSurfaceResource::dropPendingBuffer() {
pending.buffer = {};
m_pending.buffer = {};
}
void CWLSurfaceResource::dropCurrentBuffer() {
current.buffer = {};
m_current.buffer = {};
}
SP<CWLSurfaceResource> CWLSurfaceResource::fromResource(wl_resource* res) {
auto data = (CWLSurfaceResource*)(((CWlSurface*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
bool CWLSurfaceResource::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CWLSurfaceResource::client() {
return pClient;
return m_client;
}
void CWLSurfaceResource::enter(PHLMONITOR monitor) {
if (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) != enteredOutputs.end())
if (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) != m_enteredOutputs.end())
return;
if UNLIKELY (!PROTO::outputs.contains(monitor->m_name)) {
@ -282,59 +282,59 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) {
return;
}
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(pClient);
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client);
if UNLIKELY (!output || !output->getResource() || !output->getResource()->resource()) {
LOGM(ERR, "Cannot enter surface {:x} to {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name);
return;
}
enteredOutputs.emplace_back(monitor);
m_enteredOutputs.emplace_back(monitor);
resource->sendEnter(output->getResource().get());
m_resource->sendEnter(output->getResource().get());
}
void CWLSurfaceResource::leave(PHLMONITOR monitor) {
if UNLIKELY (std::find(enteredOutputs.begin(), enteredOutputs.end(), monitor) == enteredOutputs.end())
if UNLIKELY (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) == m_enteredOutputs.end())
return;
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(pClient);
auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client);
if UNLIKELY (!output) {
LOGM(ERR, "Cannot leave surface {:x} from {}, client hasn't bound the output", (uintptr_t)this, monitor->m_name);
return;
}
std::erase(enteredOutputs, monitor);
std::erase(m_enteredOutputs, monitor);
resource->sendLeave(output->getResource().get());
m_resource->sendLeave(output->getResource().get());
}
void CWLSurfaceResource::sendPreferredTransform(wl_output_transform t) {
if (resource->version() < 6)
if (m_resource->version() < 6)
return;
resource->sendPreferredBufferTransform(t);
m_resource->sendPreferredBufferTransform(t);
}
void CWLSurfaceResource::sendPreferredScale(int32_t scale) {
if (resource->version() < 6)
if (m_resource->version() < 6)
return;
resource->sendPreferredBufferScale(scale);
m_resource->sendPreferredBufferScale(scale);
}
void CWLSurfaceResource::frame(const Time::steady_tp& now) {
if (callbacks.empty())
if (m_callbacks.empty())
return;
for (auto const& c : callbacks) {
for (auto const& c : m_callbacks) {
c->send(now);
}
callbacks.clear();
m_callbacks.clear();
}
void CWLSurfaceResource::resetRole() {
role = makeShared<CDefaultSurfaceRole>();
m_role = makeShared<CDefaultSurfaceRole>();
}
void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data) {
@ -343,14 +343,14 @@ void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nod
// first, gather all nodes below
for (auto const& n : nodes) {
std::erase_if(n->subsurfaces, [](const auto& e) { return e.expired(); });
std::erase_if(n->m_subsurfaces, [](const auto& e) { return e.expired(); });
// subsurfaces is sorted lowest -> highest
for (auto const& c : n->subsurfaces) {
if (c->zIndex >= 0)
for (auto const& c : n->m_subsurfaces) {
if (c->m_zIndex >= 0)
break;
if (c->surface.expired())
if (c->m_surface.expired())
continue;
nodes2.push_back(c->surface.lock());
nodes2.push_back(c->m_surface.lock());
}
}
@ -361,8 +361,8 @@ void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nod
for (auto const& n : nodes) {
Vector2D offset = {};
if (n->role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)n->role.get())->subsurface.lock();
if (n->m_role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)n->m_role.get())->m_subsurface.lock();
offset = subsurface->posRelativeToParent();
}
@ -370,12 +370,12 @@ void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nod
}
for (auto const& n : nodes) {
for (auto const& c : n->subsurfaces) {
if (c->zIndex < 0)
for (auto const& c : n->m_subsurfaces) {
if (c->m_zIndex < 0)
continue;
if (c->surface.expired())
if (c->m_surface.expired())
continue;
nodes2.push_back(c->surface.lock());
nodes2.push_back(c->m_surface.lock());
}
}
@ -385,17 +385,17 @@ void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nod
void CWLSurfaceResource::breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data) {
std::vector<SP<CWLSurfaceResource>> surfs;
surfs.push_back(self.lock());
surfs.push_back(m_self.lock());
bfHelper(surfs, fn, data);
}
SP<CWLSurfaceResource> CWLSurfaceResource::findFirstPreorderHelper(SP<CWLSurfaceResource> root, std::function<bool(SP<CWLSurfaceResource>)> fn) {
if (fn(root))
return root;
for (auto const& sub : root->subsurfaces) {
if (sub.expired() || sub->surface.expired())
for (auto const& sub : root->m_subsurfaces) {
if (sub.expired() || sub->m_surface.expired())
continue;
const auto found = findFirstPreorderHelper(sub->surface.lock(), fn);
const auto found = findFirstPreorderHelper(sub->m_surface.lock(), fn);
if (found)
return found;
}
@ -403,7 +403,7 @@ SP<CWLSurfaceResource> CWLSurfaceResource::findFirstPreorderHelper(SP<CWLSurface
}
SP<CWLSurfaceResource> CWLSurfaceResource::findFirstPreorder(std::function<bool(SP<CWLSurfaceResource>)> fn) {
return findFirstPreorderHelper(self.lock(), fn);
return findFirstPreorderHelper(m_self.lock(), fn);
}
std::pair<SP<CWLSurfaceResource>, Vector2D> CWLSurfaceResource::at(const Vector2D& localCoords, bool allowsInput) {
@ -412,11 +412,11 @@ std::pair<SP<CWLSurfaceResource>, Vector2D> CWLSurfaceResource::at(const Vector2
for (auto const& [surf, pos] : surfs | std::views::reverse) {
if (!allowsInput) {
const auto BOX = CBox{pos, surf->current.size};
const auto BOX = CBox{pos, surf->m_current.size};
if (BOX.containsPoint(localCoords))
return {surf, localCoords - pos};
} else {
const auto REGION = surf->current.input.copy().intersect(CBox{{}, surf->current.size}).translate(pos);
const auto REGION = surf->m_current.input.copy().intersect(CBox{{}, surf->m_current.size}).translate(pos);
if (REGION.containsPoint(localCoords))
return {surf, localCoords - pos};
}
@ -426,26 +426,26 @@ std::pair<SP<CWLSurfaceResource>, Vector2D> CWLSurfaceResource::at(const Vector2
}
uint32_t CWLSurfaceResource::id() {
return wl_resource_get_id(resource->resource());
return wl_resource_get_id(m_resource->resource());
}
void CWLSurfaceResource::map() {
if UNLIKELY (mapped)
if UNLIKELY (m_mapped)
return;
mapped = true;
m_mapped = true;
frame(Time::steadyNow());
current.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
m_current.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
m_pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
}
void CWLSurfaceResource::unmap() {
if UNLIKELY (!mapped)
if UNLIKELY (!m_mapped)
return;
mapped = false;
m_mapped = false;
// release the buffers.
// this is necessary for XWayland to function correctly,
@ -460,66 +460,66 @@ void CWLSurfaceResource::releaseBuffers(bool onlyCurrent) {
}
void CWLSurfaceResource::error(int code, const std::string& str) {
resource->error(code, str);
m_resource->error(code, str);
}
SP<CWlSurface> CWLSurfaceResource::getResource() {
return resource;
return m_resource;
}
CBox CWLSurfaceResource::extends() {
CRegion full = CBox{{}, current.size};
CRegion full = CBox{{}, m_current.size};
breadthfirst(
[](SP<CWLSurfaceResource> surf, const Vector2D& offset, void* d) {
if (surf->role->role() != SURFACE_ROLE_SUBSURFACE)
if (surf->m_role->role() != SURFACE_ROLE_SUBSURFACE)
return;
((CRegion*)d)->add(CBox{offset, surf->current.size});
((CRegion*)d)->add(CBox{offset, surf->m_current.size});
},
&full);
return full.getExtents();
}
void CWLSurfaceResource::commitState(SSurfaceState& state) {
auto lastTexture = current.texture;
current.updateFrom(state);
auto lastTexture = m_current.texture;
m_current.updateFrom(state);
if (current.buffer) {
if (current.buffer->isSynchronous())
current.updateSynchronousTexture(lastTexture);
if (m_current.buffer) {
if (m_current.buffer->isSynchronous())
m_current.updateSynchronousTexture(lastTexture);
// if the surface is a cursor, update the shm buffer
// TODO: don't update the entire texture
if (role->role() == SURFACE_ROLE_CURSOR)
updateCursorShm(current.accumulateBufferDamage());
if (m_role->role() == SURFACE_ROLE_CURSOR)
updateCursorShm(m_current.accumulateBufferDamage());
}
if (current.texture)
current.texture->m_eTransform = wlTransformToHyprutils(current.transform);
if (m_current.texture)
m_current.texture->m_eTransform = wlTransformToHyprutils(m_current.transform);
if (role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)role.get())->subsurface.lock();
if (subsurface->sync)
if (m_role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)m_role.get())->m_subsurface.lock();
if (subsurface->m_sync)
return;
events.commit.emit();
m_events.commit.emit();
} else {
// send commit to all synced surfaces in this tree.
breadthfirst(
[](SP<CWLSurfaceResource> surf, const Vector2D& offset, void* data) {
if (surf->role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)surf->role.get())->subsurface.lock();
if (!subsurface->sync)
if (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)surf->m_role.get())->m_subsurface.lock();
if (!subsurface->m_sync)
return;
}
surf->events.commit.emit();
surf->m_events.commit.emit();
},
nullptr);
}
// release the buffer if it's synchronous (SHM) as updateSynchronousTexture() has copied the buffer data to a GPU tex
// if it doesn't have a role, we can't release it yet, in case it gets turned into a cursor.
if (current.buffer && current.buffer->isSynchronous() && role->role() != SURFACE_ROLE_UNASSIGNED)
if (m_current.buffer && m_current.buffer->isSynchronous() && m_role->role() != SURFACE_ROLE_UNASSIGNED)
dropCurrentBuffer();
}
@ -527,12 +527,12 @@ void CWLSurfaceResource::updateCursorShm(CRegion damage) {
if (damage.empty())
return;
auto buf = current.buffer ? current.buffer : SP<IHLBuffer>{};
auto buf = m_current.buffer ? m_current.buffer : SP<IHLBuffer>{};
if UNLIKELY (!buf)
return;
auto& shmData = CCursorSurfaceRole::cursorPixelData(self.lock());
auto& shmData = CCursorSurfaceRole::cursorPixelData(m_self.lock());
auto shmAttrs = buf->shm();
if (!shmAttrs.success) {
@ -563,7 +563,7 @@ void CWLSurfaceResource::updateCursorShm(CRegion damage) {
void CWLSurfaceResource::presentFeedback(const Time::steady_tp& when, PHLMONITOR pMonitor, bool discarded) {
frame(when);
auto FEEDBACK = makeShared<CQueuedPresentationData>(self.lock());
auto FEEDBACK = makeShared<CQueuedPresentationData>(m_self.lock());
FEEDBACK->attachMonitor(pMonitor);
if (discarded)
FEEDBACK->discarded();
@ -572,45 +572,45 @@ void CWLSurfaceResource::presentFeedback(const Time::steady_tp& when, PHLMONITOR
PROTO::presentation->queueData(FEEDBACK);
}
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : resource(resource_) {
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlCompositor* r) { PROTO::compositor->destroyResource(this); });
m_resource->setOnDestroy([this](CWlCompositor* r) { PROTO::compositor->destroyResource(this); });
resource->setCreateSurface([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vSurfaces.emplace_back(makeShared<CWLSurfaceResource>(makeShared<CWlSurface>(r->client(), r->version(), id)));
m_resource->setCreateSurface([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_surfaces.emplace_back(makeShared<CWLSurfaceResource>(makeShared<CWlSurface>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vSurfaces.pop_back();
PROTO::compositor->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
LOGM(LOG, "New wl_surface with id {} at {:x}", id, (uintptr_t)RESOURCE.get());
PROTO::compositor->events.newSurface.emit(RESOURCE);
PROTO::compositor->m_events.newSurface.emit(RESOURCE);
});
resource->setCreateRegion([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_vRegions.emplace_back(makeShared<CWLRegionResource>(makeShared<CWlRegion>(r->client(), r->version(), id)));
m_resource->setCreateRegion([](CWlCompositor* r, uint32_t id) {
const auto RESOURCE = PROTO::compositor->m_regions.emplace_back(makeShared<CWLRegionResource>(makeShared<CWlRegion>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::compositor->m_vRegions.pop_back();
PROTO::compositor->m_regions.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
LOGM(LOG, "New wl_region with id {} at {:x}", id, (uintptr_t)RESOURCE.get());
});
}
bool CWLCompositorResource::good() {
return resource->resource();
return m_resource->resource();
}
CWLCompositorProtocol::CWLCompositorProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -618,29 +618,29 @@ CWLCompositorProtocol::CWLCompositorProtocol(const wl_interface* iface, const in
}
void CWLCompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLCompositorResource>(makeShared<CWlCompositor>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CWLCompositorResource>(makeShared<CWlCompositor>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CWLCompositorProtocol::destroyResource(CWLCompositorResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CWLCompositorProtocol::destroyResource(CWLSurfaceResource* resource) {
std::erase_if(m_vSurfaces, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_surfaces, [&](const auto& other) { return other.get() == resource; });
}
void CWLCompositorProtocol::destroyResource(CWLRegionResource* resource) {
std::erase_if(m_vRegions, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_regions, [&](const auto& other) { return other.get() == resource; });
}
void CWLCompositorProtocol::forEachSurface(std::function<void(SP<CWLSurfaceResource>)> fn) {
for (auto& surf : m_vSurfaces) {
for (auto& surf : m_surfaces) {
fn(surf);
}
}

View file

@ -40,7 +40,7 @@ class CWLCallbackResource {
void send(const Time::steady_tp& now);
private:
SP<CWlCallback> resource;
SP<CWlCallback> m_resource;
};
class CWLRegionResource {
@ -50,11 +50,11 @@ class CWLRegionResource {
bool good();
CRegion region;
WP<CWLRegionResource> self;
CRegion m_region;
WP<CWLRegionResource> m_self;
private:
SP<CWlRegion> resource;
SP<CWlRegion> m_resource;
};
class CWLSurfaceResource {
@ -86,22 +86,22 @@ class CWLSurfaceResource {
CSignal unmap;
CSignal newSubsurface;
CSignal destroy;
} events;
} m_events;
SSurfaceState current, pending;
std::queue<UP<SSurfaceState>> pendingStates;
SSurfaceState m_current;
SSurfaceState m_pending;
std::queue<UP<SSurfaceState>> m_pendingStates;
std::vector<SP<CWLCallbackResource>> callbacks;
WP<CWLSurfaceResource> self;
WP<CWLSurface> hlSurface;
std::vector<PHLMONITORREF> enteredOutputs;
bool mapped = false;
std::vector<WP<CWLSubsurfaceResource>> subsurfaces;
SP<ISurfaceRole> role;
WP<CViewportResource> viewportResource;
WP<CDRMSyncobjSurfaceResource> syncobj; // may not be present
WP<CColorManagementSurface> colorManagement;
WP<CContentType> contentType;
std::vector<SP<CWLCallbackResource>> m_callbacks;
WP<CWLSurfaceResource> m_self;
WP<CWLSurface> m_hlSurface;
std::vector<PHLMONITORREF> m_enteredOutputs;
bool m_mapped = false;
std::vector<WP<CWLSubsurfaceResource>> m_subsurfaces;
SP<ISurfaceRole> m_role;
WP<CDRMSyncobjSurfaceResource> m_syncobj; // may not be present
WP<CColorManagementSurface> m_colorManagement;
WP<CContentType> m_contentType;
void breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
SP<CWLSurfaceResource> findFirstPreorder(std::function<bool(SP<CWLSurfaceResource>)> fn);
@ -113,8 +113,8 @@ class CWLSurfaceResource {
std::pair<SP<CWLSurfaceResource>, Vector2D> at(const Vector2D& localCoords, bool allowsInput = false);
private:
SP<CWlSurface> resource;
wl_client* pClient = nullptr;
SP<CWlSurface> m_resource;
wl_client* m_client = nullptr;
void destroy();
void releaseBuffers(bool onlyCurrent = true);
@ -134,7 +134,7 @@ class CWLCompositorResource {
bool good();
private:
SP<CWlCompositor> resource;
SP<CWlCompositor> m_resource;
};
class CWLCompositorProtocol : public IWaylandProtocol {
@ -147,7 +147,7 @@ class CWLCompositorProtocol : public IWaylandProtocol {
struct {
CSignal newSurface; // SP<CWLSurfaceResource>
} events;
} m_events;
private:
void destroyResource(CWLCompositorResource* resource);
@ -155,9 +155,9 @@ class CWLCompositorProtocol : public IWaylandProtocol {
void destroyResource(CWLRegionResource* resource);
//
std::vector<SP<CWLCompositorResource>> m_vManagers;
std::vector<SP<CWLSurfaceResource>> m_vSurfaces;
std::vector<SP<CWLRegionResource>> m_vRegions;
std::vector<SP<CWLCompositorResource>> m_managers;
std::vector<SP<CWLSurfaceResource>> m_surfaces;
std::vector<SP<CWLRegionResource>> m_regions;
friend class CWLSurfaceResource;
friend class CWLCompositorResource;

View file

@ -16,60 +16,60 @@
#include "../../xwayland/Dnd.hpp"
using namespace Hyprutils::OS;
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : m_source(source_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); });
resource->setOnDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); });
m_resource->setDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); });
m_resource->setOnDestroy([this](CWlDataOffer* r) { PROTO::data->destroyResource(this); });
resource->setAccept([this](CWlDataOffer* r, uint32_t serial, const char* mime) {
if (!source) {
m_resource->setAccept([this](CWlDataOffer* r, uint32_t serial, const char* mime) {
if (!m_source) {
LOGM(WARN, "Possible bug: Accept on an offer w/o a source");
return;
}
if (dead) {
if (m_dead) {
LOGM(WARN, "Possible bug: Accept on an offer that's dead");
return;
}
LOGM(LOG, "Offer {:x} accepts data from source {:x} with mime {}", (uintptr_t)this, (uintptr_t)source.get(), mime ? mime : "null");
LOGM(LOG, "Offer {:x} accepts data from source {:x} with mime {}", (uintptr_t)this, (uintptr_t)m_source.get(), mime ? mime : "null");
source->accepted(mime ? mime : "");
accepted = mime;
m_source->accepted(mime ? mime : "");
m_accepted = mime;
});
resource->setReceive([this](CWlDataOffer* r, const char* mime, int fd) {
m_resource->setReceive([this](CWlDataOffer* r, const char* mime, int fd) {
CFileDescriptor sendFd{fd};
if (!source) {
if (!m_source) {
LOGM(WARN, "Possible bug: Receive on an offer w/o a source");
return;
}
if (dead) {
if (m_dead) {
LOGM(WARN, "Possible bug: Receive on an offer that's dead");
return;
}
LOGM(LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)source.get());
LOGM(LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get());
if (!accepted) {
if (!m_accepted) {
LOGM(WARN, "Offer was never accepted, sending accept first");
source->accepted(mime ? mime : "");
m_source->accepted(mime ? mime : "");
}
source->send(mime ? mime : "", std::move(sendFd));
m_source->send(mime ? mime : "", std::move(sendFd));
recvd = true;
m_recvd = true;
// if (source->hasDnd())
// PROTO::data->completeDrag();
});
resource->setFinish([this](CWlDataOffer* r) {
dead = true;
if (!source || !recvd || !accepted)
m_resource->setFinish([this](CWlDataOffer* r) {
m_dead = true;
if (!m_source || !m_recvd || !m_accepted)
PROTO::data->abortDrag();
else
PROTO::data->completeDrag();
@ -77,37 +77,37 @@ CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataS
}
CWLDataOfferResource::~CWLDataOfferResource() {
if (!source || !source->hasDnd() || dead)
if (!m_source || !m_source->hasDnd() || m_dead)
return;
source->sendDndFinished();
m_source->sendDndFinished();
}
bool CWLDataOfferResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLDataOfferResource::sendData() {
if (!source)
if (!m_source)
return;
const auto SOURCEACTIONS = source->actions();
const auto SOURCEACTIONS = m_source->actions();
if (resource->version() >= 3 && SOURCEACTIONS > 0) {
resource->sendSourceActions(SOURCEACTIONS);
if (m_resource->version() >= 3 && SOURCEACTIONS > 0) {
m_resource->sendSourceActions(SOURCEACTIONS);
if (SOURCEACTIONS & WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE)
resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
m_resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
else if (SOURCEACTIONS & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY)
resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
m_resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY);
else {
LOGM(ERR, "Client bug? dnd source has no action move or copy. Sending move, f this.");
resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
m_resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
}
}
for (auto const& m : source->mimes()) {
for (auto const& m : m_source->mimes()) {
LOGM(LOG, " | offer {:x} supports mime {}", (uintptr_t)this, m);
resource->sendOffer(m.c_str());
m_resource->sendOffer(m.c_str());
}
}
@ -116,7 +116,7 @@ eDataSourceType CWLDataOfferResource::type() {
}
SP<CWLDataOfferResource> CWLDataOfferResource::getWayland() {
return self.lock();
return m_self.lock();
}
SP<CX11DataOffer> CWLDataOfferResource::getX11() {
@ -124,127 +124,127 @@ SP<CX11DataOffer> CWLDataOfferResource::getX11() {
}
SP<IDataSource> CWLDataOfferResource::getSource() {
return source.lock();
return m_source.lock();
}
CWLDataSourceResource::CWLDataSourceResource(SP<CWlDataSource> resource_, SP<CWLDataDeviceResource> device_) : device(device_), resource(resource_) {
CWLDataSourceResource::CWLDataSourceResource(SP<CWlDataSource> resource_, SP<CWLDataDeviceResource> device_) : m_device(device_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
resource->setDestroy([this](CWlDataSource* r) {
m_resource->setDestroy([this](CWlDataSource* r) {
events.destroy.emit();
PROTO::data->onDestroyDataSource(self);
PROTO::data->onDestroyDataSource(m_self);
PROTO::data->destroyResource(this);
});
resource->setOnDestroy([this](CWlDataSource* r) {
m_resource->setOnDestroy([this](CWlDataSource* r) {
events.destroy.emit();
PROTO::data->onDestroyDataSource(self);
PROTO::data->onDestroyDataSource(m_self);
PROTO::data->destroyResource(this);
});
resource->setOffer([this](CWlDataSource* r, const char* mime) { mimeTypes.emplace_back(mime); });
resource->setSetActions([this](CWlDataSource* r, uint32_t a) {
m_resource->setOffer([this](CWlDataSource* r, const char* mime) { m_mimeTypes.emplace_back(mime); });
m_resource->setSetActions([this](CWlDataSource* r, uint32_t a) {
LOGM(LOG, "DataSource {:x} actions {}", (uintptr_t)this, a);
supportedActions = a;
m_supportedActions = a;
});
}
CWLDataSourceResource::~CWLDataSourceResource() {
events.destroy.emit();
PROTO::data->onDestroyDataSource(self);
PROTO::data->onDestroyDataSource(m_self);
}
SP<CWLDataSourceResource> CWLDataSourceResource::fromResource(wl_resource* res) {
auto data = (CWLDataSourceResource*)(((CWlDataSource*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
bool CWLDataSourceResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLDataSourceResource::accepted(const std::string& mime) {
if (mime.empty()) {
resource->sendTarget(nullptr);
m_resource->sendTarget(nullptr);
return;
}
if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end()) {
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) {
LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAccepted with non-existent mime");
return;
}
resource->sendTarget(mime.c_str());
m_resource->sendTarget(mime.c_str());
}
std::vector<std::string> CWLDataSourceResource::mimes() {
return mimeTypes;
return m_mimeTypes;
}
void CWLDataSourceResource::send(const std::string& mime, CFileDescriptor fd) {
if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end()) {
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) {
LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAskSend with non-existent mime");
return;
}
resource->sendSend(mime.c_str(), fd.get());
m_resource->sendSend(mime.c_str(), fd.get());
}
void CWLDataSourceResource::cancelled() {
resource->sendCancelled();
m_resource->sendCancelled();
}
bool CWLDataSourceResource::hasDnd() {
return dnd;
return m_dnd;
}
bool CWLDataSourceResource::dndDone() {
return dndSuccess;
return m_dndSuccess;
}
void CWLDataSourceResource::error(uint32_t code, const std::string& msg) {
resource->error(code, msg);
m_resource->error(code, msg);
}
void CWLDataSourceResource::sendDndDropPerformed() {
if (resource->version() < 3)
if (m_resource->version() < 3)
return;
resource->sendDndDropPerformed();
dropped = true;
m_resource->sendDndDropPerformed();
m_dropped = true;
}
void CWLDataSourceResource::sendDndFinished() {
if (resource->version() < 3)
if (m_resource->version() < 3)
return;
resource->sendDndFinished();
m_resource->sendDndFinished();
}
void CWLDataSourceResource::sendDndAction(wl_data_device_manager_dnd_action a) {
if (resource->version() < 3)
if (m_resource->version() < 3)
return;
resource->sendAction(a);
m_resource->sendAction(a);
}
uint32_t CWLDataSourceResource::actions() {
return supportedActions;
return m_supportedActions;
}
eDataSourceType CWLDataSourceResource::type() {
return DATA_SOURCE_TYPE_WAYLAND;
}
CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : resource(resource_) {
CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
resource->setOnDestroy([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
m_resource->setRelease([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
m_resource->setOnDestroy([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
pClient = resource->client();
m_client = m_resource->client();
resource->setSetSelection([](CWlDataDevice* r, wl_resource* sourceR, uint32_t serial) {
m_resource->setSetSelection([](CWlDataDevice* r, wl_resource* sourceR, uint32_t serial) {
auto source = sourceR ? CWLDataSourceResource::fromResource(sourceR) : CSharedPointer<CWLDataSourceResource>{};
if (!source) {
LOGM(LOG, "Reset selection received");
@ -252,7 +252,7 @@ CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : reso
return;
}
if (source && source->used)
if (source && source->m_used)
LOGM(WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");
source->markUsed();
@ -260,63 +260,63 @@ CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : reso
g_pSeatManager->setCurrentSelection(source);
});
resource->setStartDrag([](CWlDataDevice* r, wl_resource* sourceR, wl_resource* origin, wl_resource* icon, uint32_t serial) {
m_resource->setStartDrag([](CWlDataDevice* r, wl_resource* sourceR, wl_resource* origin, wl_resource* icon, uint32_t serial) {
auto source = CWLDataSourceResource::fromResource(sourceR);
if (!source) {
LOGM(ERR, "No source in drag");
return;
}
if (source && source->used)
if (source && source->m_used)
LOGM(WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");
source->markUsed();
source->dnd = true;
source->m_dnd = true;
PROTO::data->initiateDrag(source, icon ? CWLSurfaceResource::fromResource(icon) : nullptr, CWLSurfaceResource::fromResource(origin));
});
}
bool CWLDataDeviceResource::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CWLDataDeviceResource::client() {
return pClient;
return m_client;
}
void CWLDataDeviceResource::sendDataOffer(SP<IDataOffer> offer) {
if (!offer)
resource->sendDataOfferRaw(nullptr);
m_resource->sendDataOfferRaw(nullptr);
else if (const auto WL = offer->getWayland(); WL)
resource->sendDataOffer(WL->resource.get());
m_resource->sendDataOffer(WL->m_resource.get());
//FIXME: X11
}
void CWLDataDeviceResource::sendEnter(uint32_t serial, SP<CWLSurfaceResource> surf, const Vector2D& local, SP<IDataOffer> offer) {
if (const auto WL = offer->getWayland(); WL)
resource->sendEnterRaw(serial, surf->getResource()->resource(), wl_fixed_from_double(local.x), wl_fixed_from_double(local.y), WL->resource->resource());
m_resource->sendEnterRaw(serial, surf->getResource()->resource(), wl_fixed_from_double(local.x), wl_fixed_from_double(local.y), WL->m_resource->resource());
// FIXME: X11
}
void CWLDataDeviceResource::sendLeave() {
resource->sendLeave();
m_resource->sendLeave();
}
void CWLDataDeviceResource::sendMotion(uint32_t timeMs, const Vector2D& local) {
resource->sendMotion(timeMs, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
m_resource->sendMotion(timeMs, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
}
void CWLDataDeviceResource::sendDrop() {
resource->sendDrop();
m_resource->sendDrop();
}
void CWLDataDeviceResource::sendSelection(SP<IDataOffer> offer) {
if (!offer)
resource->sendSelectionRaw(nullptr);
m_resource->sendSelectionRaw(nullptr);
else if (const auto WL = offer->getWayland(); WL)
resource->sendSelection(WL->resource.get());
m_resource->sendSelection(WL->m_resource.get());
}
eDataSourceType CWLDataDeviceResource::type() {
@ -324,55 +324,55 @@ eDataSourceType CWLDataDeviceResource::type() {
}
SP<CWLDataDeviceResource> CWLDataDeviceResource::getWayland() {
return self.lock();
return m_self.lock();
}
SP<CX11DataDevice> CWLDataDeviceResource::getX11() {
return nullptr;
}
CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManager> resource_) : resource(resource_) {
CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManager> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlDataDeviceManager* r) { PROTO::data->destroyResource(this); });
m_resource->setOnDestroy([this](CWlDataDeviceManager* r) { PROTO::data->destroyResource(this); });
resource->setCreateDataSource([this](CWlDataDeviceManager* r, uint32_t id) {
std::erase_if(sources, [](const auto& e) { return e.expired(); });
m_resource->setCreateDataSource([this](CWlDataDeviceManager* r, uint32_t id) {
std::erase_if(m_sources, [](const auto& e) { return e.expired(); });
const auto RESOURCE = PROTO::data->m_vSources.emplace_back(makeShared<CWLDataSourceResource>(makeShared<CWlDataSource>(r->client(), r->version(), id), device.lock()));
const auto RESOURCE = PROTO::data->m_sources.emplace_back(makeShared<CWLDataSourceResource>(makeShared<CWlDataSource>(r->client(), r->version(), id), m_device.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::data->m_vSources.pop_back();
PROTO::data->m_sources.pop_back();
return;
}
if (!device)
if (!m_device)
LOGM(WARN, "New data source before a device was created");
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
sources.emplace_back(RESOURCE);
m_sources.emplace_back(RESOURCE);
LOGM(LOG, "New data source bound at {:x}", (uintptr_t)RESOURCE.get());
});
resource->setGetDataDevice([this](CWlDataDeviceManager* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::data->m_vDevices.emplace_back(makeShared<CWLDataDeviceResource>(makeShared<CWlDataDevice>(r->client(), r->version(), id)));
m_resource->setGetDataDevice([this](CWlDataDeviceManager* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::data->m_devices.emplace_back(makeShared<CWLDataDeviceResource>(makeShared<CWlDataDevice>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::data->m_vDevices.pop_back();
PROTO::data->m_devices.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
for (auto const& s : sources) {
for (auto const& s : m_sources) {
if (!s)
continue;
s->device = RESOURCE;
s->m_device = RESOURCE;
}
LOGM(LOG, "New data device bound at {:x}", (uintptr_t)RESOURCE.get());
@ -380,22 +380,22 @@ CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManag
}
bool CWLDataDeviceManagerResource::good() {
return resource->resource();
return m_resource->resource();
}
CWLDataDeviceProtocol::CWLDataDeviceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
g_pEventLoopManager->doLater([this]() {
listeners.onKeyboardFocusChange = g_pSeatManager->m_events.keyboardFocusChange.registerListener([this](std::any d) { onKeyboardFocus(); });
listeners.onDndPointerFocusChange = g_pSeatManager->m_events.dndPointerFocusChange.registerListener([this](std::any d) { onDndPointerFocus(); });
m_listeners.onKeyboardFocusChange = g_pSeatManager->m_events.keyboardFocusChange.registerListener([this](std::any d) { onKeyboardFocus(); });
m_listeners.onDndPointerFocusChange = g_pSeatManager->m_events.dndPointerFocusChange.registerListener([this](std::any d) { onDndPointerFocus(); });
});
}
void CWLDataDeviceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLDataDeviceManagerResource>(makeShared<CWlDataDeviceManager>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CWLDataDeviceManagerResource>(makeShared<CWlDataDeviceManager>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
@ -403,19 +403,19 @@ void CWLDataDeviceProtocol::bindManager(wl_client* client, void* data, uint32_t
}
void CWLDataDeviceProtocol::destroyResource(CWLDataDeviceManagerResource* seat) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == seat; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == seat; });
}
void CWLDataDeviceProtocol::destroyResource(CWLDataDeviceResource* resource) {
std::erase_if(m_vDevices, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_devices, [&](const auto& other) { return other.get() == resource; });
}
void CWLDataDeviceProtocol::destroyResource(CWLDataSourceResource* resource) {
std::erase_if(m_vSources, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_sources, [&](const auto& other) { return other.get() == resource; });
}
void CWLDataDeviceProtocol::destroyResource(CWLDataOfferResource* resource) {
std::erase_if(m_vOffers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_offers, [&](const auto& other) { return other.get() == resource; });
}
SP<IDataDevice> CWLDataDeviceProtocol::dataDeviceForClient(wl_client* c) {
@ -424,8 +424,8 @@ SP<IDataDevice> CWLDataDeviceProtocol::dataDeviceForClient(wl_client* c) {
return g_pXWayland->pWM->getDataDevice();
#endif
auto it = std::find_if(m_vDevices.begin(), m_vDevices.end(), [c](const auto& e) { return e->client() == c; });
if (it == m_vDevices.end())
auto it = std::find_if(m_devices.begin(), m_devices.end(), [c](const auto& e) { return e->client() == c; });
if (it == m_devices.end())
return nullptr;
return *it;
}
@ -439,15 +439,15 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP<IDataDevice> dev, SP<IDataS
SP<IDataOffer> offer;
if (const auto WL = dev->getWayland(); WL) {
const auto OFFER = m_vOffers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(WL->resource->client(), WL->resource->version(), 0), sel));
const auto OFFER = m_offers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(WL->m_resource->client(), WL->m_resource->version(), 0), sel));
if UNLIKELY (!OFFER->good()) {
WL->resource->noMemory();
m_vOffers.pop_back();
WL->m_resource->noMemory();
m_offers.pop_back();
return;
}
OFFER->source = sel;
OFFER->self = OFFER;
offer = OFFER;
OFFER->m_source = sel;
OFFER->m_self = OFFER;
offer = OFFER;
}
#ifndef NO_XWAYLAND
else if (const auto X11 = dev->getX11(); X11)
@ -468,15 +468,15 @@ void CWLDataDeviceProtocol::sendSelectionToDevice(SP<IDataDevice> dev, SP<IDataS
}
void CWLDataDeviceProtocol::onDestroyDataSource(WP<CWLDataSourceResource> source) {
if (dnd.currentSource == source)
if (m_dnd.currentSource == source)
abortDrag();
}
void CWLDataDeviceProtocol::setSelection(SP<IDataSource> source) {
for (auto const& o : m_vOffers) {
if (o->source && o->source->hasDnd())
for (auto const& o : m_offers) {
if (o->m_source && o->m_source->hasDnd())
continue;
o->dead = true;
o->m_dead = true;
}
if (!source) {
@ -527,20 +527,20 @@ void CWLDataDeviceProtocol::updateSelection() {
}
void CWLDataDeviceProtocol::onKeyboardFocus() {
for (auto const& o : m_vOffers) {
if (o->source && o->source->hasDnd())
for (auto const& o : m_offers) {
if (o->m_source && o->m_source->hasDnd())
continue;
o->dead = true;
o->m_dead = true;
}
updateSelection();
}
void CWLDataDeviceProtocol::onDndPointerFocus() {
for (auto const& o : m_vOffers) {
if (o->source && !o->source->hasDnd())
for (auto const& o : m_offers) {
if (o->m_source && !o->m_source->hasDnd())
continue;
o->dead = true;
o->m_dead = true;
}
updateDrag();
@ -548,37 +548,37 @@ void CWLDataDeviceProtocol::onDndPointerFocus() {
void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource, SP<CWLSurfaceResource> dragSurface, SP<CWLSurfaceResource> origin) {
if (dnd.currentSource) {
if (m_dnd.currentSource) {
LOGM(WARN, "New drag started while old drag still active??");
abortDrag();
}
g_pInputManager->setCursorImageUntilUnset("grabbing");
dnd.overriddenCursor = true;
m_dnd.overriddenCursor = true;
LOGM(LOG, "initiateDrag: source {:x}, surface: {:x}, origin: {:x}", (uintptr_t)currentSource.get(), (uintptr_t)dragSurface, (uintptr_t)origin);
currentSource->used = true;
currentSource->m_used = true;
dnd.currentSource = currentSource;
dnd.originSurface = origin;
dnd.dndSurface = dragSurface;
m_dnd.currentSource = currentSource;
m_dnd.originSurface = origin;
m_dnd.dndSurface = dragSurface;
if (dragSurface) {
dnd.dndSurfaceDestroy = dragSurface->events.destroy.registerListener([this](std::any d) { abortDrag(); });
dnd.dndSurfaceCommit = dragSurface->events.commit.registerListener([this](std::any d) {
if (dnd.dndSurface->current.texture && !dnd.dndSurface->mapped) {
dnd.dndSurface->map();
m_dnd.dndSurfaceDestroy = dragSurface->m_events.destroy.registerListener([this](std::any d) { abortDrag(); });
m_dnd.dndSurfaceCommit = dragSurface->m_events.commit.registerListener([this](std::any d) {
if (m_dnd.dndSurface->m_current.texture && !m_dnd.dndSurface->m_mapped) {
m_dnd.dndSurface->map();
return;
}
if (dnd.dndSurface->current.texture <= 0 && dnd.dndSurface->mapped) {
dnd.dndSurface->unmap();
if (m_dnd.dndSurface->m_current.texture <= 0 && m_dnd.dndSurface->m_mapped) {
m_dnd.dndSurface->unmap();
return;
}
});
}
dnd.mouseButton = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any e) {
m_dnd.mouseButton = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any e) {
auto E = std::any_cast<IPointer::SButtonEvent>(e);
if (E.state == WL_POINTER_BUTTON_STATE_RELEASED) {
LOGM(LOG, "Dropping drag on mouseUp");
@ -586,14 +586,14 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
}
});
dnd.touchUp = g_pHookSystem->hookDynamic("touchUp", [this](void* self, SCallbackInfo& info, std::any e) {
m_dnd.touchUp = g_pHookSystem->hookDynamic("touchUp", [this](void* self, SCallbackInfo& info, std::any e) {
LOGM(LOG, "Dropping drag on touchUp");
dropDrag();
});
dnd.mouseMove = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any e) {
m_dnd.mouseMove = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any e) {
auto V = std::any_cast<const Vector2D>(e);
if (dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
auto surf = CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock());
if (!surf)
@ -604,14 +604,14 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
if (!box.has_value())
return;
dnd.focusedDevice->sendMotion(Time::millis(Time::steadyNow()), V - box->pos());
m_dnd.focusedDevice->sendMotion(Time::millis(Time::steadyNow()), V - box->pos());
LOGM(LOG, "Drag motion {}", V - box->pos());
}
});
dnd.touchMove = g_pHookSystem->hookDynamic("touchMove", [this](void* self, SCallbackInfo& info, std::any e) {
m_dnd.touchMove = g_pHookSystem->hookDynamic("touchMove", [this](void* self, SCallbackInfo& info, std::any e) {
auto E = std::any_cast<ITouch::SMotionEvent>(e);
if (dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
if (m_dnd.focusedDevice && g_pSeatManager->m_state.dndPointerFocus) {
auto surf = CWLSurface::fromResource(g_pSeatManager->m_state.dndPointerFocus.lock());
if (!surf)
@ -622,7 +622,7 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
if (!box.has_value())
return;
dnd.focusedDevice->sendMotion(E.timeMs, E.pos);
m_dnd.focusedDevice->sendMotion(E.timeMs, E.pos);
LOGM(LOG, "Drag motion {}", E.pos);
}
});
@ -642,34 +642,34 @@ void CWLDataDeviceProtocol::updateDrag() {
if (!dndActive())
return;
if (dnd.focusedDevice)
dnd.focusedDevice->sendLeave();
if (m_dnd.focusedDevice)
m_dnd.focusedDevice->sendLeave();
if (!g_pSeatManager->m_state.dndPointerFocus)
return;
dnd.focusedDevice = dataDeviceForClient(g_pSeatManager->m_state.dndPointerFocus->client());
m_dnd.focusedDevice = dataDeviceForClient(g_pSeatManager->m_state.dndPointerFocus->client());
if (!dnd.focusedDevice)
if (!m_dnd.focusedDevice)
return;
SP<IDataOffer> offer;
if (const auto WL = dnd.focusedDevice->getWayland(); WL) {
if (const auto WL = m_dnd.focusedDevice->getWayland(); WL) {
const auto OFFER =
m_vOffers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(WL->resource->client(), WL->resource->version(), 0), dnd.currentSource.lock()));
m_offers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(WL->m_resource->client(), WL->m_resource->version(), 0), m_dnd.currentSource.lock()));
if (!OFFER->good()) {
WL->resource->noMemory();
m_vOffers.pop_back();
WL->m_resource->noMemory();
m_offers.pop_back();
return;
}
OFFER->source = dnd.currentSource;
OFFER->self = OFFER;
offer = OFFER;
OFFER->m_source = m_dnd.currentSource;
OFFER->m_self = OFFER;
offer = OFFER;
}
#ifndef NO_XWAYLAND
else if (const auto X11 = dnd.focusedDevice->getX11(); X11)
offer = g_pXWayland->pWM->createX11DataOffer(g_pSeatManager->m_state.keyboardFocus.lock(), dnd.currentSource.lock());
else if (const auto X11 = m_dnd.focusedDevice->getX11(); X11)
offer = g_pXWayland->pWM->createX11DataOffer(g_pSeatManager->m_state.keyboardFocus.lock(), m_dnd.currentSource.lock());
#endif
if (!offer) {
@ -678,28 +678,28 @@ void CWLDataDeviceProtocol::updateDrag() {
}
LOGM(LOG, "New {} dnd offer {:x} for data source {:x}", offer->type() == DATA_SOURCE_TYPE_WAYLAND ? "wayland" : "X11", (uintptr_t)offer.get(),
(uintptr_t)dnd.currentSource.get());
(uintptr_t)m_dnd.currentSource.get());
dnd.focusedDevice->sendDataOffer(offer);
m_dnd.focusedDevice->sendDataOffer(offer);
if (const auto WL = offer->getWayland(); WL)
WL->sendData();
dnd.focusedDevice->sendEnter(wl_display_next_serial(g_pCompositor->m_wlDisplay), g_pSeatManager->m_state.dndPointerFocus.lock(),
g_pSeatManager->m_state.dndPointerFocus->current.size / 2.F, offer);
m_dnd.focusedDevice->sendEnter(wl_display_next_serial(g_pCompositor->m_wlDisplay), g_pSeatManager->m_state.dndPointerFocus.lock(),
g_pSeatManager->m_state.dndPointerFocus->m_current.size / 2.F, offer);
}
void CWLDataDeviceProtocol::cleanupDndState(bool resetDevice, bool resetSource, bool simulateInput) {
dnd.dndSurface.reset();
dnd.dndSurfaceCommit.reset();
dnd.dndSurfaceDestroy.reset();
dnd.mouseButton.reset();
dnd.mouseMove.reset();
dnd.touchUp.reset();
dnd.touchMove.reset();
m_dnd.dndSurface.reset();
m_dnd.dndSurfaceCommit.reset();
m_dnd.dndSurfaceDestroy.reset();
m_dnd.mouseButton.reset();
m_dnd.mouseMove.reset();
m_dnd.touchUp.reset();
m_dnd.touchMove.reset();
if (resetDevice)
dnd.focusedDevice.reset();
m_dnd.focusedDevice.reset();
if (resetSource)
dnd.currentSource.reset();
m_dnd.currentSource.reset();
if (simulateInput) {
g_pInputManager->simulateMouseMovement();
@ -708,8 +708,8 @@ void CWLDataDeviceProtocol::cleanupDndState(bool resetDevice, bool resetSource,
}
void CWLDataDeviceProtocol::dropDrag() {
if (!dnd.focusedDevice || !dnd.currentSource) {
if (dnd.currentSource)
if (!m_dnd.focusedDevice || !m_dnd.currentSource) {
if (m_dnd.currentSource)
abortDrag();
return;
}
@ -719,40 +719,40 @@ void CWLDataDeviceProtocol::dropDrag() {
return;
}
dnd.focusedDevice->sendDrop();
m_dnd.focusedDevice->sendDrop();
#ifndef NO_XWAYLAND
if (dnd.focusedDevice->getX11()) {
dnd.focusedDevice->sendLeave();
if (dnd.overriddenCursor)
if (m_dnd.focusedDevice->getX11()) {
m_dnd.focusedDevice->sendLeave();
if (m_dnd.overriddenCursor)
g_pInputManager->unsetCursorImage();
dnd.overriddenCursor = false;
m_dnd.overriddenCursor = false;
cleanupDndState(true, true, true);
return;
}
#endif
dnd.focusedDevice->sendLeave();
if (dnd.overriddenCursor)
m_dnd.focusedDevice->sendLeave();
if (m_dnd.overriddenCursor)
g_pInputManager->unsetCursorImage();
dnd.overriddenCursor = false;
m_dnd.overriddenCursor = false;
cleanupDndState(false, false, false);
}
bool CWLDataDeviceProtocol::wasDragSuccessful() {
if (!dnd.currentSource)
if (!m_dnd.currentSource)
return false;
for (auto const& o : m_vOffers) {
if (o->dead || o->source != dnd.currentSource)
for (auto const& o : m_offers) {
if (o->m_dead || o->m_source != m_dnd.currentSource)
continue;
if (o->recvd || o->accepted)
if (o->m_recvd || o->m_accepted)
return true;
}
#ifndef NO_XWAYLAND
if (dnd.focusedDevice->getX11())
if (m_dnd.focusedDevice->getX11())
return true;
#endif
@ -760,12 +760,12 @@ bool CWLDataDeviceProtocol::wasDragSuccessful() {
}
void CWLDataDeviceProtocol::completeDrag() {
if (!dnd.focusedDevice && !dnd.currentSource)
if (!m_dnd.focusedDevice && !m_dnd.currentSource)
return;
if (dnd.currentSource) {
dnd.currentSource->sendDndDropPerformed();
dnd.currentSource->sendDndFinished();
if (m_dnd.currentSource) {
m_dnd.currentSource->sendDndDropPerformed();
m_dnd.currentSource->sendDndFinished();
}
cleanupDndState(true, true, true);
@ -774,56 +774,56 @@ void CWLDataDeviceProtocol::completeDrag() {
void CWLDataDeviceProtocol::abortDrag() {
cleanupDndState(false, false, false);
if (dnd.overriddenCursor)
if (m_dnd.overriddenCursor)
g_pInputManager->unsetCursorImage();
dnd.overriddenCursor = false;
m_dnd.overriddenCursor = false;
if (!dnd.focusedDevice && !dnd.currentSource)
if (!m_dnd.focusedDevice && !m_dnd.currentSource)
return;
if (dnd.focusedDevice) {
if (m_dnd.focusedDevice) {
#ifndef NO_XWAYLAND
if (auto x11Device = dnd.focusedDevice->getX11(); x11Device)
if (auto x11Device = m_dnd.focusedDevice->getX11(); x11Device)
x11Device->forceCleanupDnd();
#endif
dnd.focusedDevice->sendLeave();
m_dnd.focusedDevice->sendLeave();
}
if (dnd.currentSource)
dnd.currentSource->cancelled();
if (m_dnd.currentSource)
m_dnd.currentSource->cancelled();
dnd.focusedDevice.reset();
dnd.currentSource.reset();
m_dnd.focusedDevice.reset();
m_dnd.currentSource.reset();
g_pInputManager->simulateMouseMovement();
g_pSeatManager->resendEnterEvents();
}
void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, const Time::steady_tp& when) {
if (!dnd.dndSurface || !dnd.dndSurface->current.texture)
if (!m_dnd.dndSurface || !m_dnd.dndSurface->m_current.texture)
return;
const auto POS = g_pInputManager->getMouseCoordsInternal();
Vector2D surfacePos = POS;
surfacePos += dnd.dndSurface->current.offset;
surfacePos += m_dnd.dndSurface->m_current.offset;
CBox box = CBox{surfacePos, dnd.dndSurface->current.size}.translate(-pMonitor->m_position).scale(pMonitor->m_scale);
CBox box = CBox{surfacePos, m_dnd.dndSurface->m_current.size}.translate(-pMonitor->m_position).scale(pMonitor->m_scale);
CTexPassElement::SRenderData data;
data.tex = dnd.dndSurface->current.texture;
data.tex = m_dnd.dndSurface->m_current.texture;
data.box = box;
g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data));
CBox damageBox = CBox{surfacePos, dnd.dndSurface->current.size}.expand(5);
CBox damageBox = CBox{surfacePos, m_dnd.dndSurface->m_current.size}.expand(5);
g_pHyprRenderer->damageBox(damageBox);
dnd.dndSurface->frame(when);
m_dnd.dndSurface->frame(when);
}
bool CWLDataDeviceProtocol::dndActive() {
return dnd.currentSource;
return m_dnd.currentSource;
}
void CWLDataDeviceProtocol::abortDndIfPresent() {

View file

@ -40,17 +40,15 @@ class CWLDataOfferResource : public IDataOffer {
virtual SP<CX11DataOffer> getX11();
virtual SP<IDataSource> getSource();
WP<IDataSource> source;
WP<CWLDataOfferResource> self;
WP<IDataSource> m_source;
WP<CWLDataOfferResource> m_self;
bool dead = false;
bool accepted = false;
bool recvd = false;
uint32_t actions = 0;
bool m_dead = false;
bool m_accepted = false;
bool m_recvd = false;
private:
SP<CWlDataOffer> resource;
SP<CWlDataOffer> m_resource;
friend class CWLDataDeviceResource;
};
@ -76,19 +74,19 @@ class CWLDataSourceResource : public IDataSource {
virtual void sendDndDropPerformed();
virtual void sendDndAction(wl_data_device_manager_dnd_action a);
bool used = false;
bool dnd = false;
bool dndSuccess = false;
bool dropped = false;
bool m_used = false;
bool m_dnd = false;
bool m_dndSuccess = false;
bool m_dropped = false;
WP<CWLDataDeviceResource> device;
WP<CWLDataSourceResource> self;
WP<CWLDataDeviceResource> m_device;
WP<CWLDataSourceResource> m_self;
std::vector<std::string> mimeTypes;
uint32_t supportedActions = 0;
std::vector<std::string> m_mimeTypes;
uint32_t m_supportedActions = 0;
private:
SP<CWlDataSource> resource;
SP<CWlDataSource> m_resource;
friend class CWLDataDeviceProtocol;
};
@ -110,11 +108,11 @@ class CWLDataDeviceResource : public IDataDevice {
virtual void sendSelection(SP<IDataOffer> offer);
virtual eDataSourceType type();
WP<CWLDataDeviceResource> self;
WP<CWLDataDeviceResource> m_self;
private:
SP<CWlDataDevice> resource;
wl_client* pClient = nullptr;
SP<CWlDataDevice> m_resource;
wl_client* m_client = nullptr;
friend class CWLDataDeviceProtocol;
};
@ -125,11 +123,11 @@ class CWLDataDeviceManagerResource {
bool good();
WP<CWLDataDeviceResource> device;
std::vector<WP<CWLDataSourceResource>> sources;
WP<CWLDataDeviceResource> m_device;
std::vector<WP<CWLDataSourceResource>> m_sources;
private:
SP<CWlDataDeviceManager> resource;
SP<CWlDataDeviceManager> m_resource;
};
class CWLDataDeviceProtocol : public IWaylandProtocol {
@ -154,10 +152,10 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
void destroyResource(CWLDataOfferResource* resource);
//
std::vector<SP<CWLDataDeviceManagerResource>> m_vManagers;
std::vector<SP<CWLDataDeviceResource>> m_vDevices;
std::vector<SP<CWLDataSourceResource>> m_vSources;
std::vector<SP<CWLDataOfferResource>> m_vOffers;
std::vector<SP<CWLDataDeviceManagerResource>> m_managers;
std::vector<SP<CWLDataDeviceResource>> m_devices;
std::vector<SP<CWLDataSourceResource>> m_sources;
std::vector<SP<CWLDataOfferResource>> m_offers;
//
@ -182,7 +180,7 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
SP<HOOK_CALLBACK_FN> mouseButton;
SP<HOOK_CALLBACK_FN> touchUp;
SP<HOOK_CALLBACK_FN> touchMove;
} dnd;
} m_dnd;
void abortDrag();
void initiateDrag(WP<CWLDataSourceResource> currentSource, SP<CWLSurfaceResource> dragSurface, SP<CWLSurfaceResource> origin);
@ -204,7 +202,7 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
struct {
CHyprSignalListener onKeyboardFocusChange;
CHyprSignalListener onDndPointerFocusChange;
} listeners;
} m_listeners;
};
namespace PROTO {

View file

@ -3,29 +3,29 @@
#include "../../Compositor.hpp"
#include "../../helpers/Monitor.hpp"
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : monitor(pMonitor), resource(resource_) {
CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonitor) : m_monitor(pMonitor), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
pClient = resource->client();
m_client = m_resource->client();
if (!monitor)
if (!m_monitor)
return;
resource->setOnDestroy([this](CWlOutput* r) {
if (monitor && PROTO::outputs.contains(monitor->m_name))
PROTO::outputs.at(monitor->m_name)->destroyResource(this);
m_resource->setOnDestroy([this](CWlOutput* r) {
if (m_monitor && PROTO::outputs.contains(m_monitor->m_name))
PROTO::outputs.at(m_monitor->m_name)->destroyResource(this);
});
resource->setRelease([this](CWlOutput* r) {
if (monitor && PROTO::outputs.contains(monitor->m_name))
PROTO::outputs.at(monitor->m_name)->destroyResource(this);
m_resource->setRelease([this](CWlOutput* r) {
if (m_monitor && PROTO::outputs.contains(m_monitor->m_name))
PROTO::outputs.at(m_monitor->m_name)->destroyResource(this);
});
if (resource->version() >= 4) {
resource->sendName(monitor->m_name.c_str());
resource->sendDescription(monitor->m_description.c_str());
if (m_resource->version() >= 4) {
m_resource->sendName(m_monitor->m_name.c_str());
m_resource->sendDescription(m_monitor->m_description.c_str());
}
updateState();
@ -52,72 +52,72 @@ CWLOutputResource::CWLOutputResource(SP<CWlOutput> resource_, PHLMONITOR pMonito
SP<CWLOutputResource> CWLOutputResource::fromResource(wl_resource* res) {
auto data = (CWLOutputResource*)(((CWlOutput*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
bool CWLOutputResource::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CWLOutputResource::client() {
return pClient;
return m_client;
}
SP<CWlOutput> CWLOutputResource::getResource() {
return resource;
return m_resource;
}
void CWLOutputResource::updateState() {
if (!monitor || (owner && owner->defunct))
if (!m_monitor || (m_owner && m_owner->m_defunct))
return;
if (resource->version() >= 2)
resource->sendScale(std::ceil(monitor->m_scale));
if (m_resource->version() >= 2)
m_resource->sendScale(std::ceil(m_monitor->m_scale));
resource->sendMode((wl_output_mode)(WL_OUTPUT_MODE_CURRENT), monitor->m_pixelSize.x, monitor->m_pixelSize.y, monitor->m_refreshRate * 1000.0);
m_resource->sendMode((wl_output_mode)(WL_OUTPUT_MODE_CURRENT), m_monitor->m_pixelSize.x, m_monitor->m_pixelSize.y, m_monitor->m_refreshRate * 1000.0);
resource->sendGeometry(0, 0, monitor->m_output->physicalSize.x, monitor->m_output->physicalSize.y, (wl_output_subpixel)monitor->m_output->subpixel,
monitor->m_output->make.c_str(), monitor->m_output->model.c_str(), monitor->m_transform);
m_resource->sendGeometry(0, 0, m_monitor->m_output->physicalSize.x, m_monitor->m_output->physicalSize.y, (wl_output_subpixel)m_monitor->m_output->subpixel,
m_monitor->m_output->make.c_str(), m_monitor->m_output->model.c_str(), m_monitor->m_transform);
if (resource->version() >= 2)
resource->sendDone();
if (m_resource->version() >= 2)
m_resource->sendDone();
}
CWLOutputProtocol::CWLOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name, PHLMONITOR pMonitor) :
IWaylandProtocol(iface, ver, name), monitor(pMonitor), szName(pMonitor->m_name) {
IWaylandProtocol(iface, ver, name), m_monitor(pMonitor), m_name(pMonitor->m_name) {
listeners.modeChanged = monitor->m_events.modeChanged.registerListener([this](std::any d) {
for (auto const& o : m_vOutputs) {
m_listeners.modeChanged = m_monitor->m_events.modeChanged.registerListener([this](std::any d) {
for (auto const& o : m_outputs) {
o->updateState();
}
});
}
void CWLOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
if UNLIKELY (defunct)
if UNLIKELY (m_defunct)
Debug::log(WARN, "[wl_output] Binding a wl_output that's inert?? Possible client bug.");
const auto RESOURCE = m_vOutputs.emplace_back(makeShared<CWLOutputResource>(makeShared<CWlOutput>(client, ver, id), monitor.lock()));
const auto RESOURCE = m_outputs.emplace_back(makeShared<CWLOutputResource>(makeShared<CWlOutput>(client, ver, id), m_monitor.lock()));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vOutputs.pop_back();
m_outputs.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->owner = self;
RESOURCE->m_self = RESOURCE;
RESOURCE->m_owner = m_self;
}
void CWLOutputProtocol::destroyResource(CWLOutputResource* resource) {
std::erase_if(m_vOutputs, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_outputs, [&](const auto& other) { return other.get() == resource; });
if (m_vOutputs.empty() && defunct)
PROTO::outputs.erase(szName);
if (m_outputs.empty() && m_defunct)
PROTO::outputs.erase(m_name);
}
SP<CWLOutputResource> CWLOutputProtocol::outputResourceFrom(wl_client* client) {
for (auto const& r : m_vOutputs) {
for (auto const& r : m_outputs) {
if (r->client() != client)
continue;
@ -128,22 +128,22 @@ SP<CWLOutputResource> CWLOutputProtocol::outputResourceFrom(wl_client* client) {
}
void CWLOutputProtocol::remove() {
if UNLIKELY (defunct)
if UNLIKELY (m_defunct)
return;
defunct = true;
m_defunct = true;
removeGlobal();
}
bool CWLOutputProtocol::isDefunct() {
return defunct;
return m_defunct;
}
void CWLOutputProtocol::sendDone() {
if UNLIKELY (defunct)
if UNLIKELY (m_defunct)
return;
for (auto const& r : m_vOutputs) {
r->resource->sendDone();
for (auto const& r : m_outputs) {
r->m_resource->sendDone();
}
}

View file

@ -19,13 +19,13 @@ class CWLOutputResource {
SP<CWlOutput> getResource();
void updateState();
PHLMONITORREF monitor;
WP<CWLOutputProtocol> owner;
WP<CWLOutputResource> self;
PHLMONITORREF m_monitor;
WP<CWLOutputProtocol> m_owner;
WP<CWLOutputResource> m_self;
private:
SP<CWlOutput> resource;
wl_client* pClient = nullptr;
SP<CWlOutput> m_resource;
wl_client* m_client = nullptr;
friend class CWLOutputProtocol;
};
@ -39,8 +39,8 @@ class CWLOutputProtocol : public IWaylandProtocol {
SP<CWLOutputResource> outputResourceFrom(wl_client* client);
void sendDone();
PHLMONITORREF monitor;
WP<CWLOutputProtocol> self;
PHLMONITORREF m_monitor;
WP<CWLOutputProtocol> m_self;
// will mark the protocol for removal, will be removed when no. of bound outputs is 0 (or when overwritten by a new global)
void remove();
@ -50,13 +50,13 @@ class CWLOutputProtocol : public IWaylandProtocol {
void destroyResource(CWLOutputResource* resource);
//
std::vector<SP<CWLOutputResource>> m_vOutputs;
bool defunct = false;
std::string szName = "";
std::vector<SP<CWLOutputResource>> m_outputs;
bool m_defunct = false;
std::string m_name = "";
struct {
CHyprSignalListener modeChanged;
} listeners;
} m_listeners;
friend class CWLOutputResource;
};

View file

@ -10,292 +10,292 @@
#include <fcntl.h>
CWLTouchResource::CWLTouchResource(SP<CWlTouch> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
CWLTouchResource::CWLTouchResource(SP<CWlTouch> resource_, SP<CWLSeatResource> owner_) : m_owner(owner_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
resource->setOnDestroy([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
m_resource->setRelease([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
m_resource->setOnDestroy([this](CWlTouch* r) { PROTO::seat->destroyResource(this); });
}
bool CWLTouchResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLTouchResource::sendDown(SP<CWLSurfaceResource> surface, uint32_t timeMs, int32_t id, const Vector2D& local) {
if (!owner || !surface || !surface->getResource()->resource())
if (!m_owner || !surface || !surface->getResource()->resource())
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
ASSERT(surface->client() == owner->client());
ASSERT(surface->client() == m_owner->client());
currentSurface = surface;
listeners.destroySurface = surface->events.destroy.registerListener([this, timeMs, id](std::any d) { sendUp(timeMs + 10 /* hack */, id); });
m_currentSurface = surface;
m_listeners.destroySurface = surface->m_events.destroy.registerListener([this, timeMs, id](std::any d) { sendUp(timeMs + 10 /* hack */, id); });
resource->sendDown(g_pSeatManager->nextSerial(owner.lock()), timeMs, surface->getResource().get(), id, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
m_resource->sendDown(g_pSeatManager->nextSerial(m_owner.lock()), timeMs, surface->getResource().get(), id, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
fingers++;
m_fingers++;
}
void CWLTouchResource::sendUp(uint32_t timeMs, int32_t id) {
if (!owner)
if (!m_owner)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendUp(g_pSeatManager->nextSerial(owner.lock()), timeMs, id);
fingers--;
if (fingers <= 0) {
currentSurface.reset();
listeners.destroySurface.reset();
fingers = 0;
m_resource->sendUp(g_pSeatManager->nextSerial(m_owner.lock()), timeMs, id);
m_fingers--;
if (m_fingers <= 0) {
m_currentSurface.reset();
m_listeners.destroySurface.reset();
m_fingers = 0;
}
}
void CWLTouchResource::sendMotion(uint32_t timeMs, int32_t id, const Vector2D& local) {
if (!owner)
if (!m_owner)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendMotion(timeMs, id, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
m_resource->sendMotion(timeMs, id, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
}
void CWLTouchResource::sendFrame() {
if (!owner)
if (!m_owner)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendFrame();
m_resource->sendFrame();
}
void CWLTouchResource::sendCancel() {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendCancel();
m_resource->sendCancel();
}
void CWLTouchResource::sendShape(int32_t id, const Vector2D& shape) {
if (!owner || !currentSurface || resource->version() < 6)
if (!m_owner || !m_currentSurface || m_resource->version() < 6)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendShape(id, wl_fixed_from_double(shape.x), wl_fixed_from_double(shape.y));
m_resource->sendShape(id, wl_fixed_from_double(shape.x), wl_fixed_from_double(shape.y));
}
void CWLTouchResource::sendOrientation(int32_t id, double angle) {
if (!owner || !currentSurface || resource->version() < 6)
if (!m_owner || !m_currentSurface || m_resource->version() < 6)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH))
return;
resource->sendOrientation(id, wl_fixed_from_double(angle));
m_resource->sendOrientation(id, wl_fixed_from_double(angle));
}
CWLPointerResource::CWLPointerResource(SP<CWlPointer> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
CWLPointerResource::CWLPointerResource(SP<CWlPointer> resource_, SP<CWLSeatResource> owner_) : m_owner(owner_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
resource->setOnDestroy([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
m_resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
m_resource->setOnDestroy([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
resource->setSetCursor([this](CWlPointer* r, uint32_t serial, wl_resource* surf, int32_t hotX, int32_t hotY) {
if (!owner) {
m_resource->setSetCursor([this](CWlPointer* r, uint32_t serial, wl_resource* surf, int32_t hotX, int32_t hotY) {
if (!m_owner) {
LOGM(ERR, "Client bug: setCursor when seatClient is already dead");
return;
}
auto surfResource = surf ? CWLSurfaceResource::fromResource(surf) : nullptr;
if (surfResource && surfResource->role->role() != SURFACE_ROLE_CURSOR && surfResource->role->role() != SURFACE_ROLE_UNASSIGNED) {
if (surfResource && surfResource->m_role->role() != SURFACE_ROLE_CURSOR && surfResource->m_role->role() != SURFACE_ROLE_UNASSIGNED) {
r->error(-1, "Cursor surface already has a different role");
return;
}
if (surfResource && surfResource->role->role() != SURFACE_ROLE_CURSOR) {
surfResource->role = makeShared<CCursorSurfaceRole>();
if (surfResource && surfResource->m_role->role() != SURFACE_ROLE_CURSOR) {
surfResource->m_role = makeShared<CCursorSurfaceRole>();
surfResource->updateCursorShm();
}
g_pSeatManager->onSetCursor(owner.lock(), serial, surfResource, {hotX, hotY});
g_pSeatManager->onSetCursor(m_owner.lock(), serial, surfResource, {hotX, hotY});
});
if (g_pSeatManager->m_state.pointerFocus && g_pSeatManager->m_state.pointerFocus->client() == resource->client())
if (g_pSeatManager->m_state.pointerFocus && g_pSeatManager->m_state.pointerFocus->client() == m_resource->client())
sendEnter(g_pSeatManager->m_state.pointerFocus.lock(), {-1, -1} /* Coords don't really matter that much, they will be updated next move */);
}
int CWLPointerResource::version() {
return resource->version();
return m_resource->version();
}
bool CWLPointerResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLPointerResource::sendEnter(SP<CWLSurfaceResource> surface, const Vector2D& local) {
if (!owner || currentSurface == surface || !surface->getResource()->resource())
if (!m_owner || m_currentSurface == surface || !surface->getResource()->resource())
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
if (currentSurface) {
if (m_currentSurface) {
LOGM(WARN, "requested CWLPointerResource::sendEnter without sendLeave first.");
sendLeave();
}
ASSERT(surface->client() == owner->client());
ASSERT(surface->client() == m_owner->client());
currentSurface = surface;
listeners.destroySurface = surface->events.destroy.registerListener([this](std::any d) { sendLeave(); });
m_currentSurface = surface;
m_listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) { sendLeave(); });
resource->sendEnter(g_pSeatManager->nextSerial(owner.lock()), surface->getResource().get(), wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
m_resource->sendEnter(g_pSeatManager->nextSerial(m_owner.lock()), surface->getResource().get(), wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
}
void CWLPointerResource::sendLeave() {
if (!owner || !currentSurface || !currentSurface->getResource()->resource())
if (!m_owner || !m_currentSurface || !m_currentSurface->getResource()->resource())
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
// release all buttons unless we have a dnd going on in which case
// the events shall be lost.
if (!PROTO::data->dndActive()) {
for (auto const& b : pressedButtons) {
for (auto const& b : m_pressedButtons) {
sendButton(Time::millis(Time::steadyNow()), b, WL_POINTER_BUTTON_STATE_RELEASED);
}
}
pressedButtons.clear();
m_pressedButtons.clear();
resource->sendLeave(g_pSeatManager->nextSerial(owner.lock()), currentSurface->getResource().get());
currentSurface.reset();
listeners.destroySurface.reset();
m_resource->sendLeave(g_pSeatManager->nextSerial(m_owner.lock()), m_currentSurface->getResource().get());
m_currentSurface.reset();
m_listeners.destroySurface.reset();
}
void CWLPointerResource::sendMotion(uint32_t timeMs, const Vector2D& local) {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendMotion(timeMs, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
m_resource->sendMotion(timeMs, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
}
void CWLPointerResource::sendButton(uint32_t timeMs, uint32_t button, wl_pointer_button_state state) {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::find(pressedButtons.begin(), pressedButtons.end(), button) == pressedButtons.end()) {
if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) == m_pressedButtons.end()) {
LOGM(ERR, "sendButton release on a non-pressed button");
return;
} else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::find(pressedButtons.begin(), pressedButtons.end(), button) != pressedButtons.end()) {
} else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) != m_pressedButtons.end()) {
LOGM(ERR, "sendButton press on a non-pressed button");
return;
}
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
std::erase(pressedButtons, button);
std::erase(m_pressedButtons, button);
else if (state == WL_POINTER_BUTTON_STATE_PRESSED)
pressedButtons.emplace_back(button);
m_pressedButtons.emplace_back(button);
resource->sendButton(g_pSeatManager->nextSerial(owner.lock()), timeMs, button, state);
m_resource->sendButton(g_pSeatManager->nextSerial(m_owner.lock()), timeMs, button, state);
}
void CWLPointerResource::sendAxis(uint32_t timeMs, wl_pointer_axis axis, double value) {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxis(timeMs, axis, wl_fixed_from_double(value));
m_resource->sendAxis(timeMs, axis, wl_fixed_from_double(value));
}
void CWLPointerResource::sendFrame() {
if (!owner || resource->version() < 5)
if (!m_owner || m_resource->version() < 5)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendFrame();
m_resource->sendFrame();
}
void CWLPointerResource::sendAxisSource(wl_pointer_axis_source source) {
if (!owner || !currentSurface || resource->version() < 5)
if (!m_owner || !m_currentSurface || m_resource->version() < 5)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxisSource(source);
m_resource->sendAxisSource(source);
}
void CWLPointerResource::sendAxisStop(uint32_t timeMs, wl_pointer_axis axis) {
if (!owner || !currentSurface || resource->version() < 5)
if (!m_owner || !m_currentSurface || m_resource->version() < 5)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxisStop(timeMs, axis);
m_resource->sendAxisStop(timeMs, axis);
}
void CWLPointerResource::sendAxisDiscrete(wl_pointer_axis axis, int32_t discrete) {
if (!owner || !currentSurface || resource->version() < 5)
if (!m_owner || !m_currentSurface || m_resource->version() < 5)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxisDiscrete(axis, discrete);
m_resource->sendAxisDiscrete(axis, discrete);
}
void CWLPointerResource::sendAxisValue120(wl_pointer_axis axis, int32_t value120) {
if (!owner || !currentSurface || resource->version() < 8)
if (!m_owner || !m_currentSurface || m_resource->version() < 8)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxisValue120(axis, value120);
m_resource->sendAxisValue120(axis, value120);
}
void CWLPointerResource::sendAxisRelativeDirection(wl_pointer_axis axis, wl_pointer_axis_relative_direction direction) {
if (!owner || !currentSurface || resource->version() < 9)
if (!m_owner || !m_currentSurface || m_resource->version() < 9)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER))
return;
resource->sendAxisRelativeDirection(axis, direction);
m_resource->sendAxisRelativeDirection(axis, direction);
}
CWLKeyboardResource::CWLKeyboardResource(SP<CWlKeyboard> resource_, SP<CWLSeatResource> owner_) : owner(owner_), resource(resource_) {
CWLKeyboardResource::CWLKeyboardResource(SP<CWlKeyboard> resource_, SP<CWLSeatResource> owner_) : m_owner(owner_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setRelease([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
resource->setOnDestroy([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
m_resource->setRelease([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
m_resource->setOnDestroy([this](CWlKeyboard* r) { PROTO::seat->destroyResource(this); });
if (!g_pSeatManager->m_keyboard) {
LOGM(ERR, "No keyboard on bound wl_keyboard??");
@ -305,160 +305,160 @@ CWLKeyboardResource::CWLKeyboardResource(SP<CWlKeyboard> resource_, SP<CWLSeatRe
sendKeymap(g_pSeatManager->m_keyboard.lock());
repeatInfo(g_pSeatManager->m_keyboard->m_repeatRate, g_pSeatManager->m_keyboard->m_repeatDelay);
if (g_pSeatManager->m_state.keyboardFocus && g_pSeatManager->m_state.keyboardFocus->client() == resource->client())
if (g_pSeatManager->m_state.keyboardFocus && g_pSeatManager->m_state.keyboardFocus->client() == m_resource->client())
sendEnter(g_pSeatManager->m_state.keyboardFocus.lock());
}
bool CWLKeyboardResource::good() {
return resource->resource();
return m_resource->resource();
}
void CWLKeyboardResource::sendKeymap(SP<IKeyboard> keyboard) {
if (!keyboard)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
std::string_view keymap = keyboard->m_xkbKeymapString;
Hyprutils::OS::CFileDescriptor& fd = keyboard->m_xkbKeymapFD;
uint32_t size = keyboard->m_xkbKeymapString.length() + 1;
if (keymap == lastKeymap)
if (keymap == m_lastKeymap)
return;
lastKeymap = keymap;
m_lastKeymap = keymap;
const wl_keyboard_keymap_format format = keyboard ? WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 : WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP;
resource->sendKeymap(format, fd.get(), size);
m_resource->sendKeymap(format, fd.get(), size);
}
void CWLKeyboardResource::sendEnter(SP<CWLSurfaceResource> surface) {
if (!owner || currentSurface == surface || !surface->getResource()->resource())
if (!m_owner || m_currentSurface == surface || !surface->getResource()->resource())
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
if (currentSurface) {
if (m_currentSurface) {
LOGM(WARN, "requested CWLKeyboardResource::sendEnter without sendLeave first.");
sendLeave();
}
ASSERT(surface->client() == owner->client());
ASSERT(surface->client() == m_owner->client());
currentSurface = surface;
listeners.destroySurface = surface->events.destroy.registerListener([this](std::any d) { sendLeave(); });
m_currentSurface = surface;
m_listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) { sendLeave(); });
wl_array arr;
wl_array_init(&arr);
resource->sendEnter(g_pSeatManager->nextSerial(owner.lock()), surface->getResource().get(), &arr);
m_resource->sendEnter(g_pSeatManager->nextSerial(m_owner.lock()), surface->getResource().get(), &arr);
wl_array_release(&arr);
}
void CWLKeyboardResource::sendLeave() {
if (!owner || !currentSurface || !currentSurface->getResource()->resource())
if (!m_owner || !m_currentSurface || !m_currentSurface->getResource()->resource())
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
resource->sendLeave(g_pSeatManager->nextSerial(owner.lock()), currentSurface->getResource().get());
currentSurface.reset();
listeners.destroySurface.reset();
m_resource->sendLeave(g_pSeatManager->nextSerial(m_owner.lock()), m_currentSurface->getResource().get());
m_currentSurface.reset();
m_listeners.destroySurface.reset();
}
void CWLKeyboardResource::sendKey(uint32_t timeMs, uint32_t key, wl_keyboard_key_state state) {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
resource->sendKey(g_pSeatManager->nextSerial(owner.lock()), timeMs, key, state);
m_resource->sendKey(g_pSeatManager->nextSerial(m_owner.lock()), timeMs, key, state);
}
void CWLKeyboardResource::sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) {
if (!owner || !currentSurface)
if (!m_owner || !m_currentSurface)
return;
if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
resource->sendModifiers(g_pSeatManager->nextSerial(owner.lock()), depressed, latched, locked, group);
m_resource->sendModifiers(g_pSeatManager->nextSerial(m_owner.lock()), depressed, latched, locked, group);
}
void CWLKeyboardResource::repeatInfo(uint32_t rate, uint32_t delayMs) {
if (!owner || resource->version() < 4 || (rate == lastRate && delayMs == lastDelayMs))
if (!m_owner || m_resource->version() < 4 || (rate == m_lastRate && delayMs == m_lastDelayMs))
return;
lastRate = rate;
lastDelayMs = delayMs;
m_lastRate = rate;
m_lastDelayMs = delayMs;
resource->sendRepeatInfo(rate, delayMs);
m_resource->sendRepeatInfo(rate, delayMs);
}
CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : resource(resource_) {
CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSeat* r) {
events.destroy.emit();
m_resource->setOnDestroy([this](CWlSeat* r) {
m_events.destroy.emit();
PROTO::seat->destroyResource(this);
});
resource->setRelease([this](CWlSeat* r) {
events.destroy.emit();
m_resource->setRelease([this](CWlSeat* r) {
m_events.destroy.emit();
PROTO::seat->destroyResource(this);
});
pClient = resource->client();
m_client = m_resource->client();
resource->setGetKeyboard([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vKeyboards.emplace_back(makeShared<CWLKeyboardResource>(makeShared<CWlKeyboard>(r->client(), r->version(), id), self.lock()));
m_resource->setGetKeyboard([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_keyboards.emplace_back(makeShared<CWLKeyboardResource>(makeShared<CWlKeyboard>(r->client(), r->version(), id), m_self.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vKeyboards.pop_back();
PROTO::seat->m_keyboards.pop_back();
return;
}
keyboards.emplace_back(RESOURCE);
m_keyboards.emplace_back(RESOURCE);
});
resource->setGetPointer([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vPointers.emplace_back(makeShared<CWLPointerResource>(makeShared<CWlPointer>(r->client(), r->version(), id), self.lock()));
m_resource->setGetPointer([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_pointers.emplace_back(makeShared<CWLPointerResource>(makeShared<CWlPointer>(r->client(), r->version(), id), m_self.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vPointers.pop_back();
PROTO::seat->m_pointers.pop_back();
return;
}
pointers.emplace_back(RESOURCE);
m_pointers.emplace_back(RESOURCE);
});
resource->setGetTouch([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_vTouches.emplace_back(makeShared<CWLTouchResource>(makeShared<CWlTouch>(r->client(), r->version(), id), self.lock()));
m_resource->setGetTouch([this](CWlSeat* r, uint32_t id) {
const auto RESOURCE = PROTO::seat->m_touches.emplace_back(makeShared<CWLTouchResource>(makeShared<CWlTouch>(r->client(), r->version(), id), m_self.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::seat->m_vTouches.pop_back();
PROTO::seat->m_touches.pop_back();
return;
}
touches.emplace_back(RESOURCE);
m_touches.emplace_back(RESOURCE);
});
if (resource->version() >= 2)
resource->sendName(HL_SEAT_NAME);
if (m_resource->version() >= 2)
m_resource->sendName(HL_SEAT_NAME);
sendCapabilities(PROTO::seat->currentCaps);
sendCapabilities(PROTO::seat->m_currentCaps);
}
CWLSeatResource::~CWLSeatResource() {
events.destroy.emit();
m_events.destroy.emit();
}
void CWLSeatResource::sendCapabilities(uint32_t caps) {
@ -470,15 +470,15 @@ void CWLSeatResource::sendCapabilities(uint32_t caps) {
if (caps & eHIDCapabilityType::HID_INPUT_CAPABILITY_TOUCH)
wlCaps |= WL_SEAT_CAPABILITY_TOUCH;
resource->sendCapabilities((wl_seat_capability)wlCaps);
m_resource->sendCapabilities((wl_seat_capability)wlCaps);
}
bool CWLSeatResource::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CWLSeatResource::client() {
return pClient;
return m_client;
}
CWLSeatProtocol::CWLSeatProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -486,68 +486,68 @@ CWLSeatProtocol::CWLSeatProtocol(const wl_interface* iface, const int& ver, cons
}
void CWLSeatProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vSeatResources.emplace_back(makeShared<CWLSeatResource>(makeShared<CWlSeat>(client, ver, id)));
const auto RESOURCE = m_seatResources.emplace_back(makeShared<CWLSeatResource>(makeShared<CWlSeat>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vSeatResources.pop_back();
m_seatResources.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
LOGM(LOG, "New seat resource bound at {:x}", (uintptr_t)RESOURCE.get());
events.newSeatResource.emit(RESOURCE);
m_events.newSeatResource.emit(RESOURCE);
}
void CWLSeatProtocol::destroyResource(CWLSeatResource* seat) {
std::erase_if(m_vSeatResources, [&](const auto& other) { return other.get() == seat; });
std::erase_if(m_seatResources, [&](const auto& other) { return other.get() == seat; });
}
void CWLSeatProtocol::destroyResource(CWLKeyboardResource* resource) {
std::erase_if(m_vKeyboards, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_keyboards, [&](const auto& other) { return other.get() == resource; });
}
void CWLSeatProtocol::destroyResource(CWLPointerResource* resource) {
std::erase_if(m_vPointers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_pointers, [&](const auto& other) { return other.get() == resource; });
}
void CWLSeatProtocol::destroyResource(CWLTouchResource* resource) {
std::erase_if(m_vTouches, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_touches, [&](const auto& other) { return other.get() == resource; });
}
void CWLSeatProtocol::updateCapabilities(uint32_t caps) {
if (caps == currentCaps)
if (caps == m_currentCaps)
return;
currentCaps = caps;
m_currentCaps = caps;
for (auto const& s : m_vSeatResources) {
for (auto const& s : m_seatResources) {
s->sendCapabilities(caps);
}
}
void CWLSeatProtocol::updateKeymap() {
if (!(currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
for (auto const& k : m_vKeyboards) {
for (auto const& k : m_keyboards) {
k->sendKeymap(g_pSeatManager->m_keyboard.lock());
}
}
void CWLSeatProtocol::updateRepeatInfo(uint32_t rate, uint32_t delayMs) {
if (!(currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
if (!(m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD))
return;
for (auto const& k : m_vKeyboards) {
for (auto const& k : m_keyboards) {
k->repeatInfo(rate, delayMs);
}
}
SP<CWLSeatResource> CWLSeatProtocol::seatResourceForClient(wl_client* client) {
for (auto const& r : m_vSeatResources) {
for (auto const& r : m_seatResources) {
if (r->client() == client)
return r;
}
@ -556,8 +556,8 @@ SP<CWLSeatResource> CWLSeatProtocol::seatResourceForClient(wl_client* client) {
}
std::vector<uint8_t>& CCursorSurfaceRole::cursorPixelData(SP<CWLSurfaceResource> surface) {
RASSERT(surface->role->role() == SURFACE_ROLE_CURSOR, "cursorPixelData called on a non-cursor surface");
RASSERT(surface->m_role->role() == SURFACE_ROLE_CURSOR, "cursorPixelData called on a non-cursor surface");
auto role = (CCursorSurfaceRole*)surface->role.get();
return role->cursorShmPixelData;
auto role = (CCursorSurfaceRole*)surface->m_role.get();
return role->m_cursorShmPixelData;
}

View file

@ -38,7 +38,7 @@ class CCursorSurfaceRole : public ISurfaceRole {
static std::vector<uint8_t>& cursorPixelData(SP<CWLSurfaceResource> surface);
private:
std::vector<uint8_t> cursorShmPixelData;
std::vector<uint8_t> m_cursorShmPixelData;
};
class CWLTouchResource {
@ -54,17 +54,17 @@ class CWLTouchResource {
void sendShape(int32_t id, const Vector2D& shape);
void sendOrientation(int32_t id, double angle);
WP<CWLSeatResource> owner;
WP<CWLSeatResource> m_owner;
private:
SP<CWlTouch> resource;
WP<CWLSurfaceResource> currentSurface;
SP<CWlTouch> m_resource;
WP<CWLSurfaceResource> m_currentSurface;
int fingers = 0;
int m_fingers = 0;
struct {
CHyprSignalListener destroySurface;
} listeners;
} m_listeners;
};
class CWLPointerResource {
@ -85,17 +85,17 @@ class CWLPointerResource {
void sendAxisValue120(wl_pointer_axis axis, int32_t value120);
void sendAxisRelativeDirection(wl_pointer_axis axis, wl_pointer_axis_relative_direction direction);
WP<CWLSeatResource> owner;
WP<CWLSeatResource> m_owner;
private:
SP<CWlPointer> resource;
WP<CWLSurfaceResource> currentSurface;
SP<CWlPointer> m_resource;
WP<CWLSurfaceResource> m_currentSurface;
std::vector<uint32_t> pressedButtons;
std::vector<uint32_t> m_pressedButtons;
struct {
CHyprSignalListener destroySurface;
} listeners;
} m_listeners;
};
class CWLKeyboardResource {
@ -110,19 +110,19 @@ class CWLKeyboardResource {
void sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group);
void repeatInfo(uint32_t rate, uint32_t delayMs);
WP<CWLSeatResource> owner;
WP<CWLSeatResource> m_owner;
private:
SP<CWlKeyboard> resource;
WP<CWLSurfaceResource> currentSurface;
SP<CWlKeyboard> m_resource;
WP<CWLSurfaceResource> m_currentSurface;
struct {
CHyprSignalListener destroySurface;
} listeners;
} m_listeners;
std::string lastKeymap = "<none>";
uint32_t lastRate = 0;
uint32_t lastDelayMs = 0;
std::string m_lastKeymap = "<none>";
uint32_t m_lastRate = 0;
uint32_t m_lastDelayMs = 0;
};
class CWLSeatResource {
@ -135,19 +135,19 @@ class CWLSeatResource {
bool good();
wl_client* client();
std::vector<WP<CWLPointerResource>> pointers;
std::vector<WP<CWLKeyboardResource>> keyboards;
std::vector<WP<CWLTouchResource>> touches;
std::vector<WP<CWLPointerResource>> m_pointers;
std::vector<WP<CWLKeyboardResource>> m_keyboards;
std::vector<WP<CWLTouchResource>> m_touches;
WP<CWLSeatResource> self;
WP<CWLSeatResource> m_self;
struct {
CSignal destroy;
} events;
} m_events;
private:
SP<CWlSeat> resource;
wl_client* pClient = nullptr;
SP<CWlSeat> m_resource;
wl_client* m_client = nullptr;
};
class CWLSeatProtocol : public IWaylandProtocol {
@ -158,7 +158,7 @@ class CWLSeatProtocol : public IWaylandProtocol {
struct {
CSignal newSeatResource; // SP<CWLSeatResource>
} events;
} m_events;
private:
void updateCapabilities(uint32_t caps); // in IHID caps
@ -171,15 +171,15 @@ class CWLSeatProtocol : public IWaylandProtocol {
void destroyResource(CWLPointerResource* resource);
//
std::vector<SP<CWLSeatResource>> m_vSeatResources;
std::vector<SP<CWLKeyboardResource>> m_vKeyboards;
std::vector<SP<CWLTouchResource>> m_vTouches;
std::vector<SP<CWLPointerResource>> m_vPointers;
std::vector<SP<CWLSeatResource>> m_seatResources;
std::vector<SP<CWLKeyboardResource>> m_keyboards;
std::vector<SP<CWLTouchResource>> m_touches;
std::vector<SP<CWLPointerResource>> m_pointers;
SP<CWLSeatResource> seatResourceForClient(wl_client* client);
//
uint32_t currentCaps = 0;
uint32_t m_currentCaps = 0;
friend class CWLSeatResource;
friend class CWLKeyboardResource;

View file

@ -10,22 +10,22 @@
using namespace Hyprutils::OS;
CWLSHMBuffer::CWLSHMBuffer(SP<CWLSHMPoolResource> pool_, uint32_t id, int32_t offset_, const Vector2D& size_, int32_t stride_, uint32_t fmt_) {
if UNLIKELY (!pool_->pool->data)
if UNLIKELY (!pool_->m_pool->m_data)
return;
g_pHyprRenderer->makeEGLCurrent();
size = size_;
pool = pool_->pool;
stride = stride_;
fmt = fmt_;
offset = offset_;
opaque = NFormatUtils::isFormatOpaque(NFormatUtils::shmToDRM(fmt_));
size = size_;
m_pool = pool_->m_pool;
m_stride = stride_;
m_fmt = fmt_;
m_offset = offset_;
opaque = NFormatUtils::isFormatOpaque(NFormatUtils::shmToDRM(fmt_));
resource = CWLBufferResource::create(makeShared<CWlBuffer>(pool_->resource->client(), 1, id));
resource = CWLBufferResource::create(makeShared<CWlBuffer>(pool_->m_resource->client(), 1, id));
listeners.bufferResourceDestroy = events.destroy.registerListener([this](std::any d) {
listeners.bufferResourceDestroy.reset();
m_listeners.bufferResourceDestroy = events.destroy.registerListener([this](std::any d) {
m_listeners.bufferResourceDestroy.reset();
PROTO::shm->destroyResource(this);
});
}
@ -50,16 +50,16 @@ bool CWLSHMBuffer::isSynchronous() {
Aquamarine::SSHMAttrs CWLSHMBuffer::shm() {
Aquamarine::SSHMAttrs attrs;
attrs.success = true;
attrs.fd = pool->fd.get();
attrs.format = NFormatUtils::shmToDRM(fmt);
attrs.fd = m_pool->m_fd.get();
attrs.format = NFormatUtils::shmToDRM(m_fmt);
attrs.size = size;
attrs.stride = stride;
attrs.offset = offset;
attrs.stride = m_stride;
attrs.offset = m_offset;
return attrs;
}
std::tuple<uint8_t*, uint32_t, size_t> CWLSHMBuffer::beginDataPtr(uint32_t flags) {
return {(uint8_t*)pool->data + offset, fmt, stride * size.y};
return {(uint8_t*)m_pool->m_data + m_offset, m_fmt, m_stride * size.y};
}
void CWLSHMBuffer::endDataPtr() {
@ -74,24 +74,24 @@ void CWLSHMBuffer::update(const CRegion& damage) {
;
}
CSHMPool::CSHMPool(CFileDescriptor fd_, size_t size_) : fd(std::move(fd_)), size(size_), data(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0)) {
CSHMPool::CSHMPool(CFileDescriptor fd_, size_t size_) : m_fd(std::move(fd_)), m_size(size_), m_data(mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd.get(), 0)) {
;
}
CSHMPool::~CSHMPool() {
munmap(data, size);
munmap(m_data, m_size);
}
void CSHMPool::resize(size_t size_) {
LOGM(LOG, "Resizing a SHM pool from {} to {}", size, size_);
LOGM(LOG, "Resizing a SHM pool from {} to {}", m_size, size_);
if (data)
munmap(data, size);
size = size_;
data = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0);
if (m_data)
munmap(m_data, m_size);
m_size = size_;
m_data = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_fd.get(), 0);
if UNLIKELY (data == MAP_FAILED)
LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", size, fd.get());
if UNLIKELY (m_data == MAP_FAILED)
LOGM(ERR, "Couldn't mmap {} bytes from fd {} of shm client", m_size, m_fd.get());
}
static int shmIsSizeValid(CFileDescriptor& fd, size_t size) {
@ -104,7 +104,7 @@ static int shmIsSizeValid(CFileDescriptor& fd, size_t size) {
return (size_t)st.st_size >= size;
}
CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor fd_, size_t size_) : resource(resource_) {
CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor fd_, size_t size_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
@ -113,31 +113,31 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
return;
}
pool = makeShared<CSHMPool>(std::move(fd_), size_);
m_pool = makeShared<CSHMPool>(std::move(fd_), size_);
resource->setDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
m_resource->setDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
m_resource->setOnDestroy([this](CWlShmPool* r) { PROTO::shm->destroyResource(this); });
resource->setResize([this](CWlShmPool* r, int32_t size_) {
if UNLIKELY (size_ < (int32_t)pool->size) {
m_resource->setResize([this](CWlShmPool* r, int32_t size_) {
if UNLIKELY (size_ < (int32_t)m_pool->m_size) {
r->error(-1, "Shrinking a shm pool is illegal");
return;
}
if UNLIKELY (!shmIsSizeValid(pool->fd, size_)) {
if UNLIKELY (!shmIsSizeValid(m_pool->m_fd, size_)) {
r->error(-1, "The size of the file is not big enough for the shm pool");
return;
}
pool->resize(size_);
m_pool->resize(size_);
});
resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) {
if UNLIKELY (!pool || !pool->data) {
m_resource->setCreateBuffer([this](CWlShmPool* r, uint32_t id, int32_t offset, int32_t w, int32_t h, int32_t stride, uint32_t fmt) {
if UNLIKELY (!m_pool || !m_pool->m_data) {
r->error(-1, "The provided shm pool failed to allocate properly");
return;
}
if UNLIKELY (std::find(PROTO::shm->shmFormats.begin(), PROTO::shm->shmFormats.end(), fmt) == PROTO::shm->shmFormats.end()) {
if UNLIKELY (std::find(PROTO::shm->m_shmFormats.begin(), PROTO::shm->m_shmFormats.end(), fmt) == PROTO::shm->m_shmFormats.end()) {
r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid");
return;
}
@ -147,11 +147,11 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
return;
}
const auto RESOURCE = PROTO::shm->m_vBuffers.emplace_back(makeShared<CWLSHMBuffer>(self.lock(), id, offset, Vector2D{w, h}, stride, fmt));
const auto RESOURCE = PROTO::shm->m_buffers.emplace_back(makeShared<CWLSHMBuffer>(m_self.lock(), id, offset, Vector2D{w, h}, stride, fmt));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::shm->m_vBuffers.pop_back();
PROTO::shm->m_buffers.pop_back();
return;
}
@ -159,41 +159,41 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor
RESOURCE->resource->buffer = RESOURCE;
});
if UNLIKELY (pool->data == MAP_FAILED)
resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd");
if UNLIKELY (m_pool->m_data == MAP_FAILED)
m_resource->error(WL_SHM_ERROR_INVALID_FD, "Couldn't mmap from fd");
}
bool CWLSHMPoolResource::good() {
return resource->resource();
return m_resource->resource();
}
CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : resource(resource_) {
CWLSHMResource::CWLSHMResource(SP<CWlShm> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); });
m_resource->setOnDestroy([this](CWlShm* r) { PROTO::shm->destroyResource(this); });
resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) {
m_resource->setCreatePool([](CWlShm* r, uint32_t id, int32_t fd, int32_t size) {
CFileDescriptor poolFd{fd};
const auto RESOURCE = PROTO::shm->m_vPools.emplace_back(makeShared<CWLSHMPoolResource>(makeShared<CWlShmPool>(r->client(), r->version(), id), std::move(poolFd), size));
const auto RESOURCE = PROTO::shm->m_pools.emplace_back(makeShared<CWLSHMPoolResource>(makeShared<CWlShmPool>(r->client(), r->version(), id), std::move(poolFd), size));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::shm->m_vPools.pop_back();
PROTO::shm->m_pools.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
// send a few supported formats. No need for any other I think?
for (auto const& s : PROTO::shm->shmFormats) {
resource->sendFormat((wl_shm_format)s);
for (auto const& s : PROTO::shm->m_shmFormats) {
m_resource->sendFormat((wl_shm_format)s);
}
}
bool CWLSHMResource::good() {
return resource->resource();
return m_resource->resource();
}
CWLSHMProtocol::CWLSHMProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -201,36 +201,36 @@ CWLSHMProtocol::CWLSHMProtocol(const wl_interface* iface, const int& ver, const
}
void CWLSHMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
if (shmFormats.empty()) {
shmFormats.push_back(WL_SHM_FORMAT_ARGB8888);
shmFormats.push_back(WL_SHM_FORMAT_XRGB8888);
if (m_shmFormats.empty()) {
m_shmFormats.push_back(WL_SHM_FORMAT_ARGB8888);
m_shmFormats.push_back(WL_SHM_FORMAT_XRGB8888);
static const std::array<DRMFormat, 6> supportedShmFourccFormats = {
DRM_FORMAT_XBGR8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_XRGB2101010, DRM_FORMAT_ARGB2101010, DRM_FORMAT_XBGR2101010, DRM_FORMAT_ABGR2101010,
};
for (auto const& fmt : supportedShmFourccFormats) {
shmFormats.push_back(fmt);
m_shmFormats.push_back(fmt);
}
}
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLSHMResource>(makeShared<CWlShm>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CWLSHMResource>(makeShared<CWlShm>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CWLSHMProtocol::destroyResource(CWLSHMResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CWLSHMProtocol::destroyResource(CWLSHMPoolResource* resource) {
std::erase_if(m_vPools, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_pools, [&](const auto& other) { return other.get() == resource; });
}
void CWLSHMProtocol::destroyResource(CWLSHMBuffer* resource) {
std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_buffers, [&](const auto& other) { return other.get() == resource; });
}

View file

@ -23,9 +23,9 @@ class CSHMPool {
CSHMPool(Hyprutils::OS::CFileDescriptor fd, size_t size);
~CSHMPool();
Hyprutils::OS::CFileDescriptor fd;
size_t size = 0;
void* data = nullptr;
Hyprutils::OS::CFileDescriptor m_fd;
size_t m_size = 0;
void* m_data = nullptr;
void resize(size_t size);
};
@ -45,14 +45,15 @@ class CWLSHMBuffer : public IHLBuffer {
bool good();
int32_t offset = 0, stride = 0;
uint32_t fmt = 0;
SP<CSHMPool> pool;
int32_t m_offset = 0;
int32_t m_stride = 0;
uint32_t m_fmt = 0;
SP<CSHMPool> m_pool;
private:
struct {
CHyprSignalListener bufferResourceDestroy;
} listeners;
} m_listeners;
};
class CWLSHMPoolResource {
@ -61,12 +62,12 @@ class CWLSHMPoolResource {
bool good();
SP<CSHMPool> pool;
SP<CSHMPool> m_pool;
WP<CWLSHMPoolResource> self;
WP<CWLSHMPoolResource> m_self;
private:
SP<CWlShmPool> resource;
SP<CWlShmPool> m_resource;
friend class CWLSHMBuffer;
};
@ -78,7 +79,7 @@ class CWLSHMResource {
bool good();
private:
SP<CWlShm> resource;
SP<CWlShm> m_resource;
};
class CWLSHMProtocol : public IWaylandProtocol {
@ -93,12 +94,12 @@ class CWLSHMProtocol : public IWaylandProtocol {
void destroyResource(CWLSHMBuffer* resource);
//
std::vector<SP<CWLSHMResource>> m_vManagers;
std::vector<SP<CWLSHMPoolResource>> m_vPools;
std::vector<SP<CWLSHMBuffer>> m_vBuffers;
std::vector<SP<CWLSHMResource>> m_managers;
std::vector<SP<CWLSHMPoolResource>> m_pools;
std::vector<SP<CWLSHMBuffer>> m_buffers;
//
std::vector<uint32_t> shmFormats;
std::vector<uint32_t> m_shmFormats;
friend class CWLSHMResource;
friend class CWLSHMPoolResource;

View file

@ -3,154 +3,154 @@
#include <algorithm>
CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWLSurfaceResource> surface_, SP<CWLSurfaceResource> parent_) :
surface(surface_), parent(parent_), resource(resource_) {
m_surface(surface_), m_parent(parent_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSubsurface* r) { destroy(); });
resource->setDestroy([this](CWlSubsurface* r) { destroy(); });
m_resource->setOnDestroy([this](CWlSubsurface* r) { destroy(); });
m_resource->setDestroy([this](CWlSubsurface* r) { destroy(); });
resource->setSetPosition([this](CWlSubsurface* r, int32_t x, int32_t y) { position = {x, y}; });
m_resource->setSetPosition([this](CWlSubsurface* r, int32_t x, int32_t y) { m_position = {x, y}; });
resource->setSetDesync([this](CWlSubsurface* r) { sync = false; });
resource->setSetSync([this](CWlSubsurface* r) { sync = true; });
m_resource->setSetDesync([this](CWlSubsurface* r) { m_sync = false; });
m_resource->setSetSync([this](CWlSubsurface* r) { m_sync = true; });
resource->setPlaceAbove([this](CWlSubsurface* r, wl_resource* surf) {
m_resource->setPlaceAbove([this](CWlSubsurface* r, wl_resource* surf) {
auto SURF = CWLSurfaceResource::fromResource(surf);
if (!parent)
if (!m_parent)
return;
auto pushAboveIndex = [this](int idx) -> void {
for (auto const& c : parent->subsurfaces) {
if (c->zIndex >= idx)
c->zIndex++;
for (auto const& c : m_parent->m_subsurfaces) {
if (c->m_zIndex >= idx)
c->m_zIndex++;
}
};
std::erase_if(parent->subsurfaces, [this](const auto& e) { return e == self || !e; });
std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; });
auto it = std::find(parent->subsurfaces.begin(), parent->subsurfaces.end(), SURF);
auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF);
if (it == parent->subsurfaces.end()) {
if (it == m_parent->m_subsurfaces.end()) {
LOGM(ERR, "Invalid surface reference in placeAbove, likely parent");
pushAboveIndex(1);
parent->subsurfaces.emplace_back(self);
zIndex = 1;
m_parent->m_subsurfaces.emplace_back(m_self);
m_zIndex = 1;
} else {
pushAboveIndex((*it)->zIndex);
zIndex = (*it)->zIndex;
parent->subsurfaces.emplace_back(self);
pushAboveIndex((*it)->m_zIndex);
m_zIndex = (*it)->m_zIndex;
m_parent->m_subsurfaces.emplace_back(m_self);
}
std::sort(parent->subsurfaces.begin(), parent->subsurfaces.end(), [](const auto& a, const auto& b) { return a->zIndex < b->zIndex; });
std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
});
resource->setPlaceBelow([this](CWlSubsurface* r, wl_resource* surf) {
m_resource->setPlaceBelow([this](CWlSubsurface* r, wl_resource* surf) {
auto SURF = CWLSurfaceResource::fromResource(surf);
if (!parent)
if (!m_parent)
return;
auto pushBelowIndex = [this](int idx) -> void {
for (auto const& c : parent->subsurfaces) {
if (c->zIndex <= idx)
c->zIndex--;
for (auto const& c : m_parent->m_subsurfaces) {
if (c->m_zIndex <= idx)
c->m_zIndex--;
}
};
std::erase_if(parent->subsurfaces, [this](const auto& e) { return e == self || !e; });
std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; });
auto it = std::find(parent->subsurfaces.begin(), parent->subsurfaces.end(), SURF);
auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF);
if (it == parent->subsurfaces.end()) {
if (it == m_parent->m_subsurfaces.end()) {
LOGM(ERR, "Invalid surface reference in placeBelow, likely parent");
pushBelowIndex(-1);
parent->subsurfaces.emplace_back(self);
zIndex = -1;
m_parent->m_subsurfaces.emplace_back(m_self);
m_zIndex = -1;
} else {
pushBelowIndex((*it)->zIndex);
zIndex = (*it)->zIndex;
parent->subsurfaces.emplace_back(self);
pushBelowIndex((*it)->m_zIndex);
m_zIndex = (*it)->m_zIndex;
m_parent->m_subsurfaces.emplace_back(m_self);
}
std::sort(parent->subsurfaces.begin(), parent->subsurfaces.end(), [](const auto& a, const auto& b) { return a->zIndex < b->zIndex; });
std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; });
});
listeners.commitSurface = surface->events.commit.registerListener([this](std::any d) {
if (surface->current.texture && !surface->mapped) {
surface->map();
surface->events.map.emit();
m_listeners.commitSurface = m_surface->m_events.commit.registerListener([this](std::any d) {
if (m_surface->m_current.texture && !m_surface->m_mapped) {
m_surface->map();
m_surface->m_events.map.emit();
return;
}
if (!surface->current.texture && surface->mapped) {
surface->events.unmap.emit();
surface->unmap();
if (!m_surface->m_current.texture && m_surface->m_mapped) {
m_surface->m_events.unmap.emit();
m_surface->unmap();
return;
}
});
}
CWLSubsurfaceResource::~CWLSubsurfaceResource() {
events.destroy.emit();
if (surface)
surface->resetRole();
m_events.destroy.emit();
if (m_surface)
m_surface->resetRole();
}
void CWLSubsurfaceResource::destroy() {
if (surface && surface->mapped) {
surface->events.unmap.emit();
surface->unmap();
if (m_surface && m_surface->m_mapped) {
m_surface->m_events.unmap.emit();
m_surface->unmap();
}
events.destroy.emit();
m_events.destroy.emit();
PROTO::subcompositor->destroyResource(this);
}
Vector2D CWLSubsurfaceResource::posRelativeToParent() {
Vector2D pos = position;
SP<CWLSurfaceResource> surf = parent.lock();
Vector2D pos = m_position;
SP<CWLSurfaceResource> surf = m_parent.lock();
// some apps might create cycles, which I believe _technically_ are not a protocol error
// in some cases, notably firefox likes to do that, so we keep track of what
// surfaces we've visited and if we hit a surface we've visited we bail out.
std::vector<SP<CWLSurfaceResource>> surfacesVisited;
while (surf->role->role() == SURFACE_ROLE_SUBSURFACE &&
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE &&
std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
surfacesVisited.emplace_back(surf);
auto subsurface = ((CSubsurfaceRole*)parent->role.get())->subsurface.lock();
pos += subsurface->position;
surf = subsurface->parent.lock();
auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock();
pos += subsurface->m_position;
surf = subsurface->m_parent.lock();
}
return pos;
}
bool CWLSubsurfaceResource::good() {
return resource->resource();
return m_resource->resource();
}
SP<CWLSurfaceResource> CWLSubsurfaceResource::t1Parent() {
SP<CWLSurfaceResource> surf = parent.lock();
SP<CWLSurfaceResource> surf = m_parent.lock();
std::vector<SP<CWLSurfaceResource>> surfacesVisited;
while (surf->role->role() == SURFACE_ROLE_SUBSURFACE &&
while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE &&
std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) {
surfacesVisited.emplace_back(surf);
auto subsurface = ((CSubsurfaceRole*)parent->role.get())->subsurface.lock();
surf = subsurface->parent.lock();
auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock();
surf = subsurface->m_parent.lock();
}
return surf;
}
CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource_) : resource(resource_) {
CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); });
resource->setDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); });
m_resource->setOnDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); });
m_resource->setDestroy([this](CWlSubcompositor* r) { PROTO::subcompositor->destroyResource(this); });
resource->setGetSubsurface([](CWlSubcompositor* r, uint32_t id, wl_resource* surface, wl_resource* parent) {
m_resource->setGetSubsurface([](CWlSubcompositor* r, uint32_t id, wl_resource* surface, wl_resource* parent) {
auto SURF = CWLSurfaceResource::fromResource(surface);
auto PARENT = CWLSurfaceResource::fromResource(parent);
@ -159,15 +159,15 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
return;
}
if UNLIKELY (SURF->role->role() != SURFACE_ROLE_UNASSIGNED) {
if UNLIKELY (SURF->m_role->role() != SURFACE_ROLE_UNASSIGNED) {
r->error(-1, "Surface already has a different role");
return;
}
SP<CWLSurfaceResource> t1Parent = nullptr;
if (PARENT->role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)PARENT->role.get())->subsurface.lock();
if (PARENT->m_role->role() == SURFACE_ROLE_SUBSURFACE) {
auto subsurface = ((CSubsurfaceRole*)PARENT->m_role.get())->m_subsurface.lock();
t1Parent = subsurface->t1Parent();
} else
t1Parent = PARENT;
@ -178,26 +178,26 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
}
const auto RESOURCE =
PROTO::subcompositor->m_vSurfaces.emplace_back(makeShared<CWLSubsurfaceResource>(makeShared<CWlSubsurface>(r->client(), r->version(), id), SURF, PARENT));
PROTO::subcompositor->m_surfaces.emplace_back(makeShared<CWLSubsurfaceResource>(makeShared<CWlSubsurface>(r->client(), r->version(), id), SURF, PARENT));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::subcompositor->m_vSurfaces.pop_back();
PROTO::subcompositor->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
SURF->role = makeShared<CSubsurfaceRole>(RESOURCE);
PARENT->subsurfaces.emplace_back(RESOURCE);
RESOURCE->m_self = RESOURCE;
SURF->m_role = makeShared<CSubsurfaceRole>(RESOURCE);
PARENT->m_subsurfaces.emplace_back(RESOURCE);
LOGM(LOG, "New wl_subsurface with id {} at {:x}", id, (uintptr_t)RESOURCE.get());
PARENT->events.newSubsurface.emit(RESOURCE);
PARENT->m_events.newSubsurface.emit(RESOURCE);
});
}
bool CWLSubcompositorResource::good() {
return resource->resource();
return m_resource->resource();
}
CWLSubcompositorProtocol::CWLSubcompositorProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -205,23 +205,23 @@ CWLSubcompositorProtocol::CWLSubcompositorProtocol(const wl_interface* iface, co
}
void CWLSubcompositorProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLSubcompositorResource>(makeShared<CWlSubcompositor>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CWLSubcompositorResource>(makeShared<CWlSubcompositor>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CWLSubcompositorProtocol::destroyResource(CWLSubcompositorResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CWLSubcompositorProtocol::destroyResource(CWLSubsurfaceResource* resource) {
std::erase_if(m_vSurfaces, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_surfaces, [&](const auto& other) { return other.get() == resource; });
}
CSubsurfaceRole::CSubsurfaceRole(SP<CWLSubsurfaceResource> sub) : subsurface(sub) {
CSubsurfaceRole::CSubsurfaceRole(SP<CWLSubsurfaceResource> sub) : m_subsurface(sub) {
;
}

View file

@ -25,7 +25,7 @@ class CSubsurfaceRole : public ISurfaceRole {
return SURFACE_ROLE_SUBSURFACE;
}
WP<CWLSubsurfaceResource> subsurface;
WP<CWLSubsurfaceResource> m_subsurface;
};
class CWLSubsurfaceResource {
@ -37,28 +37,28 @@ class CWLSubsurfaceResource {
bool good();
SP<CWLSurfaceResource> t1Parent();
bool sync = false;
Vector2D position;
bool m_sync = false;
Vector2D m_position;
WP<CWLSurfaceResource> surface;
WP<CWLSurfaceResource> parent;
WP<CWLSurfaceResource> m_surface;
WP<CWLSurfaceResource> m_parent;
WP<CWLSubsurfaceResource> self;
WP<CWLSubsurfaceResource> m_self;
int zIndex = 1; // by default, it's above
int m_zIndex = 1; // by default, it's above
struct {
CSignal destroy;
} events;
} m_events;
private:
SP<CWlSubsurface> resource;
SP<CWlSubsurface> m_resource;
void destroy();
struct {
CHyprSignalListener commitSurface;
} listeners;
} m_listeners;
};
class CWLSubcompositorResource {
@ -68,7 +68,7 @@ class CWLSubcompositorResource {
bool good();
private:
SP<CWlSubcompositor> resource;
SP<CWlSubcompositor> m_resource;
};
class CWLSubcompositorProtocol : public IWaylandProtocol {
@ -82,8 +82,8 @@ class CWLSubcompositorProtocol : public IWaylandProtocol {
void destroyResource(CWLSubsurfaceResource* resource);
//
std::vector<SP<CWLSubcompositorResource>> m_vManagers;
std::vector<SP<CWLSubsurfaceResource>> m_vSurfaces;
std::vector<SP<CWLSubcompositorResource>> m_managers;
std::vector<SP<CWLSubsurfaceResource>> m_surfaces;
friend class CWLSubcompositorResource;
friend class CWLSubsurfaceResource;