diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2023-08-21 19:36:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-21 19:36:09 +0200 |
| commit | 37128bfd43a3d86d270c09e34f18fe4df48c6b35 (patch) | |
| tree | ade4b361562543679b7eaecbe27b5cd0415eef73 /src/protocols/XDGOutput.cpp | |
| parent | 17d8e4750bd79e0d18b5d0c9f578f23fa47552f4 (diff) | |
internal: Wayland Protocol impl improvements (#2944)
Diffstat (limited to 'src/protocols/XDGOutput.cpp')
| -rw-r--r-- | src/protocols/XDGOutput.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 0d3aa9b1..8d9bbd84 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -8,21 +8,18 @@ #define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3 static void destroyManagerResource(wl_client* client, wl_resource* resource) { - ((CXDGOutputProtocol*)wl_resource_get_user_data(resource))->onManagerResourceDestroy(resource); - wl_resource_destroy(resource); + RESOURCE_OR_BAIL(PRESOURCE); + reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onManagerResourceDestroy(resource); } static void destroyOutputResource(wl_client* client, wl_resource* resource) { - ((CXDGOutputProtocol*)wl_resource_get_user_data(resource))->onOutputResourceDestroy(resource); - wl_resource_destroy(resource); -} - -static void destroyOutputResourceOnly(wl_resource* resource) { - ((CXDGOutputProtocol*)wl_resource_get_user_data(resource))->onOutputResourceDestroy(resource); + RESOURCE_OR_BAIL(PRESOURCE); + reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onOutputResourceDestroy(resource); } static void getXDGOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* outputResource) { - ((CXDGOutputProtocol*)wl_resource_get_user_data(resource))->onManagerGetXDGOutput(client, resource, id, outputResource); + RESOURCE_OR_BAIL(PRESOURCE); + reinterpret_cast<CXDGOutputProtocol*>(PRESOURCE->data())->onManagerGetXDGOutput(client, resource, id, outputResource); } // @@ -41,18 +38,23 @@ void CXDGOutputProtocol::onManagerResourceDestroy(wl_resource* res) { } void CXDGOutputProtocol::onOutputResourceDestroy(wl_resource* res) { - std::erase_if(m_vXDGOutputs, [&](const auto& other) { return !other->resource || other->resource->resource() == res; }); + std::erase_if(m_vXDGOutputs, [&](const auto& other) { + if (!other->resource) + return false; // ??? + return other->resource->resource() == res; + }); } void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { - const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CWaylandResource>(client, &zxdg_output_manager_v1_interface, ver, id, false)).get(); + const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CWaylandResource>(client, &zxdg_output_manager_v1_interface, ver, id)).get(); if (!RESOURCE->good()) { Debug::log(LOG, "Couldn't bind XDGOutputMgr"); return; } - RESOURCE->setImplementation(&MANAGER_IMPL, this, nullptr); + RESOURCE->setImplementation(&MANAGER_IMPL, nullptr); + RESOURCE->setData(this); } CXDGOutputProtocol::CXDGOutputProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { @@ -86,10 +88,12 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(wl_client* client, wl_resource* r if (!pXDGOutput->resource->good()) { pXDGOutput->resource.release(); + m_vXDGOutputs.pop_back(); return; } - pXDGOutput->resource->setImplementation(&OUTPUT_IMPL, this, destroyOutputResourceOnly); + pXDGOutput->resource->setImplementation(&OUTPUT_IMPL, nullptr); + pXDGOutput->resource->setData(this); const auto XDGVER = pXDGOutput->resource->version(); if (XDGVER >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) @@ -106,6 +110,9 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(wl_client* client, wl_resource* r void CXDGOutputProtocol::updateOutputDetails(SXDGOutput* pOutput) { static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + + if (!pOutput->resource->good()) + return; const auto POS = pOutput->isXWayland ? pOutput->monitor->vecXWaylandPosition : pOutput->monitor->vecPosition; zxdg_output_v1_send_logical_position(pOutput->resource->resource(), POS.x, POS.y); |
