diff --git a/src/core/LockSurface.cpp b/src/core/LockSurface.cpp index d160292..3223049 100644 --- a/src/core/LockSurface.cpp +++ b/src/core/LockSurface.cpp @@ -116,6 +116,9 @@ static const wl_callback_listener callbackListener = { void CSessionLockSurface::render() { Debug::log(TRACE, "render lock"); + if (frameCallback) + return; + const auto FEEDBACK = g_pRenderer->renderLock(*this); frameCallback = wl_surface_frame(surface); wl_callback_add_listener(frameCallback, &callbackListener, this); diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 5d2f336..1566d5d 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -405,6 +405,14 @@ void CHyprlock::run() { } } + // finalize wayland dispatching. Dispatch pending on the queue + int ret = 0; + do { + ret = wl_display_dispatch_pending(m_sWaylandState.display); + wl_display_flush(m_sWaylandState.display); + } while (ret > 0); + + // do timers m_sLoopState.timersMutex.lock(); auto timerscpy = m_vTimers; m_sLoopState.timersMutex.unlock(); @@ -427,13 +435,6 @@ void CHyprlock::run() { passed.clear(); - // finalize wayland dispatching. Dispatch pending on the queue - int ret = 0; - do { - ret = wl_display_dispatch_pending(m_sWaylandState.display); - wl_display_flush(m_sWaylandState.display); - } while (ret > 0); - if (m_bTerminate) break; } diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index 7c97efd..d2d5b88 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -263,6 +263,17 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) { preloadTargets.push_back(target); } +struct STimerCallbackData { + void (*cb)(void*) = nullptr; + void* data = nullptr; +}; + +static void timerCallback(std::shared_ptr self, void* data_) { + auto data = (STimerCallbackData*)data_; + data->cb(data->data); + delete data; +} + void CAsyncResourceGatherer::asyncAssetSpinLock() { while (!g_pHyprlock->m_bTerminate) { @@ -292,7 +303,12 @@ void CAsyncResourceGatherer::asyncAssetSpinLock() { renderText(r); } else { Debug::log(ERR, "Unsupported async preload type {}??", (int)r.type); + continue; } + + // plant timer for callback + if (r.callback) + g_pHyprlock->addTimer(std::chrono::milliseconds(0), timerCallback, new STimerCallbackData{r.callback, r.callbackData}); } asyncLoopState.busy = false; diff --git a/src/renderer/AsyncResourceGatherer.hpp b/src/renderer/AsyncResourceGatherer.hpp index 24a5e56..50c8d99 100644 --- a/src/renderer/AsyncResourceGatherer.hpp +++ b/src/renderer/AsyncResourceGatherer.hpp @@ -37,6 +37,10 @@ class CAsyncResourceGatherer { std::string id; std::unordered_map props; + + // optional + void (*callback)(void*) = nullptr; + void* callbackData = nullptr; }; void requestAsyncAssetPreload(const SPreloadRequest& request); diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index f3e1921..3e6d54c 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -16,11 +16,15 @@ static void onTimer(std::shared_ptr self, void* data) { // update label PLABEL->onTimerUpdate(); - // render and replant - PLABEL->renderSuper(); + // plant new timer PLABEL->plantTimer(); } +static void onAssetCallback(void* data) { + const auto PLABEL = (CLabel*)data; + PLABEL->renderSuper(); +} + void CLabel::onTimerUpdate() { std::string oldFormatted = label.formatted; @@ -37,6 +41,9 @@ void CLabel::onTimerUpdate() { pendingResourceID = request.id; request.asset = label.formatted; + request.callback = onAssetCallback; + request.callbackData = this; + g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); }