diff --git a/src/libs/utils/processhandle.cpp b/src/libs/utils/processhandle.cpp index 5ce2571463ad363291df3b907e579a1a3f9a29f9..51e231b957dabdfd8d4ea59cb5b79b847d00118d 100644 --- a/src/libs/utils/processhandle.cpp +++ b/src/libs/utils/processhandle.cpp @@ -68,4 +68,11 @@ bool ProcessHandle::equals(const ProcessHandle &rhs) const return m_pid == rhs.m_pid; } +#ifndef Q_OS_MACOS +bool ProcessHandle::activate() +{ + return false; +} +#endif + } // Utils diff --git a/src/libs/utils/processhandle.h b/src/libs/utils/processhandle.h index bbd942b875023ba117af3c180f85c692d13fbd9c..7b5bb6392387b55b4a7e7336bdaa8baeddc544cb 100644 --- a/src/libs/utils/processhandle.h +++ b/src/libs/utils/processhandle.h @@ -43,6 +43,8 @@ public: bool equals(const ProcessHandle &) const; + bool activate(); + private: qint64 m_pid; }; diff --git a/src/libs/utils/processhandle_mac.mm b/src/libs/utils/processhandle_mac.mm new file mode 100644 index 0000000000000000000000000000000000000000..adc39e24d376fa2a3b37ade006bf7340dea73fbf --- /dev/null +++ b/src/libs/utils/processhandle_mac.mm @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "processhandle.h" +#import + +namespace Utils { + +bool ProcessHandle::activate() +{ + NSRunningApplication *app = [NSRunningApplication + runningApplicationWithProcessIdentifier:pid()]; + return app && [app activateWithOptions:static_cast( + NSApplicationActivateIgnoringOtherApps)]; +} + +} // Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index a20a41d1596a8b4aaffc25d67a8b63859dd82dd3..bfc9d6084e1274285ad805bd0a7ecbf03822eed9 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -252,8 +252,9 @@ osx { HEADERS += \ $$PWD/fileutils_mac.h OBJECTIVE_SOURCES += \ - $$PWD/fileutils_mac.mm - LIBS += -framework Foundation + $$PWD/fileutils_mac.mm \ + $$PWD/processhandle_mac.mm + LIBS += -framework Foundation -framework AppKit } include(mimetypes/mimetypes.pri) diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 03a47ae060a3b55a9859c8e827e6749d7a9665a0..559129df1642abaabc97e512760cc92158abdde8 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -30,7 +30,7 @@ Project { Properties { condition: qbs.targetOS.contains("macos") - cpp.frameworks: ["Foundation"] + cpp.frameworks: ["Foundation", "AppKit"] } Depends { name: "Qt"; submodules: ["concurrent", "network", "qml", "widgets"] } @@ -297,6 +297,14 @@ Project { ] } + Group { + name: "ProcessHandle_macos" + condition: qbs.targetOS.contains("macos") + files: [ + "processhandle_mac.mm", + ] + } + Group { name: "MimeTypes" prefix: "mimetypes/" diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 31987ee6ee06a365b11a74861f9728b760393749..21d97fb2c2706a23b3ace24545c26d2b98742e94 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -330,8 +330,6 @@ journald { LIBS += -lsystemd } -macx:LIBS += -framework Carbon - RESOURCES += projectexplorer.qrc # Some way to override the architecture used in Abi: diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index f61ab5a221a2456a402805be0b8fb64fba240994..47bc9d3947803ed7fd40cd1f505daead4dba5741 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -15,10 +15,6 @@ Project { Depends { name: "TextEditor" } cpp.defines: base.concat("QTC_CPU=X86Architecture") - Properties { - condition: qbs.targetOS.contains("macos") - cpp.frameworks: base.concat(["Carbon"]) - } Group { name: "General" diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 1f4b9eee23d73804e22759ebb1f3faa5d16b1d65..ab597a98fbd948669ad3b13d7d2f45747dfea76b 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -704,11 +704,6 @@ public: RunControlState state = RunControlState::Initialized; QList> m_workers; - -#ifdef Q_OS_OSX - // This is used to bring apps in the foreground on Mac - int foregroundCount; -#endif }; } // Internal @@ -1242,25 +1237,7 @@ void RunControlPrivate::debugMessage(const QString &msg) */ void RunControl::bringApplicationToForeground() { -#ifdef Q_OS_OSX - d->foregroundCount = 0; - bringApplicationToForegroundInternal(); -#endif -} - -void RunControl::bringApplicationToForegroundInternal() -{ -#ifdef Q_OS_OSX - ProcessSerialNumber psn; - GetProcessForPID(d->applicationProcessHandle.pid(), &psn); - if (SetFrontProcess(&psn) == procNotFound && d->foregroundCount < 15) { - // somehow the mac/carbon api says - // "-600 no eligible process with specified process id" - // if we call SetFrontProcess too early - ++d->foregroundCount; - QTimer::singleShot(200, this, &RunControl::bringApplicationToForegroundInternal); - } -#endif + d->applicationProcessHandle.activate(); } void RunControl::appendMessage(const QString &msg, Utils::OutputFormat format) diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index 08efd90f097b7909d8a1a7bfc8a19bf9e6d1d562..31c0e88692a8cf9e01b726e5ff241a0af868b3a9 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -488,7 +488,6 @@ private: friend class Internal::RunWorkerPrivate; static void addWorkerFactory(const WorkerFactory &workerFactory); - void bringApplicationToForegroundInternal(); Internal::RunControlPrivate *d; };