diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-06-21 17:11:35 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-07-27 12:58:41 +0000 |
commit | df62fdb51c2cd8746c0fe38b5af4b575cbc2bf00 (patch) | |
tree | 6a6a824d164ee47831882a58d3f6bc9442004132 | |
parent | 25170b324b7db872be2a2bde5c04eb0c1e3972e5 (diff) |
macOS: Add helper function to check whether we're running under Rosetta
As described in https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment?language=objc#Determine-Whether-Your-App-Is-Running-as-a-Translated-Binary
Pick-to: 6.2
Change-Id: I16fa4be20e4a55c87c2eb760d671d27ee4de1703
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | src/corelib/kernel/qcore_mac.mm | 10 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_mac_p.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index a4b8a4a628..435b2a6150 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -54,6 +54,7 @@ #include <cxxabi.h> #include <objc/runtime.h> #include <mach-o/dyld.h> +#include <sys/sysctl.h> #include <qdebug.h> @@ -366,6 +367,15 @@ bool qt_mac_applicationIsInDarkMode() #endif return false; } + +bool qt_mac_runningUnderRosetta() +{ + int translated = 0; + auto size = sizeof(translated); + if (sysctlbyname("sysctl.proc_translated", &translated, &size, nullptr, 0) == 0) + return translated; + return false; +} #endif bool qt_apple_isApplicationExtension() diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 7634ffb221..538ade3466 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -188,6 +188,7 @@ private: #ifdef Q_OS_MACOS Q_CORE_EXPORT bool qt_mac_applicationIsInDarkMode(); +Q_CORE_EXPORT bool qt_mac_runningUnderRosetta(); #endif #ifndef QT_NO_DEBUG_STREAM |