diff options
-rw-r--r-- | mkspecs/common/macx.conf | 3 | ||||
-rw-r--r-- | mkspecs/features/mac/default_post.prf | 15 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 31 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 82 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.mm | 28 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 13 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 2 |
7 files changed, 165 insertions, 9 deletions
diff --git a/mkspecs/common/macx.conf b/mkspecs/common/macx.conf index d61ad33351..889027ada5 100644 --- a/mkspecs/common/macx.conf +++ b/mkspecs/common/macx.conf @@ -7,7 +7,8 @@ QMAKE_MAC_SDK = macosx QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.12 QMAKE_APPLE_DEVICE_ARCHS = x86_64 -QT_MAC_SDK_VERSION_TESTED_WITH = 10.14 +QT_MAC_SDK_VERSION_MIN = 10.13 +QT_MAC_SDK_VERSION_MAX = 10.14 device.sdk = macosx device.target = device diff --git a/mkspecs/features/mac/default_post.prf b/mkspecs/features/mac/default_post.prf index ae17f076a3..5d3ab7ed6e 100644 --- a/mkspecs/features/mac/default_post.prf +++ b/mkspecs/features/mac/default_post.prf @@ -9,19 +9,22 @@ contains(TEMPLATE, .*app) { # Detect incompatible SDK versions - !versionAtLeast(QMAKE_MAC_SDK_VERSION, $$QT_MAC_SDK_VERSION): \ - warning("Qt requires at least version $$QT_MAC_SDK_VERSION of the platform SDK," \ + isEmpty(QT_MAC_SDK_VERSION_MIN): \ + QT_MAC_SDK_VERSION_MIN = $$QT_MAC_SDK_VERSION + + !versionAtLeast(QMAKE_MAC_SDK_VERSION, $$QT_MAC_SDK_VERSION_MIN): \ + warning("Qt requires at least version $$QT_MAC_SDK_VERSION_MIN of the platform SDK," \ "you're using $${QMAKE_MAC_SDK_VERSION}. Please upgrade.") - !isEmpty(QT_MAC_SDK_VERSION_TESTED_WITH) { + !isEmpty(QT_MAC_SDK_VERSION_MAX) { # For Qt developers only !isEmpty($$list($$(QT_MAC_SDK_NO_VERSION_CHECK))): \ CONFIG += sdk_no_version_check QMAKE_MAC_SDK_MAJOR_MINOR_VERSION = $$replace(QMAKE_MAC_SDK_VERSION, "(\d+)(\.\d+)(\.\d+)?", \1\2) - !sdk_no_version_check:!versionAtMost(QMAKE_MAC_SDK_MAJOR_MINOR_VERSION, $$QT_MAC_SDK_VERSION_TESTED_WITH) { - warning("Qt has only been tested with version $$QT_MAC_SDK_VERSION_TESTED_WITH"\ + !sdk_no_version_check:!versionAtMost(QMAKE_MAC_SDK_MAJOR_MINOR_VERSION, $$QT_MAC_SDK_VERSION_MAX) { + warning("Qt has only been tested with version $$QT_MAC_SDK_VERSION_MAX"\ "of the platform SDK, you're using $${QMAKE_MAC_SDK_MAJOR_MINOR_VERSION}.") warning("This is an unsupported configuration. You may experience build issues," \ "and by using") @@ -29,7 +32,7 @@ contains(TEMPLATE, .*app) { "that Qt has not been prepared for.") warning("Please downgrade the SDK you use to build your app to version" \ - "$$QT_MAC_SDK_VERSION_TESTED_WITH, or configure") + "$$QT_MAC_SDK_VERSION_MAX, or configure") warning("with CONFIG+=sdk_no_version_check when running qmake" \ "to silence this warning.") } diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 953bf331bb..69aa7937b6 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -52,6 +52,7 @@ // #include "qt_mac_p.h" #include <private/qguiapplication_p.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtGui/qpalette.h> #include <QtGui/qscreen.h> @@ -60,6 +61,8 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSView)); +struct mach_header; + QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQpaWindow) @@ -173,6 +176,34 @@ T qt_mac_resolveOption(const T &fallback, QWindow *window, const QByteArray &pro return fallback; } +// ------------------------------------------------------------------------- + +#if !defined(Q_PROCESSOR_X86_64) +#error "32-bit builds are not supported" +#endif + +class QMacVersion +{ +public: + enum VersionTarget { + ApplicationBinary, + QtLibraries + }; + + static QOperatingSystemVersion buildSDK(VersionTarget target = ApplicationBinary); + static QOperatingSystemVersion deploymentTarget(VersionTarget target = ApplicationBinary); + static QOperatingSystemVersion currentRuntime(); + +private: + QMacVersion() = default; + using VersionTuple = QPair<QOperatingSystemVersion, QOperatingSystemVersion>; + static VersionTuple versionsForImage(const mach_header *machHeader); + static VersionTuple applicationVersion(); + static VersionTuple libraryVersion(); +}; + +// ------------------------------------------------------------------------- + QT_END_NAMESPACE // @compatibility_alias doesn't work with protocols diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 0f5ddfa49a..36841c77ab 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -55,6 +55,9 @@ #include <algorithm> +#include <mach-o/dyld.h> +#include <dlfcn.h> + QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window"); @@ -368,6 +371,85 @@ QString qt_mac_removeAmpersandEscapes(QString s) return QPlatformTheme::removeMnemonics(s).trimmed(); } +// ------------------------------------------------------------------------- + +#if !defined(Q_PROCESSOR_X86_64) +#error "32-bit builds are not supported" +#endif + +QOperatingSystemVersion QMacVersion::buildSDK(VersionTarget target) +{ + switch (target) { + case ApplicationBinary: return applicationVersion().second; + case QtLibraries: return libraryVersion().second; + } + Q_UNREACHABLE(); +} + +QOperatingSystemVersion QMacVersion::deploymentTarget(VersionTarget target) +{ + switch (target) { + case ApplicationBinary: return applicationVersion().first; + case QtLibraries: return libraryVersion().first; + } + Q_UNREACHABLE(); +} + +QOperatingSystemVersion QMacVersion::currentRuntime() +{ + return QOperatingSystemVersion::current(); +} + +QMacVersion::VersionTuple QMacVersion::versionsForImage(const mach_header *machHeader) +{ + auto commandCursor = uintptr_t(machHeader) + sizeof(mach_header_64); + for (uint32_t i = 0; i < machHeader->ncmds; ++i) { + load_command *loadCommand = reinterpret_cast<load_command *>(commandCursor); + if (loadCommand->cmd == LC_VERSION_MIN_MACOSX) { + auto versionCommand = reinterpret_cast<version_min_command *>(loadCommand); + uint32_t dt = versionCommand->version; // Deployment target + uint32_t sdk = versionCommand->sdk; // Build SDK + return qMakePair( + QOperatingSystemVersion(QOperatingSystemVersion::MacOS, + dt >> 16 & 0xffff, dt >> 8 & 0xff, dt & 0xff), + QOperatingSystemVersion(QOperatingSystemVersion::MacOS, + sdk >> 16 & 0xffff, sdk >> 8 & 0xff, sdk & 0xff) + ); + } + commandCursor += loadCommand->cmdsize; + } + Q_ASSERT_X(false, "QCocoaIntegration", "Could not find version-min load command"); + Q_UNREACHABLE(); +} + +QMacVersion::VersionTuple QMacVersion::applicationVersion() +{ + static VersionTuple version = []() { + const mach_header *executableHeader = nullptr; + for (uint32_t i = 0; i < _dyld_image_count(); ++i) { + auto header = _dyld_get_image_header(i); + if (header->filetype == MH_EXECUTE) { + executableHeader = header; + break; + } + } + Q_ASSERT_X(executableHeader, "QCocoaIntegration", "Failed to resolve Mach-O header of executable"); + return versionsForImage(executableHeader); + }(); + return version; +} + +QMacVersion::VersionTuple QMacVersion::libraryVersion() +{ + static VersionTuple version = []() { + Dl_info cocoaPluginImage; + dladdr((const void *)&QMacVersion::libraryVersion, &cocoaPluginImage); + Q_ASSERT_X(cocoaPluginImage.dli_fbase, "QCocoaIntegration", "Failed to resolve Mach-O header of Cocoa plugin"); + return versionsForImage(static_cast<mach_header*>(cocoaPluginImage.dli_fbase)); + }(); + return version; +} + QT_END_NAMESPACE /*! \internal diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 612290c9bd..936fecf8de 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -79,6 +79,32 @@ static void initResources() QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcQpa, "qt.qpa", QtWarningMsg); + +static void logVersionInformation() +{ + if (!lcQpa().isInfoEnabled()) + return; + + auto osVersion = QMacVersion::currentRuntime(); + auto qtBuildSDK = QMacVersion::buildSDK(QMacVersion::QtLibraries); + auto qtDeploymentTarget = QMacVersion::deploymentTarget(QMacVersion::QtLibraries); + auto appBuildSDK = QMacVersion::buildSDK(QMacVersion::ApplicationBinary); + auto appDeploymentTarget = QMacVersion::deploymentTarget(QMacVersion::ApplicationBinary); + + qCInfo(lcQpa, "Loading macOS (Cocoa) platform plugin for Qt " QT_VERSION_STR ", running on macOS %d.%d.%d\n\n" \ + " Component SDK version Deployment target \n" \ + " ------------- ------------- -------------------\n" \ + " Qt " QT_VERSION_STR " %d.%d.%d %d.%d.%d\n" \ + " Application %d.%d.%d %d.%d.%d\n", + osVersion.majorVersion(), osVersion.minorVersion(), osVersion.microVersion(), + qtBuildSDK.majorVersion(), qtBuildSDK.minorVersion(), qtBuildSDK.microVersion(), + qtDeploymentTarget.majorVersion(), qtDeploymentTarget.minorVersion(), qtDeploymentTarget.microVersion(), + appBuildSDK.majorVersion(), appBuildSDK.minorVersion(), appBuildSDK.microVersion(), + appDeploymentTarget.majorVersion(), appDeploymentTarget.minorVersion(), appDeploymentTarget.microVersion()); +} + + class QCoreTextFontEngine; class QFontEngineFT; @@ -112,6 +138,8 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList) , mServices(new QCocoaServices) , mKeyboardMapper(new QCocoaKeyMapper) { + logVersionInformation(); + if (mInstance) qWarning("Creating multiple Cocoa platform integrations is not supported"); mInstance = this; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 98e48a8b70..1ce671941d 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -541,6 +541,12 @@ void QCocoaWindow::setWindowZoomButton(Qt::WindowFlags flags) void QCocoaWindow::setWindowFlags(Qt::WindowFlags flags) { + // Updating the window flags may affect the window's theme frame, which + // in the process retains and then autoreleases the NSWindow. To make + // sure this doesn't leave lingering releases when there is no pool in + // place (e.g. during main(), before exec), we add one locally here. + QMacAutoReleasePool pool; + if (!isContentView()) return; @@ -1372,11 +1378,14 @@ void QCocoaWindow::recreateWindowIfNeeded() if (m_windowModality != window()->modality()) recreateReason |= WindowModalityChanged; - const bool shouldBeContentView = !parentWindow && !isEmbeddedView; + Qt::WindowType type = window()->type(); + + const bool shouldBeContentView = !parentWindow + && !((type & Qt::SubWindow) == Qt::SubWindow) + && !isEmbeddedView; if (isContentView() != shouldBeContentView) recreateReason |= ContentViewChanged; - Qt::WindowType type = window()->type(); const bool isPanel = isContentView() && [m_view.window isKindOfClass:[QNSPanel class]]; const bool shouldBePanel = shouldBeContentView && ((type & Qt::Popup) == Qt::Popup || (type & Qt::Dialog) == Qt::Dialog); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index e56f6b13d8..70aab77a51 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -904,6 +904,8 @@ void QXcbWindow::doFocusOut() struct QtMotifWmHints { quint32 flags, functions, decorations; + qint32 input_mode; // unused + quint32 status; // unused }; enum { |