diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index af8c042..78faec3 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -316,7 +316,7 @@ std::vector>* CRenderer::getOrCreateWidgetsFor(const CS } else if (c.type == "input-field") { widgets[surf].emplace_back(std::make_unique(surf->size, c.values)); } else if (c.type == "label") { - widgets[surf].emplace_back(std::make_unique(surf->size, c.values, /* evil */ const_cast(surf))); + widgets[surf].emplace_back(std::make_unique(surf->size, c.values, surf->output->stringPort)); } } } diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index 3866103..04530b5 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -56,8 +56,8 @@ void CLabel::plantTimer() { labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), onTimer, this); } -CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map& props, CSessionLockSurface* surface_) : - surface(surface_), shadow(this, props, viewport_) { +CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map& props, const std::string& output) : + outputStringPort(output), shadow(this, props, viewport_) { labelPreFormat = std::any_cast(props.at("text")); std::string fontFamily = std::any_cast(props.at("font_family")); CColor labelColor = std::any_cast(props.at("color")); @@ -118,9 +118,25 @@ bool CLabel::draw(const SRenderData& data) { shadow.draw(data); g_pRenderer->renderTexture(box, asset->texture, data.opacity); - return !pendingResourceID.empty(); + return false; +} + +static void onAssetCallbackTimer(std::shared_ptr self, void* data) { + const auto PLABEL = (CLabel*)data; + PLABEL->renderSuper(); } void CLabel::renderSuper() { - surface->render(); + const auto MON = + std::find_if(g_pHyprlock->m_vOutputs.begin(), g_pHyprlock->m_vOutputs.end(), [this](const auto& other) { return other->stringPort == this->outputStringPort; }); + + if (MON == g_pHyprlock->m_vOutputs.end() || !MON->get()) + return; + + const auto PMONITOR = MON->get(); + + PMONITOR->sessionLockSurface->render(); + + if (!pendingResourceID.empty()) /* did not consume the pending resource */ + g_pHyprlock->addTimer(std::chrono::milliseconds(100), onAssetCallbackTimer, this); } \ No newline at end of file diff --git a/src/renderer/widgets/Label.hpp b/src/renderer/widgets/Label.hpp index 9d27683..5fb6bf0 100644 --- a/src/renderer/widgets/Label.hpp +++ b/src/renderer/widgets/Label.hpp @@ -14,7 +14,7 @@ class CSessionLockSurface; class CLabel : public IWidget { public: - CLabel(const Vector2D& viewport, const std::unordered_map& props, CSessionLockSurface* surface_); + CLabel(const Vector2D& viewport, const std::unordered_map& props, const std::string& output); ~CLabel(); virtual bool draw(const SRenderData& data); @@ -35,8 +35,9 @@ class CLabel : public IWidget { std::string resourceID; std::string pendingResourceID; // if dynamic label std::string halign, valign; - SPreloadedAsset* asset = nullptr; - CSessionLockSurface* surface = nullptr; + SPreloadedAsset* asset = nullptr; + + std::string outputStringPort; CAsyncResourceGatherer::SPreloadRequest request;