From 0426149580feaca188c7f34b268411ffeb8787b0 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Tue, 24 May 2022 13:35:01 +0800 Subject: [PATCH 1/4] standard macOS app behavior --- launcher/Application.cpp | 24 ++++++++++++++++++++++++ launcher/Application.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ba4096b6..bcfdc460 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -871,6 +871,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_mcedit.reset(new MCEditTool(m_settings)); } + connect(this, &Application::clickedOnDock, [this]() { + this->showMainWindow(); + }); + connect(this, &Application::aboutToQuit, [this](){ if(m_instances) { @@ -954,6 +958,22 @@ bool Application::createSetupWizard() return false; } +bool Application::event(QEvent* event) { +#ifdef Q_OS_MACOS + if (event->type() == QEvent::ApplicationStateChange) { + auto ev = static_cast(event); + + if (m_prevAppState == Qt::ApplicationActive + && ev->applicationState() == Qt::ApplicationActive) { + qDebug() << "Clicked on dock!"; + emit clickedOnDock(); + } + m_prevAppState = ev->applicationState(); + } +#endif + return QApplication::event(event); +} + void Application::setupWizardFinished(int status) { qDebug() << "Wizard result =" << status; @@ -1284,6 +1304,10 @@ void Application::subRunningInstance() bool Application::shouldExitNow() const { +#ifdef Q_OS_MACOS + return false; +#endif + return m_runningInstances == 0 && m_openWindows == 0; } diff --git a/launcher/Application.h b/launcher/Application.h index 3129b4fb..d6a5473d 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -94,6 +94,8 @@ public: Application(int &argc, char **argv); virtual ~Application(); + bool event(QEvent* event) override; + std::shared_ptr settings() const { return m_settings; } @@ -180,6 +182,7 @@ signals: void updateAllowedChanged(bool status); void globalSettingsAboutToOpen(); void globalSettingsClosed(); + void clickedOnDock(); public slots: bool launch( @@ -238,6 +241,10 @@ private: QString m_rootPath; Status m_status = Application::StartingUp; +#ifdef Q_OS_MACOS + Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive; +#endif + #if defined Q_OS_WIN32 // used on Windows to attach the standard IO streams bool consoleAttached = false; From 9673dac22b0ff81a54847d5db5438c099a6df587 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Tue, 24 May 2022 16:18:02 +0800 Subject: [PATCH 2/4] add more `#ifdef`s --- launcher/Application.cpp | 2 ++ launcher/Application.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index bcfdc460..ff0f2129 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -871,9 +871,11 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_mcedit.reset(new MCEditTool(m_settings)); } +#ifdef Q_OS_MACOS connect(this, &Application::clickedOnDock, [this]() { this->showMainWindow(); }); +#endif connect(this, &Application::aboutToQuit, [this](){ if(m_instances) diff --git a/launcher/Application.h b/launcher/Application.h index d6a5473d..686137ec 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -182,7 +182,10 @@ signals: void updateAllowedChanged(bool status); void globalSettingsAboutToOpen(); void globalSettingsClosed(); + +#ifdef Q_OS_MACOS void clickedOnDock(); +#endif public slots: bool launch( From 529fb07b4200b5dada2a8eec2953b29fc535ec7d Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Fri, 10 Jun 2022 15:18:47 +0800 Subject: [PATCH 3/4] I changed my mind --- launcher/Application.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ff0f2129..29088c39 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1306,10 +1306,6 @@ void Application::subRunningInstance() bool Application::shouldExitNow() const { -#ifdef Q_OS_MACOS - return false; -#endif - return m_runningInstances == 0 && m_openWindows == 0; } From 13b03e7e503dacdb7a3251a9804c520aae641db0 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 12 Jun 2022 11:44:04 +0800 Subject: [PATCH 4/4] Update Application.cpp --- launcher/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 29088c39..dfa756d4 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -967,7 +967,6 @@ bool Application::event(QEvent* event) { if (m_prevAppState == Qt::ApplicationActive && ev->applicationState() == Qt::ApplicationActive) { - qDebug() << "Clicked on dock!"; emit clickedOnDock(); } m_prevAppState = ev->applicationState();