diff --git a/example/launch.json b/example/launch.json index c47bdb72..e60cc900 100644 --- a/example/launch.json +++ b/example/launch.json @@ -22,5 +22,6 @@ } ] }, + ] } \ No newline at end of file diff --git a/src/protocols/FractionalScale.cpp b/src/protocols/FractionalScale.cpp index d1e0a604..3b24becd 100644 --- a/src/protocols/FractionalScale.cpp +++ b/src/protocols/FractionalScale.cpp @@ -41,13 +41,14 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1* return; } - PADDON->resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); }); - PADDON->resource->setDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); }); + PADDON->m_resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); }); + PADDON->m_resource->setDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); }); - if (std::find_if(m_mSurfaceScales.begin(), m_mSurfaceScales.end(), [surface](const auto& e) { return e.first == surface; }) == m_mSurfaceScales.end()) + if (std::ranges::find_if(m_mSurfaceScales, [surface](const auto& e) { return e.first == surface; }) == m_mSurfaceScales.end()) m_mSurfaceScales.emplace(surface, 1.F); - PADDON->setScale(m_mSurfaceScales.at(surface)); + if (surface->mapped) + PADDON->setScale(m_mSurfaceScales.at(surface)); // clean old std::erase_if(m_mSurfaceScales, [](const auto& e) { return e.first.expired(); }); @@ -59,23 +60,23 @@ void CFractionalScaleProtocol::sendScale(SP surf, const floa m_mAddons[surf]->setScale(scale); } -CFractionalScaleAddon::CFractionalScaleAddon(SP resource_, SP surf_) : resource(resource_), surface(surf_) { - resource->setDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); }); - resource->setOnDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); }); -} - -void CFractionalScaleAddon::onSurfaceDestroy() { - surfaceGone = true; +CFractionalScaleAddon::CFractionalScaleAddon(SP resource_, SP surf_) : m_resource(resource_), m_surface(surf_) { + m_resource->setDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); }); + m_resource->setOnDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); }); } void CFractionalScaleAddon::setScale(const float& scale) { - resource->sendPreferredScale(std::round(scale * 120.0)); + if (m_scale == scale) + return; + + m_scale = scale; + m_resource->sendPreferredScale(std::round(scale * 120.0)); } bool CFractionalScaleAddon::good() { - return resource->resource(); + return m_resource->resource(); } SP CFractionalScaleAddon::surf() { - return surface.lock(); + return m_surface.lock(); } diff --git a/src/protocols/FractionalScale.hpp b/src/protocols/FractionalScale.hpp index f6d1f96f..98cd7eaa 100644 --- a/src/protocols/FractionalScale.hpp +++ b/src/protocols/FractionalScale.hpp @@ -13,25 +13,23 @@ class CFractionalScaleAddon { CFractionalScaleAddon(SP resource_, SP surf_); void setScale(const float& scale); - void onSurfaceDestroy(); bool good(); SP surf(); bool operator==(const wl_resource* other) const { - return other == resource->resource(); + return other == m_resource->resource(); } bool operator==(const CFractionalScaleAddon* other) const { - return other->resource == resource; + return other->m_resource == m_resource; } private: - SP resource; - float scale = 1.F; - WP surface; - bool surfaceGone = false; + SP m_resource; + float m_scale = -1.F; // unset + WP m_surface; friend class CFractionalScaleProtocol; };