diff --git a/src/MainApplicationWindow.qml b/src/MainApplicationWindow.qml index d03d75d0..9dd2360b 100644 --- a/src/MainApplicationWindow.qml +++ b/src/MainApplicationWindow.qml @@ -150,6 +150,9 @@ ApplicationWindow { // layoutManager to handle as much as possible. layoutManager.restoreWindowSettings() } + if (Qt.platform.os.toString() === "osx") { + MainApplication.setEventFilter() + } // This will trigger `visible = true`. windowSettingsLoaded = true diff --git a/src/mainapplication.cpp b/src/mainapplication.cpp index 02616e98..4c9de1c3 100644 --- a/src/mainapplication.cpp +++ b/src/mainapplication.cpp @@ -445,3 +445,11 @@ MainApplication::cleanup() #endif QApplication::exit(0); } + +#ifdef Q_OS_MACOS +void +MainApplication::setEventFilter() +{ + installEventFilter(this); +} +#endif diff --git a/src/mainapplication.h b/src/mainapplication.h index 06597d3b..ab899d04 100644 --- a/src/mainapplication.h +++ b/src/mainapplication.h @@ -83,6 +83,18 @@ public: return runOptions_[opt]; }; +#ifdef Q_OS_MACOS + Q_INVOKABLE void setEventFilter(); + + bool eventFilter(QObject* object, QEvent* event) + { + if (event->type() == QEvent::ApplicationActivate) { + restoreApp(); + } + return QApplication::eventFilter(object, event); + } +#endif // Q_OS_MACOS + Q_SIGNALS: void closeRequested();