summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Costa <ucosty@gmail.com>2022-07-05 18:42:45 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commit7bf3010185323c93845bb072417a64a61c819a77 (patch)
tree9a2aaa7245d1da07f355b1c30764af494cd88473
parent95e3e06a1e70813f9ead9699c69f102dae739b7e (diff)
downloadserenity-7bf3010185323c93845bb072417a64a61c819a77.zip
Ladybird: Trigger browser to quit when the main window is closed
This patch adds an event handler to the main window which allows it to respond to a user closing the window. This event is then passed on to the LibCore event loop, which allows the application quit itself. Previously the application would hang, only running in the background, until killed by an external force.
-rw-r--r--Ladybird/BrowserWindow.cpp14
-rw-r--r--Ladybird/BrowserWindow.h6
-rw-r--r--Ladybird/main.cpp2
3 files changed, 19 insertions, 3 deletions
diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp
index d0eb5bcbed..769bc8042b 100644
--- a/Ladybird/BrowserWindow.cpp
+++ b/Ladybird/BrowserWindow.cpp
@@ -1,8 +1,10 @@
#include "BrowserWindow.h"
#include "WebView.h"
+#include <LibCore/EventLoop.h>
#include <QStatusBar>
-BrowserWindow::BrowserWindow()
+BrowserWindow::BrowserWindow(Core::EventLoop& event_loop)
+ : m_event_loop(event_loop)
{
m_toolbar = new QToolBar;
m_location_edit = new QLineEdit;
@@ -39,3 +41,13 @@ void BrowserWindow::page_favicon_changed(QIcon icon)
{
setWindowIcon(icon);
}
+
+void BrowserWindow::closeEvent(QCloseEvent* event)
+{
+ QWidget::closeEvent(event);
+
+ // FIXME: Ladybird only supports one window at the moment. When we support
+ // multiple windows, we'll only want to fire off the quit event when
+ // all of the browser windows have closed.
+ m_event_loop.quit(0);
+}
diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h
index 419716d971..80780d95b1 100644
--- a/Ladybird/BrowserWindow.h
+++ b/Ladybird/BrowserWindow.h
@@ -1,3 +1,4 @@
+#include <LibCore/Forward.h>
#include <QIcon>
#include <QLineEdit>
#include <QMainWindow>
@@ -10,10 +11,12 @@ class WebView;
class BrowserWindow : public QMainWindow {
Q_OBJECT
public:
- BrowserWindow();
+ explicit BrowserWindow(Core::EventLoop&);
WebView& view() { return *m_view; }
+ virtual void closeEvent(QCloseEvent*) override;
+
public slots:
void location_edit_return_pressed();
void page_title_changed(QString);
@@ -23,4 +26,5 @@ private:
QToolBar* m_toolbar { nullptr };
QLineEdit* m_location_edit { nullptr };
WebView* m_view { nullptr };
+ Core::EventLoop& m_event_loop;
};
diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp
index 6c6e9b157e..c5bb0dea9f 100644
--- a/Ladybird/main.cpp
+++ b/Ladybird/main.cpp
@@ -28,7 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::EventLoop event_loop;
QApplication app(arguments.argc, arguments.argv);
- BrowserWindow window;
+ BrowserWindow window(event_loop);
window.setWindowTitle("Ladybird");
window.resize(800, 600);
window.show();