protocols: refactor class member vars (a-m) (#10265)

This commit is contained in:
davc0n 2025-05-04 00:13:29 +02:00 committed by GitHub
parent 46ac115bd1
commit adbae0f74d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
58 changed files with 1566 additions and 1561 deletions

View file

@ -2,34 +2,34 @@
#include "../Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) {
if UNLIKELY (!resource_->resource())
return;
resource->setData(this);
m_resource->setData(this);
resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
resource->setDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
m_resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
m_resource->setDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
}
bool CForeignToplevelHandle::good() {
return resource->resource();
return m_resource->resource();
}
PHLWINDOW CForeignToplevelHandle::window() {
return pWindow.lock();
return m_window.lock();
}
CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_) : resource(resource_) {
CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_) : m_resource(resource_) {
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
resource->setDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
m_resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
m_resource->setDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
resource->setStop([this](CExtForeignToplevelListV1* h) {
resource->sendFinished();
finished = true;
m_resource->setStop([this](CExtForeignToplevelListV1* h) {
m_resource->sendFinished();
m_finished = true;
LOGM(LOG, "CForeignToplevelList: finished");
});
@ -42,75 +42,75 @@ CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resourc
}
void CForeignToplevelList::onMap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto NEWHANDLE = PROTO::foreignToplevel->m_vHandles.emplace_back(
makeShared<CForeignToplevelHandle>(makeShared<CExtForeignToplevelHandleV1>(resource->client(), resource->version(), 0), pWindow));
const auto NEWHANDLE = PROTO::foreignToplevel->m_handles.emplace_back(
makeShared<CForeignToplevelHandle>(makeShared<CExtForeignToplevelHandleV1>(m_resource->client(), m_resource->version(), 0), pWindow));
if (!NEWHANDLE->good()) {
LOGM(ERR, "Couldn't create a foreign handle");
resource->noMemory();
PROTO::foreignToplevel->m_vHandles.pop_back();
m_resource->noMemory();
PROTO::foreignToplevel->m_handles.pop_back();
return;
}
const auto IDENTIFIER = std::format("{:08x}->{:016x}", static_cast<uint32_t>((uintptr_t)this & 0xFFFFFFFF), (uintptr_t)pWindow.get());
LOGM(LOG, "Newly mapped window gets an identifier of {}", IDENTIFIER);
resource->sendToplevel(NEWHANDLE->resource.get());
NEWHANDLE->resource->sendIdentifier(IDENTIFIER.c_str());
NEWHANDLE->resource->sendAppId(pWindow->m_initialClass.c_str());
NEWHANDLE->resource->sendTitle(pWindow->m_initialTitle.c_str());
NEWHANDLE->resource->sendDone();
m_resource->sendToplevel(NEWHANDLE->m_resource.get());
NEWHANDLE->m_resource->sendIdentifier(IDENTIFIER.c_str());
NEWHANDLE->m_resource->sendAppId(pWindow->m_initialClass.c_str());
NEWHANDLE->m_resource->sendTitle(pWindow->m_initialTitle.c_str());
NEWHANDLE->m_resource->sendDone();
handles.push_back(NEWHANDLE);
m_handles.push_back(NEWHANDLE);
}
SP<CForeignToplevelHandle> CForeignToplevelList::handleForWindow(PHLWINDOW pWindow) {
std::erase_if(handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(handles.begin(), handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == handles.end() ? SP<CForeignToplevelHandle>{} : IT->lock();
std::erase_if(m_handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(m_handles.begin(), m_handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == m_handles.end() ? SP<CForeignToplevelHandle>{} : IT->lock();
}
void CForeignToplevelList::onTitle(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendTitle(pWindow->m_title.c_str());
H->resource->sendDone();
H->m_resource->sendTitle(pWindow->m_title.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelList::onClass(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendAppId(pWindow->m_class.c_str());
H->resource->sendDone();
H->m_resource->sendAppId(pWindow->m_class.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelList::onUnmap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H)
return;
H->resource->sendClosed();
H->closed = true;
H->m_resource->sendClosed();
H->m_closed = true;
}
bool CForeignToplevelList::good() {
return resource->resource();
return m_resource->resource();
}
CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -120,7 +120,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onMap(window);
}
});
@ -131,7 +131,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onUnmap(window);
}
});
@ -142,29 +142,29 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onTitle(window);
}
});
}
void CForeignToplevelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CForeignToplevelList>(makeShared<CExtForeignToplevelListV1>(client, ver, id))).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CForeignToplevelList>(makeShared<CExtForeignToplevelListV1>(client, ver, id))).get();
if UNLIKELY (!RESOURCE->good()) {
LOGM(ERR, "Couldn't create a foreign list");
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CForeignToplevelProtocol::onManagerResourceDestroy(CForeignToplevelList* mgr) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == mgr; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == mgr; });
}
void CForeignToplevelProtocol::destroyHandle(CForeignToplevelHandle* handle) {
std::erase_if(m_vHandles, [&](const auto& other) { return other.get() == handle; });
std::erase_if(m_handles, [&](const auto& other) { return other.get() == handle; });
}
bool CForeignToplevelProtocol::windowValidForForeign(PHLWINDOW pWindow) {