mirror of
https://github.com/RGBCube/serenity
synced 2025-05-26 01:55:08 +00:00
Ladybird: Use only the Qt event loop to speed everything up :^)
This patch removes the dual-event-loop setup, leaving only the Qt event loop. We teach LibWeb how to drive Qt by installing an EventLoopPlugin. This removes the 50ms latency on all UI interactions (and network requests, etc.)
This commit is contained in:
parent
dcab11f5e9
commit
37d844fd66
9 changed files with 209 additions and 28 deletions
94
Ladybird/TimerQt.cpp
Normal file
94
Ladybird/TimerQt.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#define AK_DONT_REPLACE_STD
|
||||
|
||||
#include "TimerQt.h"
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
NonnullRefPtr<TimerQt> TimerQt::create()
|
||||
{
|
||||
return adopt_ref(*new TimerQt);
|
||||
}
|
||||
|
||||
TimerQt::TimerQt()
|
||||
{
|
||||
m_timer = new QTimer;
|
||||
QObject::connect(m_timer, &QTimer::timeout, [this] {
|
||||
if (on_timeout)
|
||||
on_timeout();
|
||||
});
|
||||
}
|
||||
|
||||
TimerQt::~TimerQt()
|
||||
{
|
||||
delete m_timer;
|
||||
}
|
||||
|
||||
void TimerQt::start()
|
||||
{
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
void TimerQt::start(int interval_ms)
|
||||
{
|
||||
m_timer->start(interval_ms);
|
||||
}
|
||||
|
||||
void TimerQt::restart()
|
||||
{
|
||||
restart(interval());
|
||||
}
|
||||
|
||||
void TimerQt::restart(int interval_ms)
|
||||
{
|
||||
if (is_active())
|
||||
stop();
|
||||
start(interval_ms);
|
||||
}
|
||||
|
||||
void TimerQt::stop()
|
||||
{
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
void TimerQt::set_active(bool active)
|
||||
{
|
||||
if (active)
|
||||
m_timer->start();
|
||||
else
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
bool TimerQt::is_active() const
|
||||
{
|
||||
return m_timer->isActive();
|
||||
}
|
||||
|
||||
int TimerQt::interval() const
|
||||
{
|
||||
return m_timer->interval();
|
||||
}
|
||||
|
||||
void TimerQt::set_interval(int interval_ms)
|
||||
{
|
||||
m_timer->setInterval(interval_ms);
|
||||
}
|
||||
|
||||
bool TimerQt::is_single_shot() const
|
||||
{
|
||||
return m_timer->isSingleShot();
|
||||
}
|
||||
|
||||
void TimerQt::set_single_shot(bool single_shot)
|
||||
{
|
||||
m_timer->setSingleShot(single_shot);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue