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>
bb10
Tor Arne Vestbø 2021-06-21 17:11:35 +02:00
parent 25170b324b
commit df62fdb51c
2 changed files with 11 additions and 0 deletions

View File

@ -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()

View File

@ -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