mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-01 12:41:55 -07:00
eventloop: avoid duplicate timers
This commit is contained in:
@@ -100,7 +100,8 @@ void CEventLoopManager::enterLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::onTimerFire() {
|
void CEventLoopManager::onTimerFire() {
|
||||||
for (auto const& t : m_timers.timers) {
|
const auto CPY = m_timers.timers;
|
||||||
|
for (auto const& t : CPY) {
|
||||||
if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled())
|
if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled())
|
||||||
t->call(t);
|
t->call(t);
|
||||||
}
|
}
|
||||||
@@ -109,11 +110,15 @@ void CEventLoopManager::onTimerFire() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) {
|
void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) {
|
||||||
m_timers.timers.push_back(timer);
|
if (std::ranges::contains(m_timers.timers, timer))
|
||||||
|
return;
|
||||||
|
m_timers.timers.emplace_back(timer);
|
||||||
nudgeTimers();
|
nudgeTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) {
|
void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) {
|
||||||
|
if (!std::ranges::contains(m_timers.timers, timer))
|
||||||
|
return;
|
||||||
std::erase_if(m_timers.timers, [timer](const auto& t) { return timer == t; });
|
std::erase_if(m_timers.timers, [timer](const auto& t) { return timer == t; });
|
||||||
nudgeTimers();
|
nudgeTimers();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user