From 2d4ac408d75a9bc04585b22d04121e3d860713a1 Mon Sep 17 00:00:00 2001
From: kkostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Thu, 3 Feb 2022 17:16:47 -0500
Subject: [PATCH] UI: fix app opening from macOS dock

A single click on the app icon on macOS dock should
open the app.

Change-Id: Ied215ee9288d6d46fd8852a7daa996db7ac0468f
---
 src/MainApplicationWindow.qml |  3 +++
 src/mainapplication.cpp       |  8 ++++++++
 src/mainapplication.h         | 12 ++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/src/MainApplicationWindow.qml b/src/MainApplicationWindow.qml
index d03d75d08..9dd2360b3 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 02616e988..4c9de1c33 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 06597d3b3..ab899d047 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();
 
-- 
GitLab