diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2022-06-12 10:46:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-12 10:46:49 +0200 |
commit | 91301ec7fe5c6d78d7143be3790bd0bbf8c93e91 (patch) | |
tree | 6e85d901f39cc9c66d0a775d9d2f7f170b14a743 | |
parent | 2bd8e7dca4aa55c836cb0bf33dc8d4be84fc938c (diff) | |
parent | 13b03e7e503dacdb7a3251a9804c520aae641db0 (diff) | |
download | PrismLauncher-91301ec7fe5c6d78d7143be3790bd0bbf8c93e91.tar.gz PrismLauncher-91301ec7fe5c6d78d7143be3790bd0bbf8c93e91.tar.bz2 PrismLauncher-91301ec7fe5c6d78d7143be3790bd0bbf8c93e91.zip |
Merge pull request #632 from ryanccn/macos-app-heuristic
-rw-r--r-- | launcher/Application.cpp | 21 | ||||
-rw-r--r-- | launcher/Application.h | 10 |
2 files changed, 31 insertions, 0 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a4525d83..4e0393c0 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -875,6 +875,12 @@ 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) { @@ -958,6 +964,21 @@ bool Application::createSetupWizard() return false; } +bool Application::event(QEvent* event) { +#ifdef Q_OS_MACOS + if (event->type() == QEvent::ApplicationStateChange) { + auto ev = static_cast<QApplicationStateChangeEvent*>(event); + + if (m_prevAppState == Qt::ApplicationActive + && ev->applicationState() == Qt::ApplicationActive) { + emit clickedOnDock(); + } + m_prevAppState = ev->applicationState(); + } +#endif + return QApplication::event(event); +} + void Application::setupWizardFinished(int status) { qDebug() << "Wizard result =" << status; diff --git a/launcher/Application.h b/launcher/Application.h index f440f433..e08e354a 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<SettingsObject> settings() const { return m_settings; } @@ -183,6 +185,10 @@ signals: void globalSettingsAboutToOpen(); void globalSettingsClosed(); +#ifdef Q_OS_MACOS + void clickedOnDock(); +#endif + public slots: bool launch( InstancePtr instance, @@ -240,6 +246,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; |