misc: make the last window closing not quit by default

This commit is contained in:
outfoxxed 2024-03-09 03:23:58 -08:00
parent 3789709820
commit 31365dd179
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 26 additions and 0 deletions

View file

@ -252,6 +252,7 @@ int main(int argc, char** argv) {
QQuickWindow::setDefaultAlphaBuffer(true); QQuickWindow::setDefaultAlphaBuffer(true);
auto root = RootWrapper(configFilePath); auto root = RootWrapper(configFilePath);
QGuiApplication::setQuitOnLastWindowClosed(false);
return QGuiApplication::exec(); return QGuiApplication::exec();
} }

View file

@ -20,6 +20,15 @@
#include "qmlscreen.hpp" #include "qmlscreen.hpp"
#include "rootwrapper.hpp" #include "rootwrapper.hpp"
QuickshellSettings::QuickshellSettings() {
QObject::connect(
static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT
&QGuiApplication::lastWindowClosed,
this,
&QuickshellSettings::lastWindowClosed
);
}
QuickshellSettings* QuickshellSettings::instance() { QuickshellSettings* QuickshellSettings::instance() {
static QuickshellSettings* instance = nullptr; // NOLINT static QuickshellSettings* instance = nullptr; // NOLINT
if (instance == nullptr) { if (instance == nullptr) {
@ -52,6 +61,7 @@ QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) {
// clang-format off // clang-format off
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::workingDirectoryChanged, this, &QuickshellGlobal::workingDirectoryChanged); QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::workingDirectoryChanged, this, &QuickshellGlobal::workingDirectoryChanged);
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &QuickshellGlobal::watchFilesChanged); QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::watchFilesChanged, this, &QuickshellGlobal::watchFilesChanged);
QObject::connect(QuickshellSettings::instance(), &QuickshellSettings::lastWindowClosed, this, &QuickshellGlobal::lastWindowClosed);
// clang-format on // clang-format on
auto* app = QCoreApplication::instance(); auto* app = QCoreApplication::instance();

View file

@ -26,16 +26,26 @@ class QuickshellSettings: public QObject {
QML_UNCREATABLE("singleton"); QML_UNCREATABLE("singleton");
public: public:
QuickshellSettings();
[[nodiscard]] QString workingDirectory() const; [[nodiscard]] QString workingDirectory() const;
void setWorkingDirectory(QString workingDirectory); void setWorkingDirectory(QString workingDirectory);
[[nodiscard]] bool watchFiles() const; [[nodiscard]] bool watchFiles() const;
void setWatchFiles(bool watchFiles); void setWatchFiles(bool watchFiles);
[[nodiscard]] bool quitOnLastClosed() const;
void setQuitOnLastClosed(bool exitOnLastClosed);
static QuickshellSettings* instance(); static QuickshellSettings* instance();
static void reset(); static void reset();
signals: 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 workingDirectoryChanged();
void watchFilesChanged(); void watchFilesChanged();
@ -105,6 +115,11 @@ public:
void setWatchFiles(bool watchFiles); void setWatchFiles(bool watchFiles);
signals: 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 screensChanged();
void workingDirectoryChanged(); void workingDirectoryChanged();
void watchFilesChanged(); void watchFilesChanged();