mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
label: use a callback from asyncGatherer to render
This commit is contained in:
parent
1f268e0a39
commit
582e8c86b4
5 changed files with 40 additions and 9 deletions
|
@ -116,6 +116,9 @@ static const wl_callback_listener callbackListener = {
|
||||||
void CSessionLockSurface::render() {
|
void CSessionLockSurface::render() {
|
||||||
Debug::log(TRACE, "render lock");
|
Debug::log(TRACE, "render lock");
|
||||||
|
|
||||||
|
if (frameCallback)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto FEEDBACK = g_pRenderer->renderLock(*this);
|
const auto FEEDBACK = g_pRenderer->renderLock(*this);
|
||||||
frameCallback = wl_surface_frame(surface);
|
frameCallback = wl_surface_frame(surface);
|
||||||
wl_callback_add_listener(frameCallback, &callbackListener, this);
|
wl_callback_add_listener(frameCallback, &callbackListener, this);
|
||||||
|
|
|
@ -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();
|
m_sLoopState.timersMutex.lock();
|
||||||
auto timerscpy = m_vTimers;
|
auto timerscpy = m_vTimers;
|
||||||
m_sLoopState.timersMutex.unlock();
|
m_sLoopState.timersMutex.unlock();
|
||||||
|
@ -427,13 +435,6 @@ void CHyprlock::run() {
|
||||||
|
|
||||||
passed.clear();
|
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)
|
if (m_bTerminate)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,6 +263,17 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
|
||||||
preloadTargets.push_back(target);
|
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() {
|
void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
||||||
while (!g_pHyprlock->m_bTerminate) {
|
while (!g_pHyprlock->m_bTerminate) {
|
||||||
|
|
||||||
|
@ -292,7 +303,12 @@ void CAsyncResourceGatherer::asyncAssetSpinLock() {
|
||||||
renderText(r);
|
renderText(r);
|
||||||
} else {
|
} else {
|
||||||
Debug::log(ERR, "Unsupported async preload type {}??", (int)r.type);
|
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;
|
asyncLoopState.busy = false;
|
||||||
|
|
|
@ -37,6 +37,10 @@ class CAsyncResourceGatherer {
|
||||||
std::string id;
|
std::string id;
|
||||||
|
|
||||||
std::unordered_map<std::string, std::any> props;
|
std::unordered_map<std::string, std::any> props;
|
||||||
|
|
||||||
|
// optional
|
||||||
|
void (*callback)(void*) = nullptr;
|
||||||
|
void* callbackData = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void requestAsyncAssetPreload(const SPreloadRequest& request);
|
void requestAsyncAssetPreload(const SPreloadRequest& request);
|
||||||
|
|
|
@ -16,11 +16,15 @@ static void onTimer(std::shared_ptr<CTimer> self, void* data) {
|
||||||
// update label
|
// update label
|
||||||
PLABEL->onTimerUpdate();
|
PLABEL->onTimerUpdate();
|
||||||
|
|
||||||
// render and replant
|
// plant new timer
|
||||||
PLABEL->renderSuper();
|
|
||||||
PLABEL->plantTimer();
|
PLABEL->plantTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onAssetCallback(void* data) {
|
||||||
|
const auto PLABEL = (CLabel*)data;
|
||||||
|
PLABEL->renderSuper();
|
||||||
|
}
|
||||||
|
|
||||||
void CLabel::onTimerUpdate() {
|
void CLabel::onTimerUpdate() {
|
||||||
std::string oldFormatted = label.formatted;
|
std::string oldFormatted = label.formatted;
|
||||||
|
|
||||||
|
@ -37,6 +41,9 @@ void CLabel::onTimerUpdate() {
|
||||||
pendingResourceID = request.id;
|
pendingResourceID = request.id;
|
||||||
request.asset = label.formatted;
|
request.asset = label.formatted;
|
||||||
|
|
||||||
|
request.callback = onAssetCallback;
|
||||||
|
request.callbackData = this;
|
||||||
|
|
||||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue