From 0ffae69bcaca623acc3efb3afc2c0def2aa67977 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sun, 4 Dec 2016 20:27:41 -0800 Subject: 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 --- src/app/config-ui/main.cpp | 9 --------- 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); } -- cgit v1.2.3