[LyX/master] #11682 open new window on Mac if there is none and LyX is activated via dock
Stephan Witt
switt at lyx.org
Sun Feb 7 17:50:47 UTC 2021
commit 4d4dc96b0698de7368e0e63c7c27e1e5d7913a7f
Author: Stephan Witt <switt at lyx.org>
Date: Sun Feb 7 18:53:11 2021 +0100
#11682 open new window on Mac if there is none and LyX is activated via dock
---
src/frontends/qt/GuiApplication.cpp | 38 ++++++++++++++++++++++++++++++++++-
src/frontends/qt/GuiApplication.h | 4 +++
2 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 8160e39..625d85b 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -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();
}
diff --git a/src/frontends/qt/GuiApplication.h b/src/frontends/qt/GuiApplication.h
index 148d20f..8afdd7f 100644
--- a/src/frontends/qt/GuiApplication.h
+++ b/src/frontends/qt/GuiApplication.h
@@ -228,6 +228,10 @@ private Q_SLOTS:
void onLocaleChanged();
///
void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
+ ///
+#if (QT_VERSION >= 0x050100)
+ void onApplicationStateChanged(Qt::ApplicationState state);
+#endif
private:
///
More information about the lyx-cvs
mailing list