protocols/fractional-scale: track if scale is known and send scales eagerly when known (#14798)

This commit is contained in:
Awused
2026-06-07 12:26:02 +02:00
committed by Vaxry
parent acf0972147
commit 55b136e390
4 changed files with 26 additions and 4 deletions
+9 -4
View File
@@ -1,5 +1,6 @@
#include "FractionalScale.hpp"
#include <algorithm>
#include "Compositor.hpp"
#include "core/Compositor.hpp"
CFractionalScaleProtocol::CFractionalScaleProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@@ -44,11 +45,11 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1*
PADDON->m_resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
PADDON->m_resource->setDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
if (std::ranges::find_if(m_surfaceScales, [surface](const auto& e) { return e.first == surface; }) == m_surfaceScales.end())
m_surfaceScales.emplace(surface, 1.F);
if (surface->m_mapped)
// send known scale or default 1.0 if surface is already mapped without a known scale
if (hasKnownScale(surface))
PADDON->setScale(m_surfaceScales.at(surface));
else if (surface->m_mapped)
PADDON->setScale(1.F);
// clean old
std::erase_if(m_surfaceScales, [](const auto& e) { return e.first.expired(); });
@@ -60,6 +61,10 @@ void CFractionalScaleProtocol::sendScale(SP<CWLSurfaceResource> surf, const floa
m_addons[surf]->setScale(scale);
}
bool CFractionalScaleProtocol::hasKnownScale(SP<CWLSurfaceResource> surf) {
return m_surfaceScales.contains(surf);
}
CFractionalScaleAddon::CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> 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); });
+1
View File
@@ -41,6 +41,7 @@ class CFractionalScaleProtocol : public IWaylandProtocol {
void onSurfaceDestroy(SP<CWLSurfaceResource> surf);
void sendScale(SP<CWLSurfaceResource> surf, const float& scale);
bool hasKnownScale(SP<CWLSurfaceResource> surf);
private:
void removeAddon(CFractionalScaleAddon*);
+5
View File
@@ -249,6 +249,11 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id
SURF->m_role = makeShared<CLayerShellRole>(RESOURCE);
g_pCompositor->m_layers.emplace_back(Desktop::View::CLayerSurface::create(RESOURCE));
if (PMONITOR) {
g_pCompositor->setPreferredScaleForSurface(SURF, PMONITOR->m_scale);
g_pCompositor->setPreferredTransformForSurface(SURF, PMONITOR->m_transform);
}
LOGM(Log::DEBUG, "New wlr_layer_surface {:x}", (uintptr_t)RESOURCE.get());
}
+11
View File
@@ -1,5 +1,7 @@
#include "Subcompositor.hpp"
#include "Compositor.hpp"
#include "protocols/FractionalScale.hpp"
#include "../../Compositor.hpp"
#include <algorithm>
CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWLSurfaceResource> surface_, SP<CWLSurfaceResource> parent_) :
@@ -197,6 +199,15 @@ CWLSubcompositorResource::CWLSubcompositorResource(SP<CWlSubcompositor> resource
SURF->m_role = makeShared<CSubsurfaceRole>(RESOURCE);
PARENT->m_subsurfaces.emplace_back(RESOURCE);
if (PROTO::fractional->hasKnownScale(PARENT)) {
const auto PARENTSURFACE = Desktop::View::CWLSurface::fromResource(PARENT);
if (PARENTSURFACE) {
g_pCompositor->setPreferredScaleForSurface(SURF, PARENTSURFACE->m_lastScaleFloat);
g_pCompositor->setPreferredTransformForSurface(SURF, PARENTSURFACE->m_lastTransform);
}
}
LOGM(Log::DEBUG, "New wl_subsurface with id {} at {:x}", id, (uintptr_t)RESOURCE.get());
PARENT->m_events.newSubsurface.emit(RESOURCE);