mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 17:57:35 +00:00
LibCore: Add a convenience constructor for CTimer.
new CTimer(250, [] { thing_to_do_every_250_msec(); });
This commit is contained in:
parent
2af729a58a
commit
a3e8fc3d9c
3 changed files with 11 additions and 4 deletions
|
@ -5,6 +5,13 @@ CTimer::CTimer(CObject* parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTimer::CTimer(int interval, Function<void()>&& timeout_handler, CObject* parent)
|
||||||
|
: CObject(parent)
|
||||||
|
, on_timeout(move(timeout_handler))
|
||||||
|
{
|
||||||
|
start(interval);
|
||||||
|
}
|
||||||
|
|
||||||
CTimer::~CTimer()
|
CTimer::~CTimer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -18,6 +25,7 @@ void CTimer::start(int interval)
|
||||||
{
|
{
|
||||||
if (m_active)
|
if (m_active)
|
||||||
return;
|
return;
|
||||||
|
m_interval = interval;
|
||||||
start_timer(interval);
|
start_timer(interval);
|
||||||
m_active = true;
|
m_active = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
class CTimer final : public CObject {
|
class CTimer final : public CObject {
|
||||||
public:
|
public:
|
||||||
explicit CTimer(CObject* parent = nullptr);
|
explicit CTimer(CObject* parent = nullptr);
|
||||||
|
CTimer(int interval, Function<void()>&& timeout_handler, CObject* parent = nullptr);
|
||||||
virtual ~CTimer() override;
|
virtual ~CTimer() override;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
|
@ -142,8 +142,7 @@ WSWindowManager::WSWindowManager()
|
||||||
// NOTE: This ensures that the system menu has the correct dimensions.
|
// NOTE: This ensures that the system menu has the correct dimensions.
|
||||||
set_current_menubar(nullptr);
|
set_current_menubar(nullptr);
|
||||||
|
|
||||||
auto* timer = new CTimer;
|
new CTimer(300, [this] {
|
||||||
timer->on_timeout = [this] {
|
|
||||||
static time_t last_update_time;
|
static time_t last_update_time;
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
if (now != last_update_time || m_cpu_monitor.is_dirty()) {
|
if (now != last_update_time || m_cpu_monitor.is_dirty()) {
|
||||||
|
@ -151,8 +150,7 @@ WSWindowManager::WSWindowManager()
|
||||||
last_update_time = now;
|
last_update_time = now;
|
||||||
m_cpu_monitor.set_dirty(false);
|
m_cpu_monitor.set_dirty(false);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
timer->start(300);
|
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
compose();
|
compose();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue