mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 15:15:08 +00:00

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.)
40 lines
850 B
C++
40 lines
850 B
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#define AK_DONT_REPLACE_STD
|
|
|
|
#include "EventLoopPluginQt.h"
|
|
#include "TimerQt.h"
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <QCoreApplication>
|
|
#include <QTimer>
|
|
|
|
namespace Ladybird {
|
|
|
|
EventLoopPluginQt::EventLoopPluginQt() = default;
|
|
EventLoopPluginQt::~EventLoopPluginQt() = default;
|
|
|
|
void EventLoopPluginQt::spin_until(Function<bool()> goal_condition)
|
|
{
|
|
while (!goal_condition())
|
|
QCoreApplication::processEvents();
|
|
}
|
|
|
|
void EventLoopPluginQt::deferred_invoke(Function<void()> function)
|
|
{
|
|
VERIFY(function);
|
|
QTimer::singleShot(0, [function = move(function)] {
|
|
function();
|
|
});
|
|
}
|
|
|
|
NonnullRefPtr<Web::Platform::Timer> EventLoopPluginQt::create_timer()
|
|
{
|
|
return TimerQt::create();
|
|
}
|
|
|
|
}
|