mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore+LibGUI: Remove GEventLoop and use CEventLoop everywhere
GEventLoop was just a dummy subclass of CEventLoop anyway. The only thing it actually did was make sure a GWindowServerConnectionw was instantiated. We now take care of that in GApplication instead. CEventLoop is now non-virtual and a little less confusing. :^)
This commit is contained in:
parent
edac8704de
commit
34d0e96aec
Notes:
sideshowbarker
2024-07-19 12:00:10 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/34d0e96aec8
12 changed files with 23 additions and 42 deletions
|
@ -37,8 +37,8 @@ int main(int argc, char** argv)
|
||||||
u8 buffer[4096];
|
u8 buffer[4096];
|
||||||
piano_widget->fill_audio_buffer(buffer, sizeof(buffer));
|
piano_widget->fill_audio_buffer(buffer, sizeof(buffer));
|
||||||
audio->write(buffer, sizeof(buffer));
|
audio->write(buffer, sizeof(buffer));
|
||||||
GEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0));
|
CEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0));
|
||||||
GEventLoop::wake();
|
CEventLoop::wake();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sound_thread.start();
|
sound_thread.start();
|
||||||
|
|
|
@ -181,6 +181,7 @@ CEventLoop& CEventLoop::current()
|
||||||
|
|
||||||
void CEventLoop::quit(int code)
|
void CEventLoop::quit(int code)
|
||||||
{
|
{
|
||||||
|
dbg() << "CEventLoop::quit(" << code << ")";
|
||||||
m_exit_requested = true;
|
m_exit_requested = true;
|
||||||
m_exit_code = code;
|
m_exit_code = code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class CNotifier;
|
||||||
class CEventLoop {
|
class CEventLoop {
|
||||||
public:
|
public:
|
||||||
CEventLoop();
|
CEventLoop();
|
||||||
virtual ~CEventLoop();
|
~CEventLoop();
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ GApplication::GApplication(int argc, char** argv)
|
||||||
(void)argv;
|
(void)argv;
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = this;
|
s_the = this;
|
||||||
m_event_loop = make<GEventLoop>();
|
m_event_loop = make<CEventLoop>();
|
||||||
|
GWindowServerConnection::the();
|
||||||
}
|
}
|
||||||
|
|
||||||
GApplication::~GApplication()
|
GApplication::~GApplication()
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <LibGUI/GShortcut.h>
|
#include <LibGUI/GShortcut.h>
|
||||||
|
|
||||||
|
class CEventLoop;
|
||||||
class GAction;
|
class GAction;
|
||||||
class GEventLoop;
|
|
||||||
class GKeyEvent;
|
class GKeyEvent;
|
||||||
class GMenuBar;
|
class GMenuBar;
|
||||||
class GWindow;
|
class GWindow;
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
void did_delete_last_window(Badge<GWindow>);
|
void did_delete_last_window(Badge<GWindow>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OwnPtr<GEventLoop> m_event_loop;
|
OwnPtr<CEventLoop> m_event_loop;
|
||||||
OwnPtr<GMenuBar> m_menubar;
|
OwnPtr<GMenuBar> m_menubar;
|
||||||
HashMap<GShortcut, GAction*> m_global_shortcut_actions;
|
HashMap<GShortcut, GAction*> m_global_shortcut_actions;
|
||||||
class TooltipWindow;
|
class TooltipWindow;
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
#include <LibGUI/GDesktop.h>
|
#include <LibGUI/GDesktop.h>
|
||||||
#include <LibGUI/GDialog.h>
|
#include <LibGUI/GDialog.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
|
||||||
|
|
||||||
GDialog::GDialog(CObject* parent)
|
GDialog::GDialog(CObject* parent)
|
||||||
: GWindow(parent)
|
: GWindow(parent)
|
||||||
{
|
{
|
||||||
set_modal(true);
|
set_modal(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GDialog::~GDialog()
|
GDialog::~GDialog()
|
||||||
|
@ -16,7 +14,7 @@ GDialog::~GDialog()
|
||||||
int GDialog::exec()
|
int GDialog::exec()
|
||||||
{
|
{
|
||||||
ASSERT(!m_event_loop);
|
ASSERT(!m_event_loop);
|
||||||
m_event_loop = make<GEventLoop>();
|
m_event_loop = make<CEventLoop>();
|
||||||
auto new_rect = rect();
|
auto new_rect = rect();
|
||||||
if (parent() && parent()->is_window()) {
|
if (parent() && parent()->is_window()) {
|
||||||
auto& parent_window = *static_cast<GWindow*>(parent());
|
auto& parent_window = *static_cast<GWindow*>(parent());
|
||||||
|
@ -47,4 +45,3 @@ void GDialog::close()
|
||||||
GWindow::close();
|
GWindow::close();
|
||||||
m_event_loop->quit(ExecCancel);
|
m_event_loop->quit(ExecCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibCore/CEventLoop.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
|
|
||||||
class GDialog : public GWindow {
|
class GDialog : public GWindow {
|
||||||
|
@ -25,6 +25,6 @@ protected:
|
||||||
explicit GDialog(CObject* parent);
|
explicit GDialog(CObject* parent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OwnPtr<GEventLoop> m_event_loop;
|
OwnPtr<CEventLoop> m_event_loop;
|
||||||
int m_result { ExecAborted };
|
int m_result { ExecAborted };
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,17 +43,6 @@ void GWindowServerConnection::handshake()
|
||||||
handle_greeting(response);
|
handle_greeting(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
GEventLoop::GEventLoop()
|
|
||||||
{
|
|
||||||
// ensure the WS connection is up, as our users might be expecting it to be
|
|
||||||
// valid very early (via e.g. GDesktop) :)
|
|
||||||
GWindowServerConnection::the();
|
|
||||||
}
|
|
||||||
|
|
||||||
GEventLoop::~GEventLoop()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GWindowServerConnection::handle_paint_event(const WSAPI_ServerMessage& event, GWindow& window, const ByteBuffer& extra_data)
|
void GWindowServerConnection::handle_paint_event(const WSAPI_ServerMessage& event, GWindow& window, const ByteBuffer& extra_data)
|
||||||
{
|
{
|
||||||
#ifdef GEVENTLOOP_DEBUG
|
#ifdef GEVENTLOOP_DEBUG
|
||||||
|
|
|
@ -33,14 +33,3 @@ private:
|
||||||
void handle_wm_event(const WSAPI_ServerMessage&, GWindow&);
|
void handle_wm_event(const WSAPI_ServerMessage&, GWindow&);
|
||||||
void handle_greeting(WSAPI_ServerMessage&);
|
void handle_greeting(WSAPI_ServerMessage&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class GEventLoop final : public CEventLoop {
|
|
||||||
public:
|
|
||||||
GEventLoop();
|
|
||||||
virtual ~GEventLoop() override;
|
|
||||||
|
|
||||||
static GEventLoop& current() { return static_cast<GEventLoop&>(CEventLoop::current()); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void process_unprocessed_bundles();
|
|
||||||
};
|
|
||||||
|
|
|
@ -497,12 +497,12 @@ void GWindow::set_focused_widget(GWidget* widget)
|
||||||
if (m_focused_widget == widget)
|
if (m_focused_widget == widget)
|
||||||
return;
|
return;
|
||||||
if (m_focused_widget) {
|
if (m_focused_widget) {
|
||||||
GEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusOut));
|
CEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusOut));
|
||||||
m_focused_widget->update();
|
m_focused_widget->update();
|
||||||
}
|
}
|
||||||
m_focused_widget = widget ? widget->make_weak_ptr() : nullptr;
|
m_focused_widget = widget ? widget->make_weak_ptr() : nullptr;
|
||||||
if (m_focused_widget) {
|
if (m_focused_widget) {
|
||||||
GEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusIn));
|
CEventLoop::current().post_event(*m_focused_widget, make<GEvent>(GEvent::FocusIn));
|
||||||
m_focused_widget->update();
|
m_focused_widget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -567,12 +567,12 @@ void GWindow::set_hovered_widget(GWidget* widget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_hovered_widget)
|
if (m_hovered_widget)
|
||||||
GEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Leave));
|
CEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Leave));
|
||||||
|
|
||||||
m_hovered_widget = widget ? widget->make_weak_ptr() : nullptr;
|
m_hovered_widget = widget ? widget->make_weak_ptr() : nullptr;
|
||||||
|
|
||||||
if (m_hovered_widget)
|
if (m_hovered_widget)
|
||||||
GEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Enter));
|
CEventLoop::current().post_event(*m_hovered_widget, make<GEvent>(GEvent::Enter));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWindow::set_current_backing_bitmap(GraphicsBitmap& bitmap, bool flush_immediately)
|
void GWindow::set_current_backing_bitmap(GraphicsBitmap& bitmap, bool flush_immediately)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <LibCore/CEventLoop.h>
|
||||||
#include <LibCore/CFile.h>
|
#include <LibCore/CFile.h>
|
||||||
#include <LibGUI/GClipboard.h>
|
#include <LibGUI/GClipboard.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
String data;
|
String data;
|
||||||
|
@ -86,7 +88,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Options options = parse_options(argc, argv);
|
Options options = parse_options(argc, argv);
|
||||||
|
|
||||||
new GEventLoop;
|
CEventLoop loop;
|
||||||
|
|
||||||
GClipboard& clipboard = GClipboard::the();
|
GClipboard& clipboard = GClipboard::the();
|
||||||
clipboard.set_data(options.data, options.type);
|
clipboard.set_data(options.data, options.type);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <LibCore/CEventLoop.h>
|
||||||
#include <LibGUI/GClipboard.h>
|
#include <LibGUI/GClipboard.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
bool print_type { false };
|
bool print_type { false };
|
||||||
|
@ -62,7 +64,7 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Options options = parse_options(argc, argv);
|
Options options = parse_options(argc, argv);
|
||||||
|
|
||||||
new GEventLoop;
|
CEventLoop loop;
|
||||||
|
|
||||||
GClipboard& clipboard = GClipboard::the();
|
GClipboard& clipboard = GClipboard::the();
|
||||||
auto data_and_type = clipboard.data_and_type();
|
auto data_and_type = clipboard.data_and_type();
|
||||||
|
|
Loading…
Reference in a new issue