From 21ba8b363e94294c3af8ac535728d5ad27762d35 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 3 Nov 2023 21:02:12 +0000 Subject: [PATCH] fractional-scale: fix addon existence check --- src/protocols/FractionalScale.cpp | 11 ++--------- src/protocols/FractionalScale.hpp | 1 - 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/protocols/FractionalScale.cpp b/src/protocols/FractionalScale.cpp index 19e60295..f284dd0d 100644 --- a/src/protocols/FractionalScale.cpp +++ b/src/protocols/FractionalScale.cpp @@ -76,26 +76,19 @@ static void handleAddonDestroy(wl_resource* resource) { void CFractionalScaleProtocolManager::getFractionalScale(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface) { const auto PSURFACE = wlr_surface_from_resource(surface); + const auto PADDON = getAddonForSurface(PSURFACE); - if (addonExists(PSURFACE)) { + if (PADDON->pResource) { wl_resource_post_error(resource, WP_FRACTIONAL_SCALE_MANAGER_V1_ERROR_FRACTIONAL_SCALE_EXISTS, "Fractional scale exists."); return; } - const auto PADDON = getAddonForSurface(PSURFACE); - PADDON->pResource = wl_resource_create(client, &wp_fractional_scale_v1_interface, wl_resource_get_version(resource), id); wl_resource_set_implementation(PADDON->pResource, &fractionalScaleAddonImpl, PADDON, handleAddonDestroy); wp_fractional_scale_v1_send_preferred_scale(PADDON->pResource, (uint32_t)std::round(PADDON->preferredScale * 120.0)); } -bool CFractionalScaleProtocolManager::addonExists(wlr_surface* surface) { - const auto IT = std::find_if(m_vFractionalScaleAddons.begin(), m_vFractionalScaleAddons.end(), [&](const auto& other) { return other->pSurface == surface; }); - - return IT != m_vFractionalScaleAddons.end(); -} - SFractionalScaleAddon* CFractionalScaleProtocolManager::getAddonForSurface(wlr_surface* surface) { const auto IT = std::find_if(m_vFractionalScaleAddons.begin(), m_vFractionalScaleAddons.end(), [&](const auto& other) { return other->pSurface == surface; }); diff --git a/src/protocols/FractionalScale.hpp b/src/protocols/FractionalScale.hpp index 99696319..71b2c858 100644 --- a/src/protocols/FractionalScale.hpp +++ b/src/protocols/FractionalScale.hpp @@ -30,7 +30,6 @@ class CFractionalScaleProtocolManager { private: SFractionalScaleAddon* getAddonForSurface(wlr_surface*); - bool addonExists(wlr_surface*); std::vector> m_vFractionalScaleAddons;