]> git.lyx.org Git - lyx.git/commitdiff
#11682 open new window on Mac if there is none and LyX is activated via dock
authorStephan Witt <switt@lyx.org>
Sun, 7 Feb 2021 17:53:11 +0000 (18:53 +0100)
committerStephan Witt <switt@lyx.org>
Sun, 7 Feb 2021 17:53:40 +0000 (18:53 +0100)
src/frontends/qt/GuiApplication.cpp
src/frontends/qt/GuiApplication.h

index 8160e39a4def3ad5039907865f79bd10b6b74607..625d85b3cbfc038e1f51d7ea208d9ecc56652627 100644 (file)
@@ -944,7 +944,7 @@ public:
 struct GuiApplication::Private
 {
        Private(): language_model_(nullptr), meta_fake_bit(NoModifier),
-               global_menubar_(nullptr)
+               global_menubar_(nullptr), last_state_(Qt::ApplicationInactive)
        {
        #if (QT_VERSION < 0x050000) || (QT_VERSION >= 0x050400)
        #if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
@@ -1011,6 +1011,8 @@ struct GuiApplication::Private
 
        /// Only used on mac.
        QMenuBar * global_menubar_;
+       /// Holds previous application state on Mac
+       Qt::ApplicationState last_state_;
 
 #ifdef Q_OS_MAC
        /// Linkback mime handler for MacOSX.
@@ -1084,6 +1086,10 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        setupApplescript();
        appleCleanupEditMenu();
        appleCleanupViewMenu();
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
+       connect(this, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
+                       this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
+#endif
 #endif
 
 #if defined(Q_WS_X11) || defined(QPA_XCB)
@@ -3293,6 +3299,36 @@ void GuiApplication::onLastWindowClosed()
 }
 
 
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
+void GuiApplication::onApplicationStateChanged(Qt::ApplicationState state)
+{
+       std::string name = "unknown";
+       switch (state) {
+       case Qt::ApplicationSuspended:
+               name = "ApplicationSuspended";
+               break;
+       case Qt::ApplicationHidden:
+               name = "ApplicationHidden";
+               break;
+       case Qt::ApplicationInactive:
+               name = "ApplicationInactive";
+               break;
+       case Qt::ApplicationActive:
+               name = "ApplicationActive";
+               /// The Dock icon click produces 2 sequential QEvent::ApplicationStateChangeEvent events.
+               /// cmd+tab only one QEvent::ApplicationStateChangeEvent event
+               if (d->views_.empty() && d->last_state_ == state) {
+                       LYXERR(Debug::GUI, "Open new window...");
+                       createView();
+               }
+               break;
+       }
+       LYXERR(Debug::GUI, "onApplicationStateChanged..." << name);
+       d->last_state_ = state;
+}
+#endif
+
+
 void GuiApplication::startLongOperation() {
        d->key_checker_.start();
 }
index 148d20f8dc24670d77fa4811602248db16daf23a..8afdd7f5640d32f80117352237e2471bea9456bc 100644 (file)
@@ -228,6 +228,10 @@ private Q_SLOTS:
        void onLocaleChanged();
        ///
        void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
+       ///
+#if (QT_VERSION >= 0x050100)
+       void onApplicationStateChanged(Qt::ApplicationState state);
+#endif
 
 private:
        ///