From 31365dd179b8a7ca68df4a41ab3e839c20b8ee18 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 9 Mar 2024 03:23:58 -0800 Subject: [PATCH] misc: make the last window closing not quit by default --- src/core/main.cpp | 1 + src/core/qmlglobal.cpp | 10 ++++++++++ src/core/qmlglobal.hpp | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/core/main.cpp b/src/core/main.cpp index 7dd7af3..21732ee 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -252,6 +252,7 @@ int main(int argc, char** argv) { QQuickWindow::setDefaultAlphaBuffer(true); auto root = RootWrapper(configFilePath); + QGuiApplication::setQuitOnLastWindowClosed(false); return QGuiApplication::exec(); } diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index fc45217..0242d0e 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -20,6 +20,15 @@ #include "qmlscreen.hpp" #include "rootwrapper.hpp" +QuickshellSettings::QuickshellSettings() { + QObject::connect( + static_cast(QGuiApplication::instance()), // NOLINT + &QGuiApplication::lastWindowClosed, + this, + &QuickshellSettings::lastWindowClosed + ); +} + QuickshellSettings* QuickshellSettings::instance() { static QuickshellSettings* instance = nullptr; // NOLINT if (instance == nullptr) { @@ -52,6 +61,7 @@ QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) { // clang-format off QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::workingDirectoryChanged, this, &QuickshellGlobal::workingDirectoryChanged); QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &QuickshellGlobal::watchFilesChanged); + QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::lastWindowClosed, this, &QuickshellGlobal::lastWindowClosed); // clang-format on auto* app = QCoreApplication::instance(); diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 8dceea1..204ff03 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -26,16 +26,26 @@ class QuickshellSettings: public QObject { QML_UNCREATABLE("singleton"); public: + QuickshellSettings(); + [[nodiscard]] QString workingDirectory() const; void setWorkingDirectory(QString workingDirectory); [[nodiscard]] bool watchFiles() const; void setWatchFiles(bool watchFiles); + [[nodiscard]] bool quitOnLastClosed() const; + void setQuitOnLastClosed(bool exitOnLastClosed); + static QuickshellSettings* instance(); static void reset(); signals: + /// Sent when the last window is closed. + /// + /// To make the application exit when the last window is closed run `Qt.quit()`. + void lastWindowClosed(); + void workingDirectoryChanged(); void watchFilesChanged(); @@ -105,6 +115,11 @@ public: void setWatchFiles(bool watchFiles); signals: + /// Sent when the last window is closed. + /// + /// To make the application exit when the last window is closed run `Qt.quit()`. + void lastWindowClosed(); + void screensChanged(); void workingDirectoryChanged(); void watchFilesChanged();