diff options
author | Jake Petroules <jake.petroules@qt.io> | 2016-12-04 20:27:41 -0800 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2016-12-05 10:42:17 +0000 |
commit | 0ffae69bcaca623acc3efb3afc2c0def2aa67977 (patch) | |
tree | b218f41b63d78c88187c2c09109a0a2bb5c1cbb6 | |
parent | bf31eeeb789572dd919f797b21cbab15758916ff (diff) |
macOS: Move foreground transformation code later in the lifetime cycle
This corrects an issue where the user sometimes needed to set focus on a
different application and then back to qbs-config-ui in order to access
the menu bar.
Change-Id: Idecddd99e477cbee29a2e7d4aa16aeaf428757f0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/app/config-ui/main.cpp | 9 | ||||
-rw-r--r-- | src/app/config-ui/mainwindow.cpp | 13 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/app/config-ui/main.cpp b/src/app/config-ui/main.cpp index 7ab2abd04..cec37baa0 100644 --- a/src/app/config-ui/main.cpp +++ b/src/app/config-ui/main.cpp @@ -49,8 +49,6 @@ using qbs::Internal::Tr; -extern "C" void qt_macos_forceTransformProcessToForegroundApplicationAndActivate(); - int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -67,13 +65,6 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - // Effectively delay the foreground process transformation from QApplication construction to - // just before UI is shown - this prevents the application icon from popping up in the Dock - // when running `qbs help`, and QCoreApplication::arguments() requires the application object - // to be constructed, so it is not easily worked around -#if defined(Q_OS_MACOS) || defined(Q_OS_OSX) - qt_macos_forceTransformProcessToForegroundApplicationAndActivate(); -#endif MainWindow mw(clParser.settingsDir()); mw.show(); return app.exec(); diff --git a/src/app/config-ui/mainwindow.cpp b/src/app/config-ui/mainwindow.cpp index 28e169b58..250e1c597 100644 --- a/src/app/config-ui/mainwindow.cpp +++ b/src/app/config-ui/mainwindow.cpp @@ -173,6 +173,8 @@ void MainWindow::provideContextMenu(const QPoint &pos) m_model->removeKey(index); } +extern "C" void qt_macos_forceTransformProcessToForegroundApplicationAndActivate(); + bool MainWindow::eventFilter(QObject *watched, QEvent *event) { if (ui->treeView->hasFocus() && event->type() == QEvent::KeyPress) { @@ -189,5 +191,16 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) } } + if (event->type() == QEvent::WindowActivate) { + // Effectively delay the foreground process transformation from QApplication construction to + // when the UI is shown - this prevents the application icon from popping up in the Dock + // when running `qbs help`, and QCoreApplication::arguments() requires the application + // object to be constructed, so it is not easily worked around + #if defined(Q_OS_MACOS) || defined(Q_OS_OSX) + qt_macos_forceTransformProcessToForegroundApplicationAndActivate(); + #endif + } + + return QMainWindow::eventFilter(watched, event); } |