|
18 | 18 |
|
19 | 19 | static int wlTick(SP<CEventLoopTimer> self, void* data) { |
20 | 20 | if (g_pAnimationManager) |
21 | | - g_pAnimationManager->onTicked(); |
22 | | - |
23 | | - if (g_pCompositor->m_sessionActive && g_pAnimationManager && g_pHookSystem && !g_pCompositor->m_unsafeState && |
24 | | - std::ranges::any_of(g_pCompositor->m_monitors, [](const auto& mon) { return mon->m_enabled && mon->m_output; })) { |
25 | | - g_pAnimationManager->tick(); |
26 | | - EMIT_HOOK_EVENT("tick", nullptr); |
27 | | - } |
28 | | - |
29 | | - if (g_pAnimationManager && g_pAnimationManager->shouldTickForNext()) |
30 | | - g_pAnimationManager->scheduleTick(); |
| 21 | + g_pAnimationManager->frameTick(); |
31 | 22 |
|
32 | 23 | return 0; |
33 | 24 | } |
@@ -249,26 +240,40 @@ void CHyprAnimationManager::tick() { |
249 | 240 | tickDone(); |
250 | 241 | } |
251 | 242 |
|
252 | | -void CHyprAnimationManager::scheduleTick() { |
253 | | - if (m_tickScheduled) |
| 243 | +void CHyprAnimationManager::frameTick() { |
| 244 | + onTicked(); |
| 245 | + |
| 246 | + if (!shouldTickForNext()) |
254 | 247 | return; |
255 | 248 |
|
256 | | - m_tickScheduled = true; |
| 249 | + if (!g_pCompositor->m_sessionActive || !g_pHookSystem || g_pCompositor->m_unsafeState || |
| 250 | + !std::ranges::any_of(g_pCompositor->m_monitors, [](const auto& mon) { return mon->m_enabled && mon->m_output; })) |
| 251 | + return; |
257 | 252 |
|
258 | | - const auto PMOSTHZ = g_pHyprRenderer->m_mostHzMonitor; |
| 253 | + if (!m_lastTickValid || m_lastTickTimer.getMillis() >= 1.0f) { |
| 254 | + m_lastTickTimer.reset(); |
| 255 | + m_lastTickValid = true; |
259 | 256 |
|
260 | | - if (!PMOSTHZ) { |
261 | | - m_animationTimer->updateTimeout(std::chrono::milliseconds(16)); |
262 | | - return; |
| 257 | + tick(); |
| 258 | + EMIT_HOOK_EVENT("tick", nullptr); |
263 | 259 | } |
264 | 260 |
|
265 | | - float refreshDelayMs = std::floor(1000.f / PMOSTHZ->m_refreshRate); |
| 261 | + if (shouldTickForNext()) |
| 262 | + scheduleTick(); |
| 263 | +} |
266 | 264 |
|
267 | | - const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(Time::steadyNow() - PMOSTHZ->m_lastPresentationTimer.chrono()).count() / 1000.F; |
| 265 | +void CHyprAnimationManager::scheduleTick() { |
| 266 | + if (m_tickScheduled) |
| 267 | + return; |
268 | 268 |
|
269 | | - const auto TOPRES = std::clamp(refreshDelayMs - SINCEPRES, 1.1f, 1000.f); // we can't send 0, that will disarm it |
| 269 | + m_tickScheduled = true; |
| 270 | + |
| 271 | + if (!m_animationTimer || !g_pEventLoopManager) { |
| 272 | + m_tickScheduled = false; |
| 273 | + return; |
| 274 | + } |
270 | 275 |
|
271 | | - m_animationTimer->updateTimeout(std::chrono::milliseconds(sc<int>(std::floor(TOPRES)))); |
| 276 | + m_animationTimer->updateTimeout(std::chrono::milliseconds(1)); |
272 | 277 | } |
273 | 278 |
|
274 | 279 | void CHyprAnimationManager::onTicked() { |
|
0 commit comments