Serenity Operating System
1/*
2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#define AK_DONT_REPLACE_STD
8
9#include "EventLoopPluginQt.h"
10#include "TimerQt.h"
11#include <AK/Function.h>
12#include <AK/NonnullRefPtr.h>
13#include <QCoreApplication>
14#include <QTimer>
15
16namespace Ladybird {
17
18EventLoopPluginQt::EventLoopPluginQt() = default;
19EventLoopPluginQt::~EventLoopPluginQt() = default;
20
21void EventLoopPluginQt::spin_until(Function<bool()> goal_condition)
22{
23 while (!goal_condition())
24 QCoreApplication::processEvents(QEventLoop::ProcessEventsFlag::AllEvents | QEventLoop::ProcessEventsFlag::WaitForMoreEvents);
25}
26
27void EventLoopPluginQt::deferred_invoke(Function<void()> function)
28{
29 VERIFY(function);
30 QTimer::singleShot(0, [function = move(function)] {
31 function();
32 });
33}
34
35NonnullRefPtr<Web::Platform::Timer> EventLoopPluginQt::create_timer()
36{
37 return TimerQt::create();
38}
39
40void EventLoopPluginQt::quit()
41{
42 QCoreApplication::quit();
43}
44
45}