label: use a callback from asyncGatherer to render

This commit is contained in:
Vaxry 2024-02-26 18:25:52 +00:00
parent 1f268e0a39
commit 582e8c86b4
5 changed files with 40 additions and 9 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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<CTimer> 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;

View File

@ -37,6 +37,10 @@ class CAsyncResourceGatherer {
std::string id;
std::unordered_map<std::string, std::any> props;
// optional
void (*callback)(void*) = nullptr;
void* callbackData = nullptr;
};
void requestAsyncAssetPreload(const SPreloadRequest& request);

View File

@ -16,11 +16,15 @@ static void onTimer(std::shared_ptr<CTimer> 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);
}