label: Fix label updates (#152)

* label: render output via stringPort instead of surface

* label: retry onAssetCallback

Calling `render` might not update the asset when the surfaces frameCallback is already set.

* Revert "label: fix rendering with multiple timers that fire at the same time (#147)"

This reverts commit e9a57f0dae.
This commit is contained in:
Maximilian Seidler 2024-03-08 23:48:59 +01:00 committed by GitHub
parent e9a57f0dae
commit b4a1c8ccbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 8 deletions

View File

@ -316,7 +316,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
} else if (c.type == "input-field") {
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values));
} else if (c.type == "label") {
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values, /* evil */ const_cast<CSessionLockSurface*>(surf)));
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values, surf->output->stringPort));
}
}
}

View File

@ -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<std::string, std::any>& props, CSessionLockSurface* surface_) :
surface(surface_), shadow(this, props, viewport_) {
CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
outputStringPort(output), shadow(this, props, viewport_) {
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
CColor labelColor = std::any_cast<Hyprlang::INT>(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<CTimer> 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);
}

View File

@ -14,7 +14,7 @@ class CSessionLockSurface;
class CLabel : public IWidget {
public:
CLabel(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, CSessionLockSurface* surface_);
CLabel(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
~CLabel();
virtual bool draw(const SRenderData& data);
@ -36,7 +36,8 @@ class CLabel : public IWidget {
std::string pendingResourceID; // if dynamic label
std::string halign, valign;
SPreloadedAsset* asset = nullptr;
CSessionLockSurface* surface = nullptr;
std::string outputStringPort;
CAsyncResourceGatherer::SPreloadRequest request;