mirror of
https://github.com/hyprwm/Hyprland
synced 2025-01-23 19:09:50 +01:00
fractional-scale: avoid redundant and duplicate scale events
fixes #9126
This commit is contained in:
parent
c8a0443adc
commit
d335c8f101
3 changed files with 21 additions and 21 deletions
|
@ -22,5 +22,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -41,13 +41,14 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1*
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PADDON->resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
|
PADDON->m_resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
|
||||||
PADDON->resource->setDestroy([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);
|
m_mSurfaceScales.emplace(surface, 1.F);
|
||||||
|
|
||||||
PADDON->setScale(m_mSurfaceScales.at(surface));
|
if (surface->mapped)
|
||||||
|
PADDON->setScale(m_mSurfaceScales.at(surface));
|
||||||
|
|
||||||
// clean old
|
// clean old
|
||||||
std::erase_if(m_mSurfaceScales, [](const auto& e) { return e.first.expired(); });
|
std::erase_if(m_mSurfaceScales, [](const auto& e) { return e.first.expired(); });
|
||||||
|
@ -59,23 +60,23 @@ void CFractionalScaleProtocol::sendScale(SP<CWLSurfaceResource> surf, const floa
|
||||||
m_mAddons[surf]->setScale(scale);
|
m_mAddons[surf]->setScale(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFractionalScaleAddon::CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_) : resource(resource_), surface(surf_) {
|
CFractionalScaleAddon::CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_) : m_resource(resource_), m_surface(surf_) {
|
||||||
resource->setDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); });
|
m_resource->setDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); });
|
||||||
resource->setOnDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); });
|
m_resource->setOnDestroy([this](CWpFractionalScaleV1* self) { PROTO::fractional->removeAddon(this); });
|
||||||
}
|
|
||||||
|
|
||||||
void CFractionalScaleAddon::onSurfaceDestroy() {
|
|
||||||
surfaceGone = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFractionalScaleAddon::setScale(const float& scale) {
|
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() {
|
bool CFractionalScaleAddon::good() {
|
||||||
return resource->resource();
|
return m_resource->resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
SP<CWLSurfaceResource> CFractionalScaleAddon::surf() {
|
SP<CWLSurfaceResource> CFractionalScaleAddon::surf() {
|
||||||
return surface.lock();
|
return m_surface.lock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,25 +13,23 @@ class CFractionalScaleAddon {
|
||||||
CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_);
|
CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_);
|
||||||
|
|
||||||
void setScale(const float& scale);
|
void setScale(const float& scale);
|
||||||
void onSurfaceDestroy();
|
|
||||||
|
|
||||||
bool good();
|
bool good();
|
||||||
|
|
||||||
SP<CWLSurfaceResource> surf();
|
SP<CWLSurfaceResource> surf();
|
||||||
|
|
||||||
bool operator==(const wl_resource* other) const {
|
bool operator==(const wl_resource* other) const {
|
||||||
return other == resource->resource();
|
return other == m_resource->resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const CFractionalScaleAddon* other) const {
|
bool operator==(const CFractionalScaleAddon* other) const {
|
||||||
return other->resource == resource;
|
return other->m_resource == m_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SP<CWpFractionalScaleV1> resource;
|
SP<CWpFractionalScaleV1> m_resource;
|
||||||
float scale = 1.F;
|
float m_scale = -1.F; // unset
|
||||||
WP<CWLSurfaceResource> surface;
|
WP<CWLSurfaceResource> m_surface;
|
||||||
bool surfaceGone = false;
|
|
||||||
|
|
||||||
friend class CFractionalScaleProtocol;
|
friend class CFractionalScaleProtocol;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue