diff --git a/LibCore/CTimer.cpp b/LibCore/CTimer.cpp index f78fa6a51c..cb479a1d18 100644 --- a/LibCore/CTimer.cpp +++ b/LibCore/CTimer.cpp @@ -5,6 +5,13 @@ CTimer::CTimer(CObject* parent) { } +CTimer::CTimer(int interval, Function&& timeout_handler, CObject* parent) + : CObject(parent) + , on_timeout(move(timeout_handler)) +{ + start(interval); +} + CTimer::~CTimer() { } @@ -18,6 +25,7 @@ void CTimer::start(int interval) { if (m_active) return; + m_interval = interval; start_timer(interval); m_active = true; } diff --git a/LibCore/CTimer.h b/LibCore/CTimer.h index 349917eae4..736b8c17e5 100644 --- a/LibCore/CTimer.h +++ b/LibCore/CTimer.h @@ -6,6 +6,7 @@ class CTimer final : public CObject { public: explicit CTimer(CObject* parent = nullptr); + CTimer(int interval, Function&& timeout_handler, CObject* parent = nullptr); virtual ~CTimer() override; void start(); diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index 9243745043..2e54589b0d 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -142,8 +142,7 @@ WSWindowManager::WSWindowManager() // NOTE: This ensures that the system menu has the correct dimensions. set_current_menubar(nullptr); - auto* timer = new CTimer; - timer->on_timeout = [this] { + new CTimer(300, [this] { static time_t last_update_time; time_t now = time(nullptr); if (now != last_update_time || m_cpu_monitor.is_dirty()) { @@ -151,8 +150,7 @@ WSWindowManager::WSWindowManager() last_update_time = now; m_cpu_monitor.set_dirty(false); } - }; - timer->start(300); + }); invalidate(); compose();