From 6ec5a97ebbf65a9283a57b8e5f4192e7ec84a759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 28 Nov 2019 17:46:34 +0100 Subject: macOS: Harden screen handling logic when reconfiguring displays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When connecting/disconnecting/reconfiguring screens Qt needs to know about the changes before they are propagated by the OS in other ways, so that we can reflect the changes in the list of QScreens as soon as they happen. Unfortunately the canonical notifications for this in AppKit, NSApplicationDidChangeScreenParametersNotification, is delivered after AppKit itself reacts to the change, which results in receiving NSWindowDidChangeScreenNotification, NSWindowWillMoveNotification, and others, while the list of QScreens is stale. To work around this we adopted the lower layer Quartz Display Services API in 3976df2805 to notify us when there are changes to the screen configuration. Unfortunately the window server on macOS is not consistent in how it orders events during screen reconfiguration, and we can't rely on the NSScreen list being up to date when we get our callbacks from Quartz. To work around this we still hook into Quartz, so that we get the callbacks as early as possible, but then track the state of the AppKit NSScreen list and update our own QScreens as soon as we see a change. We now also include sleeping displays in the list of QScreens, which matches the behavior of NSScreen.screens. Similarly we exclude displays that are mirroring another display. Task-number: QTBUG-80193 Change-Id: I6b1958d6ee61373b2861e05a0d971d2300596f3e Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoascreen.h | 21 ++- src/plugins/platforms/cocoa/qcocoascreen.mm | 272 +++++++++++++++++++++------- 2 files changed, 225 insertions(+), 68 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h index 7ec9a2b5af..dcf6f1c753 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.h +++ b/src/plugins/platforms/cocoa/qcocoascreen.h @@ -53,9 +53,6 @@ class QCocoaIntegration; class QCocoaScreen : public QPlatformScreen { public: - static void initializeScreens(); - static void cleanupScreens(); - ~QCocoaScreen(); // ---------------------------------------------------- @@ -79,7 +76,6 @@ public: // ---------------------------------------------------- NSScreen *nativeScreen() const; - void updateProperties(); void requestUpdate(); void deliverUpdateRequests(); @@ -88,6 +84,7 @@ public: static QCocoaScreen *primaryScreen(); static QCocoaScreen *get(NSScreen *nsScreen); static QCocoaScreen *get(CGDirectDisplayID displayId); + static QCocoaScreen *get(CFUUIDRef uuid); static CGPoint mapToNative(const QPointF &pos, QCocoaScreen *screen = QCocoaScreen::primaryScreen()); static CGRect mapToNative(const QRectF &rect, QCocoaScreen *screen = QCocoaScreen::primaryScreen()); @@ -95,11 +92,23 @@ public: static QRectF mapFromNative(CGRect rect, QCocoaScreen *screen = QCocoaScreen::primaryScreen()); private: - QCocoaScreen(CGDirectDisplayID displayId); + static void initializeScreens(); + static void updateScreens(); + static void cleanupScreens(); + + static bool updateScreensIfNeeded(); + static NSArray *s_screenConfigurationBeforeUpdate; + static void add(CGDirectDisplayID displayId); + QCocoaScreen(CGDirectDisplayID displayId); + void update(CGDirectDisplayID displayId); void remove(); + bool isOnline() const; + bool isMirroring() const; + CGDirectDisplayID m_displayId = kCGNullDirectDisplay; + CGDirectDisplayID displayId() const { return m_displayId; } QRect m_geometry; QRect m_availableGeometry; @@ -116,6 +125,8 @@ private: dispatch_source_t m_displayLinkSource = nullptr; QAtomicInt m_pendingUpdates; + friend class QCocoaIntegration; + friend class QCocoaWindow; friend QDebug operator<<(QDebug debug, const QCocoaScreen *screen); }; diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index bd5c95b9d0..e4dd4cf6c6 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE namespace CoreGraphics { Q_NAMESPACE enum DisplayChange { + ReconfiguredWithFlagsMissing = 0, Moved = kCGDisplayMovedFlag, SetMain = kCGDisplaySetMainFlag, SetMode = kCGDisplaySetModeFlag, @@ -71,73 +72,165 @@ namespace CoreGraphics { Q_ENUM_NS(DisplayChange) } +NSArray *QCocoaScreen::s_screenConfigurationBeforeUpdate = nil; + void QCocoaScreen::initializeScreens() { - uint32_t displayCount = 0; - if (CGGetActiveDisplayList(0, nullptr, &displayCount) != kCGErrorSuccess) - qFatal("Failed to get number of active displays"); - - CGDirectDisplayID activeDisplays[displayCount]; - if (CGGetActiveDisplayList(displayCount, &activeDisplays[0], &displayCount) != kCGErrorSuccess) - qFatal("Failed to get active displays"); - - for (CGDirectDisplayID displayId : activeDisplays) - QCocoaScreen::add(displayId); + updateScreens(); CGDisplayRegisterReconfigurationCallback([](CGDirectDisplayID displayId, CGDisplayChangeSummaryFlags flags, void *userInfo) { - if (flags & kCGDisplayBeginConfigurationFlag) - return; // Wait for changes to apply - Q_UNUSED(userInfo); - qCDebug(lcQpaScreen).verbosity(0).nospace() << "Display reconfiguration" - << " (" << QFlags(flags) << ")" - << " for displayId=" << displayId; - - QCocoaScreen *cocoaScreen = QCocoaScreen::get(displayId); + // Displays are reconfigured in batches, and we want to update our screens + // once a batch ends, so that all the states of the displays are up to date. + static int displayReconfigurationsInProgress = 0; + + const bool beforeReconfigure = flags & kCGDisplayBeginConfigurationFlag; + qCDebug(lcQpaScreen).verbosity(0).nospace() << "Display " << displayId + << (beforeReconfigure ? " about to reconfigure" : " was ") + << QFlags(flags) + << " with " << displayReconfigurationsInProgress + << " display configuration(s) in progress"; + + if (!flags) { + // CGDisplayRegisterReconfigurationCallback has been observed to be called + // with flags unset. This seems like a bug. The callback is not paired with + // a matching "completion" callback either, so we don't know whether to treat + // it as a begin or end of reconfigure. + return; + } - if ((flags & kCGDisplayAddFlag) || !cocoaScreen) { - if (!CGDisplayIsActive(displayId)) { - qCDebug(lcQpaScreen) << "Not adding inactive display" << displayId; - return; // Will be added when activated + if (beforeReconfigure) { + if (!displayReconfigurationsInProgress++) { + // There might have been a screen reconfigure before this that + // we didn't process yet, so do that now if that's the case. + updateScreensIfNeeded(); + + Q_ASSERT(!s_screenConfigurationBeforeUpdate); + s_screenConfigurationBeforeUpdate = NSScreen.screens; + qCDebug(lcQpaScreen, "Display reconfigure transaction started" + " with screen configuration %p", s_screenConfigurationBeforeUpdate); + + static void (^tryScreenUpdate)(); + tryScreenUpdate = ^void () { + qCDebug(lcQpaScreen) << "Attempting screen update from runloop block"; + if (!updateScreensIfNeeded()) + CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, tryScreenUpdate); + }; + CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, tryScreenUpdate); } - QCocoaScreen::add(displayId); - } else if ((flags & kCGDisplayRemoveFlag) || !CGDisplayIsActive(displayId)) { - cocoaScreen->remove(); } else { - // Detect changes to the primary screen immediately, instead of - // waiting for a display reconfigure with kCGDisplaySetMainFlag. - // This ensures that any property updates to the other screens - // will be in reference to the correct primary screen. - QCocoaScreen *mainDisplay = QCocoaScreen::get(CGMainDisplayID()); - if (QGuiApplication::primaryScreen()->handle() != mainDisplay) { - mainDisplay->updateProperties(); - qCInfo(lcQpaScreen) << "Primary screen changed to" << mainDisplay; - QWindowSystemInterface::handlePrimaryScreenChanged(mainDisplay); - if (cocoaScreen == mainDisplay) - return; // Already reconfigured - } + Q_ASSERT_X(displayReconfigurationsInProgress, "QCococaScreen", + "Display configuration transactions are expected to be balanced"); - cocoaScreen->updateProperties(); - qCInfo(lcQpaScreen).nospace() << "Reconfigured " << - (primaryScreen() == cocoaScreen ? "primary " : "") - << cocoaScreen; + if (!--displayReconfigurationsInProgress) { + qCDebug(lcQpaScreen) << "Display reconfigure transaction completed"; + // We optimistically update now, in case the NSScreens have changed + updateScreensIfNeeded(); + } } }, nullptr); + + static QMacNotificationObserver screenParameterObserver(NSApplication.sharedApplication, + NSApplicationDidChangeScreenParametersNotification, [&]() { + qCDebug(lcQpaScreen) << "Received screen parameter change notification"; + updateScreensIfNeeded(); // As a last resort we update screens here + }); +} + +bool QCocoaScreen::updateScreensIfNeeded() +{ + if (!s_screenConfigurationBeforeUpdate) { + qCDebug(lcQpaScreen) << "QScreens have already been updated, all good"; + return true; + } + + if (s_screenConfigurationBeforeUpdate == NSScreen.screens) { + qCDebug(lcQpaScreen) << "Still waiting for NSScreen configuration change"; + return false; + } + + qCDebug(lcQpaScreen, "NSScreen configuration changed to %p", NSScreen.screens); + updateScreens(); + + s_screenConfigurationBeforeUpdate = nil; + return true; +} + +/* + Update the list of available QScreens, and the properties of existing screens. + + At this point we rely on the NSScreen.screens to be up to date. +*/ +void QCocoaScreen::updateScreens() +{ + uint32_t displayCount = 0; + if (CGGetOnlineDisplayList(0, nullptr, &displayCount) != kCGErrorSuccess) + qFatal("Failed to get number of online displays"); + + QVector onlineDisplays(displayCount); + if (CGGetOnlineDisplayList(displayCount, onlineDisplays.data(), &displayCount) != kCGErrorSuccess) + qFatal("Failed to get online displays"); + + qCInfo(lcQpaScreen) << "Updating screens with" << displayCount + << "online displays:" << onlineDisplays; + + // TODO: Verify whether we can always assume the main display is first + int mainDisplayIndex = onlineDisplays.indexOf(CGMainDisplayID()); + if (mainDisplayIndex < 0) { + qCWarning(lcQpaScreen) << "Main display not in list of online displays!"; + } else if (mainDisplayIndex > 0) { + qCWarning(lcQpaScreen) << "Main display not first display, making sure it is"; + onlineDisplays.move(mainDisplayIndex, 0); + } + + for (CGDirectDisplayID displayId : onlineDisplays) { + Q_ASSERT(CGDisplayIsOnline(displayId)); + + if (CGDisplayMirrorsDisplay(displayId)) + continue; + + // A single physical screen can map to multiple displays IDs, + // depending on which GPU is in use or which physical port the + // screen is connected to. By mapping the display ID to a UUID, + // which are shared between displays that target the same screen, + // we can pick an existing QScreen to update instead of needlessly + // adding and removing QScreens. + QCFType uuid = CGDisplayCreateUUIDFromDisplayID(displayId); + Q_ASSERT(uuid); + + if (QCocoaScreen *existingScreen = QCocoaScreen::get(uuid)) { + existingScreen->update(displayId); + qCInfo(lcQpaScreen) << "Updated" << existingScreen; + if (CGDisplayIsMain(displayId) && existingScreen != qGuiApp->primaryScreen()->handle()) { + qCInfo(lcQpaScreen) << "Primary screen changed to" << existingScreen; + QWindowSystemInterface::handlePrimaryScreenChanged(existingScreen); + } + } else { + QCocoaScreen::add(displayId); + } + } + + for (QScreen *screen : QGuiApplication::screens()) { + QCocoaScreen *platformScreen = static_cast(screen->handle()); + if (!platformScreen->isOnline() || platformScreen->isMirroring()) + platformScreen->remove(); + } } void QCocoaScreen::add(CGDirectDisplayID displayId) { const bool isPrimary = CGDisplayIsMain(displayId); QCocoaScreen *cocoaScreen = new QCocoaScreen(displayId); - qCInfo(lcQpaScreen).nospace() << "Adding " << (isPrimary ? "new primary " : "") << cocoaScreen; + qCInfo(lcQpaScreen) << "Adding" << cocoaScreen + << (isPrimary ? "as new primary screen" : ""); QWindowSystemInterface::handleScreenAdded(cocoaScreen, isPrimary); } QCocoaScreen::QCocoaScreen(CGDirectDisplayID displayId) : QPlatformScreen(), m_displayId(displayId) { - updateProperties(); + update(m_displayId); m_cursor = new QCocoaCursor; } @@ -150,8 +243,6 @@ void QCocoaScreen::cleanupScreens() void QCocoaScreen::remove() { - m_displayId = kCGNullDirectDisplay; // Prevent stale references during removal - // This may result in the application responding to QGuiApplication::screenRemoved // by moving the window to another screen, either by setGeometry, or by setScreen. // If the window isn't moved by the application, Qt will as a fallback move it to @@ -163,7 +254,7 @@ void QCocoaScreen::remove() // QCocoaWindow::windowDidChangeScreen. At that point the window will appear to have // already changed its screen, but that's only true if comparing the Qt screens, // not when comparing the NSScreens. - qCInfo(lcQpaScreen).nospace() << "Removing " << (primaryScreen() == this ? "current primary " : "") << this; + qCInfo(lcQpaScreen) << "Removing " << this; QWindowSystemInterface::handleScreenRemoved(this); } @@ -210,9 +301,14 @@ static QString displayName(CGDirectDisplayID displayID) return QString(); } -void QCocoaScreen::updateProperties() +void QCocoaScreen::update(CGDirectDisplayID displayId) { - Q_ASSERT(m_displayId); + if (displayId != m_displayId) { + qCDebug(lcQpaScreen) << "Reconnecting" << this << "as display" << displayId; + m_displayId = displayId; + } + + Q_ASSERT(isOnline()); const QRect previousGeometry = m_geometry; const QRect previousAvailableGeometry = m_availableGeometry; @@ -350,8 +446,8 @@ struct DeferredDebugHelper void QCocoaScreen::deliverUpdateRequests() { - if (!m_displayId) - return; // Screen removed + if (!isOnline()) + return; QMacAutoReleasePool pool; @@ -562,6 +658,29 @@ QPixmap QCocoaScreen::grabWindow(WId view, int x, int y, int width, int height) return windowPixmap; } +bool QCocoaScreen::isOnline() const +{ + // When a display is disconnected CGDisplayIsOnline and other CGDisplay + // functions that take a displayId will not return false, but will start + // returning -1 to signal that the displayId is invalid. Some functions + // will also assert or even crash in this case, so it's important that + // we double check if a display is online before calling other functions. + auto isOnline = CGDisplayIsOnline(m_displayId); + static const uint32_t kCGDisplayIsDisconnected = int32_t(-1); + return isOnline != kCGDisplayIsDisconnected && isOnline; +} + +/* + Returns true if a screen is mirroring another screen +*/ +bool QCocoaScreen::isMirroring() const +{ + if (!isOnline()) + return false; + + return CGDisplayMirrorsDisplay(m_displayId); +} + /*! The screen used as a reference for global window geometry */ @@ -586,6 +705,12 @@ QList QCocoaScreen::virtualSiblings() const QCocoaScreen *QCocoaScreen::get(NSScreen *nsScreen) { + if (s_screenConfigurationBeforeUpdate) { + qCWarning(lcQpaScreen) << "Trying to resolve screen while waiting for screen reconfigure!"; + if (!updateScreensIfNeeded()) + qCWarning(lcQpaScreen) << "Failed to do last minute screen update. Expect crashes."; + } + return get(nsScreen.qt_displayId); } @@ -600,23 +725,34 @@ QCocoaScreen *QCocoaScreen::get(CGDirectDisplayID displayId) return nullptr; } +QCocoaScreen *QCocoaScreen::get(CFUUIDRef uuid) +{ + for (QScreen *screen : QGuiApplication::screens()) { + auto *platformScreen = static_cast(screen->handle()); + if (!platformScreen->isOnline()) + continue; + + auto displayId = platformScreen->displayId(); + QCFType candidateUuid(CGDisplayCreateUUIDFromDisplayID(displayId)); + Q_ASSERT(candidateUuid); + + if (candidateUuid == uuid) + return platformScreen; + } + + return nullptr; +} + NSScreen *QCocoaScreen::nativeScreen() const { if (!m_displayId) return nil; // The display has been disconnected - // A single display may have different displayIds depending on - // which GPU is in use or which physical port the display is - // connected to. By comparing UUIDs instead of display IDs we - // ensure that we always pick up the appropriate NSScreen. - QCFType uuid = CGDisplayCreateUUIDFromDisplayID(m_displayId); - - for (NSScreen *screen in [NSScreen screens]) { - if (QCFType(CGDisplayCreateUUIDFromDisplayID(screen.qt_displayId)) == uuid) + for (NSScreen *screen in NSScreen.screens) { + if (screen.qt_displayId == m_displayId) return screen; } - qCWarning(lcQpaScreen) << "Could not find NSScreen for display ID" << m_displayId; return nil; } @@ -651,11 +787,21 @@ QDebug operator<<(QDebug debug, const QCocoaScreen *screen) debug.nospace(); debug << "QCocoaScreen(" << (const void *)screen; if (screen) { - debug << ", geometry=" << screen->geometry(); + debug << ", " << screen->name(); + if (screen->isOnline()) { + if (CGDisplayIsAsleep(screen->displayId())) + debug << ", Sleeping"; + if (auto mirroring = CGDisplayMirrorsDisplay(screen->displayId())) + debug << ", mirroring=" << mirroring; + } else { + debug << ", Offline"; + } + debug << ", " << screen->geometry(); debug << ", dpr=" << screen->devicePixelRatio(); - debug << ", name=" << screen->name(); - debug << ", displayId=" << screen->m_displayId; - debug << ", native=" << screen->nativeScreen(); + debug << ", displayId=" << screen->displayId(); + + if (auto nativeScreen = screen->nativeScreen()) + debug << ", " << nativeScreen; } debug << ')'; return debug; -- cgit v1.2.3 From d027860201c55b686b9f8330c559f84799442d68 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 28 Nov 2019 18:36:48 +0200 Subject: Fix assets iterator - start from index -1 each time when we iterate. Each time when we add a FolderIterator to the stack we MUST reset the index (-1) otherwise it will continue from it's last position. To fix it we are cloning the FolderIterator to set the index to -1. The index must be -1 in order to set it to 0 when we first call next() method. - introduce "fileType" static method for a more reliable also much faster file type lookup. The old version of checking if a file exists, is a folder or a file was buggy that's why it skipped some file randomly. Fixes: QTBUG-80178 Change-Id: I4b28e4616399b1bff35d792b55ded1bf19b62dd9 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../android/qandroidassetsfileenginehandler.cpp | 70 +++++++++++++++++----- 1 file changed, 56 insertions(+), 14 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index 26e72a480f..3d16f96450 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -72,9 +72,10 @@ static inline QString prefixedPath(QString path) struct AssetItem { enum class Type { File, - Folder + Folder, + Invalid }; - + AssetItem() = default; AssetItem (const QString &rawName) : name(rawName) { @@ -92,21 +93,47 @@ using AssetItemList = QVector; class FolderIterator : public AssetItemList { public: - static QSharedPointer fromCache(const QString &path) + static QSharedPointer fromCache(const QString &path, bool clone) { QMutexLocker lock(&m_assetsCacheMutex); QSharedPointer *folder = m_assetsCache.object(path); if (!folder) { folder = new QSharedPointer{new FolderIterator{path}}; - if (!m_assetsCache.insert(path, folder)) { + if ((*folder)->empty() || !m_assetsCache.insert(path, folder)) { QSharedPointer res = *folder; delete folder; return res; } } - return *folder; + return clone ? QSharedPointer{new FolderIterator{*(*folder)}} : *folder; + } + + static AssetItem::Type fileType(const QString &filePath) + { + const QStringList paths = filePath.split(QLatin1Char('/')); + QString fullPath; + AssetItem::Type res = AssetItem::Type::Invalid; + for (const auto &path: paths) { + auto folder = fromCache(fullPath, false); + auto it = std::lower_bound(folder->begin(), folder->end(), AssetItem{path}, [](const AssetItem &val, const AssetItem &assetItem) { + return val.name < assetItem.name; + }); + if (it == folder->end() || it->name != path) + return AssetItem::Type::Invalid; + if (!fullPath.isEmpty()) + fullPath.append(QLatin1Char('/')); + fullPath += path; + res = it->type; + } + return res; } + FolderIterator(const FolderIterator &other) + : AssetItemList(other) + , m_index(-1) + , m_path(other.m_path) + {} + FolderIterator(const QString &path) : m_path(path) { @@ -118,8 +145,12 @@ public: QJNIEnvironmentPrivate env; jobjectArray jFiles = static_cast(files.object()); const jint nFiles = env->GetArrayLength(jFiles); - for (int i = 0; i < nFiles; ++i) - push_back({QJNIObjectPrivate(env->GetObjectArrayElement(jFiles, i)).toString()}); + for (int i = 0; i < nFiles; ++i) { + AssetItem item{QJNIObjectPrivate(env->GetObjectArrayElement(jFiles, i)).toString()}; + insert(std::upper_bound(begin(), end(), item, [](const auto &a, const auto &b){ + return a.name < b.name; + }), item); + } } m_path = assetsPrefix + QLatin1Char('/') + m_path + QLatin1Char('/'); m_path.replace(QLatin1String("//"), QLatin1String("/")); @@ -169,7 +200,7 @@ public: const QString &path) : QAbstractFileEngineIterator(filters, nameFilters) { - m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(path))); + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(path), true)); if (m_stack.last()->empty()) m_stack.pop_back(); } @@ -215,7 +246,7 @@ public: if (!res) return {}; if (res->second.type == AssetItem::Type::Folder) { - m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(currentFilePath()))); + m_stack.push_back(FolderIterator::fromCache(cleanedAssetPath(currentFilePath()), true)); if (m_stack.last()->empty()) m_stack.pop_back(); } @@ -305,12 +336,12 @@ public: FileFlags fileFlags(FileFlags type = FileInfoAll) const override { - FileFlags flags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); + FileFlags commonFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm|ExistsFlag); + FileFlags flags; if (m_assetFile) - flags |= FileType; + flags = FileType | commonFlags; else if (m_isFolder) - flags |= DirectoryType; - + flags = DirectoryType | commonFlags; return type & flags; } @@ -341,9 +372,20 @@ public: void setFileName(const QString &file) override { + if (m_fileName == cleanedAssetPath(file)) + return; close(); m_fileName = cleanedAssetPath(file); - m_isFolder = !open(QIODevice::ReadOnly) && !FolderIterator::fromCache(m_fileName)->empty(); + switch (FolderIterator::fileType(m_fileName)) { + case AssetItem::Type::File: + open(QIODevice::ReadOnly); + break; + case AssetItem::Type::Folder: + m_isFolder = true; + break; + case AssetItem::Type::Invalid: + break; + } } Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override -- cgit v1.2.3 From a966a7b7df18ebf7b92409b1199386df7f872b6c Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Tue, 3 Dec 2019 09:25:06 +0200 Subject: Initialize all variables Set m_isFolder = false also in "close" method Fixes: QTBUG-80468 Change-Id: I5449692d61d4d340e83bdca337b86e054e8bf561 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index 3d16f96450..fcc08ea00d 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -288,6 +288,7 @@ public: m_assetFile = 0; return true; } + m_isFolder = false; return false; } @@ -397,9 +398,9 @@ public: private: AAsset *m_assetFile = nullptr; - AAssetManager *m_assetManager; + AAssetManager *m_assetManager = nullptr; QString m_fileName; - bool m_isFolder; + bool m_isFolder = false; }; -- cgit v1.2.3 From 5a26bf9d65b75db3abefa967beb13b2510719bd5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 11 Dec 2019 09:30:26 +0100 Subject: Avoid initializing QFlags with 0 or nullptr in macOS-specific code It is being deprecated. Change-Id: If1b0b058140e197d41efae93025c4eefc2ed9bbd Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/cocoa/qcocoatheme.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index a00cbdfea3..50e56ef1bf 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -70,7 +70,7 @@ public: const QPalette *palette(Palette type = SystemPalette) const override; const QFont *font(Font type = SystemFont) const override; QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override; - QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = 0) const override; + QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = {}) const override; QVariant themeHint(ThemeHint hint) const override; QString standardButtonText(int button) const override; -- cgit v1.2.3 From e076965542148b8c2341fd4418733febbf9ae1ec Mon Sep 17 00:00:00 2001 From: James McDonnell Date: Fri, 16 Aug 2019 15:38:54 -0400 Subject: Move QQnxGLContext::ms_eglDisplay to the integration object In part, this is a continuation of https://codereview.qt-project.org/c/qt/qtbase/+/227953. It also paves the way toward implementing the EglDisplay integration resource needed by QtWayland. For the code that's being moved around and modified, switch from !QT_NO_OPENGL to QT_CONFIG(opengl). Change-Id: I5046e8caf5df7cf326f8e697d7d41cf802250414 Reviewed-by: Dan Cape Reviewed-by: Samuli Piippo --- src/plugins/platforms/qnx/qqnxglcontext.cpp | 27 ++----------------- src/plugins/platforms/qnx/qqnxglcontext.h | 7 ----- src/plugins/platforms/qnx/qqnxintegration.cpp | 37 ++++++++++++++++++++++----- src/plugins/platforms/qnx/qqnxintegration.h | 13 +++++++++- 4 files changed, 45 insertions(+), 39 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/qnx/qqnxglcontext.cpp b/src/plugins/platforms/qnx/qqnxglcontext.cpp index 1d030ba1aa..69391c4fec 100644 --- a/src/plugins/platforms/qnx/qqnxglcontext.cpp +++ b/src/plugins/platforms/qnx/qqnxglcontext.cpp @@ -58,8 +58,6 @@ QT_BEGIN_NAMESPACE -EGLDisplay QQnxGLContext::ms_eglDisplay = EGL_NO_DISPLAY; - static QEGLPlatformContext::Flags makeFlags() { QEGLPlatformContext::Flags result = 0; @@ -71,7 +69,8 @@ static QEGLPlatformContext::Flags makeFlags() } QQnxGLContext::QQnxGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share) - : QEGLPlatformContext(format, share, ms_eglDisplay, 0, QVariant(), makeFlags()) + : QEGLPlatformContext(format, share, QQnxIntegration::instance()->eglDisplay(), 0, QVariant(), + makeFlags()) { } @@ -79,28 +78,6 @@ QQnxGLContext::~QQnxGLContext() { } -void QQnxGLContext::initializeContext() -{ - qGLContextDebug(); - - // Initialize connection to EGL - ms_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (Q_UNLIKELY(ms_eglDisplay == EGL_NO_DISPLAY)) - qFatal("QQnxGLContext: failed to obtain EGL display: %x", eglGetError()); - - EGLBoolean eglResult = eglInitialize(ms_eglDisplay, 0, 0); - if (Q_UNLIKELY(eglResult != EGL_TRUE)) - qFatal("QQnxGLContext: failed to initialize EGL display, err=%d", eglGetError()); -} - -void QQnxGLContext::shutdownContext() -{ - qGLContextDebug(); - - // Close connection to EGL - eglTerminate(ms_eglDisplay); -} - EGLSurface QQnxGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface) { QQnxEglWindow *window = static_cast(surface); diff --git a/src/plugins/platforms/qnx/qqnxglcontext.h b/src/plugins/platforms/qnx/qqnxglcontext.h index 19179a80e2..5d807ee9e4 100644 --- a/src/plugins/platforms/qnx/qqnxglcontext.h +++ b/src/plugins/platforms/qnx/qqnxglcontext.h @@ -58,19 +58,12 @@ public: QQnxGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share); virtual ~QQnxGLContext(); - static void initializeContext(); - static void shutdownContext(); - bool makeCurrent(QPlatformSurface *surface) override; void swapBuffers(QPlatformSurface *surface) override; void doneCurrent() override; protected: EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override; - -private: - //Can be static because different displays returne the same handle - static EGLDisplay ms_eglDisplay; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/qnx/qqnxintegration.cpp b/src/plugins/platforms/qnx/qqnxintegration.cpp index f479e94988..84baa6ec44 100644 --- a/src/plugins/platforms/qnx/qqnxintegration.cpp +++ b/src/plugins/platforms/qnx/qqnxintegration.cpp @@ -170,6 +170,9 @@ QQnxIntegration::QQnxIntegration(const QStringList ¶mList) #if QT_CONFIG(draganddrop) , m_drag(new QSimpleDrag()) #endif +#if QT_CONFIG(opengl) + , m_eglDisplay(EGL_NO_DISPLAY) +#endif { ms_instance = this; m_options = parseOptions(paramList); @@ -195,9 +198,8 @@ QQnxIntegration::QQnxIntegration(const QStringList ¶mList) QMetaObject::invokeMethod(m_navigatorEventNotifier, "start", Qt::QueuedConnection); #endif -#if !defined(QT_NO_OPENGL) - // Initialize global OpenGL resources - QQnxGLContext::initializeContext(); +#if QT_CONFIG(opengl) + createEglDisplay(); #endif // Create/start event thread @@ -284,9 +286,8 @@ QQnxIntegration::~QQnxIntegration() // Close connection to QNX composition manager screen_destroy_context(m_screenContext); -#if !defined(QT_NO_OPENGL) - // Cleanup global OpenGL resources - QQnxGLContext::shutdownContext(); +#if QT_CONFIG(opengl) + destroyEglDisplay(); #endif #if QT_CONFIG(qqnx_pps) @@ -741,4 +742,28 @@ bool QQnxIntegration::supportsNavigatorEvents() const return m_navigator != 0; } +#if QT_CONFIG(opengl) +void QQnxIntegration::createEglDisplay() +{ + qIntegrationDebug(); + + // Initialize connection to EGL + m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY)) + qFatal("QQnxiIntegration: failed to obtain EGL display: %x", eglGetError()); + + EGLBoolean eglResult = eglInitialize(m_eglDisplay, 0, 0); + if (Q_UNLIKELY(eglResult != EGL_TRUE)) + qFatal("QQnxIntegration: failed to initialize EGL display, err=%d", eglGetError()); +} + +void QQnxIntegration::destroyEglDisplay() +{ + qIntegrationDebug(); + + // Close connection to EGL + eglTerminate(m_eglDisplay); +} +#endif + QT_END_NAMESPACE diff --git a/src/plugins/platforms/qnx/qqnxintegration.h b/src/plugins/platforms/qnx/qqnxintegration.h index 0bf37880d1..2596af3c45 100644 --- a/src/plugins/platforms/qnx/qqnxintegration.h +++ b/src/plugins/platforms/qnx/qqnxintegration.h @@ -46,6 +46,10 @@ #include +#if QT_CONFIG(opengl) +#include +#endif + QT_BEGIN_NAMESPACE class QQnxScreenEventThread; @@ -96,7 +100,8 @@ public: QPlatformWindow *createPlatformWindow(QWindow *window) const override; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override; -#if !defined(QT_NO_OPENGL) +#if QT_CONFIG(opengl) + EGLDisplay eglDisplay() const { return m_eglDisplay; } QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override; #endif @@ -175,6 +180,12 @@ private: Options m_options; +#if QT_CONFIG(opengl) + EGLDisplay m_eglDisplay; + void createEglDisplay(); + void destroyEglDisplay(); +#endif + static QQnxIntegration *ms_instance; friend class QQnxWindow; -- cgit v1.2.3 From 127533637e4ff4d3301fe02c88a2a506dd24c199 Mon Sep 17 00:00:00 2001 From: James McDonnell Date: Wed, 30 Oct 2019 10:22:07 -0400 Subject: Provide repeat parameter to handleExtendedKeyEvent QtWayland uses this to discard key repeats. Modifier key repeats confuse xkbcommon. Change-Id: I3ea384aa7b750ff83520bfb2440e61b91bb6e354 Reviewed-by: Dan Cape Reviewed-by: Johan Helsing --- src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp index a9b5860187..e3a6aea99f 100644 --- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp +++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp @@ -257,7 +257,7 @@ void QQnxScreenEventHandler::injectKeyboardEvent(int flags, int sym, int modifie capKeyString(cap, modifiers, key); QWindowSystemInterface::handleExtendedKeyEvent(QGuiApplication::focusWindow(), type, key, qtMod, - scan, virtualKey, modifiers, keyStr); + scan, virtualKey, modifiers, keyStr, flags & KEY_REPEAT); qScreenEventDebug() << "Qt key t=" << type << ", k=" << key << ", s=" << keyStr; } -- cgit v1.2.3 From d6266c757d2f2ea4ff1e71dc8545f9bf97aa3bb1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 6 Dec 2019 13:19:37 +0100 Subject: Replace usages of QVariant::value by qvariant_cast This is done automatically with a clazy check Change-Id: I3b59511d3d36d416c8eda74858ead611d327b116 Reviewed-by: Lars Knoll --- src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index 57805d5571..75189a9c80 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -429,7 +429,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share, const qWarning("QGLXContext: Requires a QGLXNativeContext"); return; } - QGLXNativeContext handle = nativeHandle.value(); + QGLXNativeContext handle = qvariant_cast(nativeHandle); GLXContext context = handle.context(); if (!context) { qWarning("QGLXContext: No GLXContext given"); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 66030b9ad4..23ed80ab5a 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -930,7 +930,7 @@ void QXcbWindow::setWindowFlags(Qt::WindowFlags flags) QXcbWindowFunctions::WmWindowTypes wmWindowTypes; if (window()->dynamicPropertyNames().contains(wm_window_type_property_id)) { wmWindowTypes = static_cast( - window()->property(wm_window_type_property_id).value()); + qvariant_cast(window()->property(wm_window_type_property_id))); } setWmWindowType(wmWindowTypes, flags); -- cgit v1.2.3 From 313c2b46fe2830de981c94d07c5ef5ced9cb3257 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 27 Nov 2019 15:00:50 +0100 Subject: Windows QPA: Use UTF-16 literals where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should minimize diffs to Qt 6. Change-Id: Id74c0b4085085984bd51251765420718d16e9fc7 Reviewed-by: André de la Rocha --- .../platforms/windows/qwindowsclipboard.cpp | 4 +- .../platforms/windows/qwindowsdialoghelpers.cpp | 60 +++++++++++----------- .../platforms/windows/qwindowseglcontext.cpp | 2 +- .../platforms/windows/qwindowsintegration.cpp | 32 ++++++------ src/plugins/platforms/windows/qwindowsmenu.cpp | 2 +- src/plugins/platforms/windows/qwindowsmime.cpp | 44 ++++++++-------- .../platforms/windows/qwindowsopengltester.cpp | 4 +- src/plugins/platforms/windows/qwindowsscreen.cpp | 2 +- src/plugins/platforms/windows/qwindowsservices.cpp | 6 +-- .../platforms/windows/qwindowssystemtrayicon.cpp | 2 +- src/plugins/platforms/windows/qwindowstheme.cpp | 14 ++--- src/plugins/platforms/windows/qwindowswindow.cpp | 2 +- .../uiautomation/qwindowsuiamainprovider.cpp | 2 +- 13 files changed, 89 insertions(+), 87 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index 4e6d3306e1..ccd4e50a8b 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -82,7 +82,7 @@ static QDebug operator<<(QDebug d, const QMimeData *mimeData) d << "QMimeData("; if (mimeData) { const QStringList formats = mimeData->formats(); - d << "formats=" << formats.join(QLatin1String(", ")); + d << "formats=" << formats.join(u", "); if (mimeData->hasText()) d << ", text=" << mimeData->text(); if (mimeData->hasHtml()) @@ -339,7 +339,7 @@ void QWindowsClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode) if (src != S_OK) { QString mimeDataFormats = mimeData ? - mimeData->formats().join(QLatin1String(", ")) : QString(QStringLiteral("NULL")); + mimeData->formats().join(u", ") : QString(QStringLiteral("NULL")); qErrnoWarning("OleSetClipboard: Failed to set mime data (%s) on clipboard: %s", qPrintable(mimeDataFormats), QWindowsContext::comErrorString(src).constData()); diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index cdb4e407d1..b038e19689 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -91,7 +91,7 @@ static inline QString guidToString(const GUID &g) str << '{' << g.Data1 << ", " << g.Data2 << ", " << g.Data3; str.setFieldWidth(2); str.setFieldAlignment(QTextStream::AlignRight); - str.setPadChar(QLatin1Char('0')); + str.setPadChar(u'0'); str << ",{" << g.Data4[0] << ", " << g.Data4[1] << ", " << g.Data4[2] << ", " << g.Data4[3] << ", " << g.Data4[4] << ", " << g.Data4[5] << ", " << g.Data4[6] << ", " << g.Data4[7] << "}};"; @@ -915,7 +915,7 @@ IShellItem *QWindowsNativeFileDialogBase::shellItem(const QUrl &url) return nullptr; } return result; - } else if (url.scheme() == QLatin1String("clsid")) { + } else if (url.scheme() == u"clsid") { // Support for virtual folders via GUID // (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx) // specified as "clsid:" (without '{', '}'). @@ -1040,20 +1040,20 @@ static QList filterSpecs(const QStringList &filters, // Split filter specification as 'Texts (*.txt[;] *.doc)', '*.txt[;] *.doc' // into description and filters specification as '*.txt;*.doc' for (const QString &filterString : filters) { - const int openingParenPos = filterString.lastIndexOf(QLatin1Char('(')); + const int openingParenPos = filterString.lastIndexOf(u'('); const int closingParenPos = openingParenPos != -1 ? - filterString.indexOf(QLatin1Char(')'), openingParenPos + 1) : -1; + filterString.indexOf(u')', openingParenPos + 1) : -1; FilterSpec filterSpec; filterSpec.filter = closingParenPos == -1 ? filterString : filterString.mid(openingParenPos + 1, closingParenPos - openingParenPos - 1).trimmed(); if (filterSpec.filter.isEmpty()) - filterSpec.filter += QLatin1Char('*'); + filterSpec.filter += u'*'; filterSpec.filter.replace(filterSeparatorRE, separator); filterSpec.description = filterString; if (hideFilterDetails && openingParenPos != -1) { // Do not show pattern in description filterSpec.description.truncate(openingParenPos); - while (filterSpec.description.endsWith(QLatin1Char(' '))) + while (filterSpec.description.endsWith(u' ')) filterSpec.description.truncate(filterSpec.description.size() - 1); } *totalStringLength += filterSpec.filter.size() + filterSpec.description.size(); @@ -1084,8 +1084,8 @@ void QWindowsNativeFileDialogBase::setNameFilters(const QStringList &filters) // 'AAA files (a.*) (a.*)' QString description = specs[i].description; const QString &filter = specs[i].filter; - if (!m_hideFiltersDetails && !filter.startsWith(QLatin1String("*."))) { - const int pos = description.lastIndexOf(QLatin1Char('(')); + if (!m_hideFiltersDetails && !filter.startsWith(u"*.")) { + const int pos = description.lastIndexOf(u'('); if (pos > 0) description.truncate(pos); } @@ -1151,8 +1151,8 @@ static bool isHexRange(const QString& s, int start, int end) for (;start < end; ++start) { QChar ch = s.at(start); if (!(ch.isDigit() - || (ch >= QLatin1Char('a') && ch <= QLatin1Char('f')) - || (ch >= QLatin1Char('A') && ch <= QLatin1Char('F')))) + || (ch >= u'a' && ch <= u'f') + || (ch >= u'A' && ch <= u'F'))) return false; } return true; @@ -1161,7 +1161,7 @@ static bool isHexRange(const QString& s, int start, int end) static inline bool isClsid(const QString &s) { // detect "374DE290-123F-4565-9164-39C4925E467B". - const QChar dash(QLatin1Char('-')); + const QChar dash(u'-'); return s.size() == 36 && isHexRange(s, 0, 8) && s.at(8) == dash @@ -1204,7 +1204,7 @@ void QWindowsNativeFileDialogBase::selectNameFilter(const QString &filter) if (index < 0) { qWarning("%s: Invalid parameter '%s' not found in '%s'.", __FUNCTION__, qPrintable(filter), - qPrintable(m_nameFilters.join(QLatin1String(", ")))); + qPrintable(m_nameFilters.join(u", "))); return; } m_fileDialog->SetFileTypeIndex(index + 1); // one-based. @@ -1313,15 +1313,15 @@ public: // Also handles the simple name filter case "*.txt" -> "txt" static inline QString suffixFromFilter(const QString &filter) { - int suffixPos = filter.indexOf(QLatin1String("*.")); + int suffixPos = filter.indexOf(u"*."); if (suffixPos < 0) return QString(); suffixPos += 2; - int endPos = filter.indexOf(QLatin1Char(' '), suffixPos + 1); + int endPos = filter.indexOf(u' ', suffixPos + 1); if (endPos < 0) - endPos = filter.indexOf(QLatin1Char(';'), suffixPos + 1); + endPos = filter.indexOf(u';', suffixPos + 1); if (endPos < 0) - endPos = filter.indexOf(QLatin1Char(')'), suffixPos + 1); + endPos = filter.indexOf(u')', suffixPos + 1); if (endPos < 0) endPos = filter.size(); return filter.mid(suffixPos, endPos - suffixPos); @@ -1406,27 +1406,27 @@ static void cleanupTemporaryItemCopies() static bool validFileNameCharacter(QChar c) { - return c.isLetterOrNumber() || c == QLatin1Char('_') || c == QLatin1Char('-'); + return c.isLetterOrNumber() || c == u'_' || c == u'-'; } QString tempFilePattern(QString name) { - const int lastSlash = qMax(name.lastIndexOf(QLatin1Char('/')), - name.lastIndexOf(QLatin1Char('\\'))); + const int lastSlash = qMax(name.lastIndexOf(u'/'), + name.lastIndexOf(u'\\')); if (lastSlash != -1) name.remove(0, lastSlash + 1); - int lastDot = name.lastIndexOf(QLatin1Char('.')); + int lastDot = name.lastIndexOf(u'.'); if (lastDot < 0) lastDot = name.size(); name.insert(lastDot, QStringLiteral("_XXXXXX")); for (int i = lastDot - 1; i >= 0; --i) { if (!validFileNameCharacter(name.at(i))) - name[i] = QLatin1Char('_'); + name[i] = u'_'; } - name.prepend(QDir::tempPath() + QLatin1Char('/')); + name.prepend(QDir::tempPath() + u'/'); return name; } @@ -1456,7 +1456,7 @@ static QString createTemporaryItemCopy(QWindowsShellItem &qItem, QString *errorM static QUrl itemToDialogUrl(QWindowsShellItem &qItem, QString *errorMessage) { QUrl url = qItem.url(); - if (url.isLocalFile() || url.scheme().startsWith(QLatin1String("http"))) + if (url.isLocalFile() || url.scheme().startsWith(u"http")) return url; const QString path = qItem.path(); if (path.isEmpty() && !qItem.isDir() && qItem.canStream()) { @@ -1859,10 +1859,12 @@ void QWindowsXpNativeFileDialog::populateOpenFileName(OPENFILENAME *ofn, HWND ow // for the target. If it contains any invalid character, the dialog // will not show. ofn->nMaxFile = 65535; - const QString initiallySelectedFile = - QDir::toNativeSeparators(m_data.selectedFile()).remove(QLatin1Char('<')). - remove(QLatin1Char('>')).remove(QLatin1Char('"')).remove(QLatin1Char('|')); - ofn->lpstrFile = qStringToWCharArray(initiallySelectedFile, ofn->nMaxFile); + QString initiallySelectedFile = m_data.selectedFile(); + initiallySelectedFile.remove(u'<'); + initiallySelectedFile.remove(u'>'); + initiallySelectedFile.remove(u'"'); + initiallySelectedFile.remove(u'|'); + ofn->lpstrFile = qStringToWCharArray(QDir::toNativeSeparators(initiallySelectedFile), ofn->nMaxFile); ofn->lpstrInitialDir = qStringToWCharArray(QDir::toNativeSeparators(m_data.directory().toLocalFile())); ofn->lpstrTitle = (wchar_t*)m_title.utf16(); // Determine lpstrDefExt. Note that the current MSDN docs document this @@ -1872,7 +1874,7 @@ void QWindowsXpNativeFileDialog::populateOpenFileName(OPENFILENAME *ofn, HWND ow // the extension of the current filter". if (m_options->acceptMode() == QFileDialogOptions::AcceptSave) { QString defaultSuffix = m_options->defaultSuffix(); - if (defaultSuffix.startsWith(QLatin1Char('.'))) + if (defaultSuffix.startsWith(u'.')) defaultSuffix.remove(0, 1); // QTBUG-33156, also create empty strings to trigger the appending mechanism. ofn->lpstrDefExt = qStringToWCharArray(defaultSuffix); @@ -1905,7 +1907,7 @@ QList QWindowsXpNativeFileDialog::execFileNames(HWND owner, int *selectedF wchar_t *ptr = ofn.lpstrFile + dir.size() + 1; if (*ptr) { result.pop_front(); - const QString path = dir + QLatin1Char('/'); + const QString path = dir + u'/'; while (*ptr) { const QString fileName = QString::fromWCharArray(ptr); result.push_back(QUrl::fromLocalFile(path + fileName)); diff --git a/src/plugins/platforms/windows/qwindowseglcontext.cpp b/src/plugins/platforms/windows/qwindowseglcontext.cpp index e9f3dc5189..76baa93d98 100644 --- a/src/plugins/platforms/windows/qwindowseglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowseglcontext.cpp @@ -88,7 +88,7 @@ static void *resolveFunc(HMODULE lib, const char *name) while (!proc && argSize <= 64) { nameStr = baseNameStr; if (argSize >= 0) - nameStr += QLatin1Char('@') + QString::number(argSize); + nameStr += u'@' + QString::number(argSize); argSize = argSize < 0 ? 0 : argSize + 4; proc = (void *) ::GetProcAddress(lib, nameStr.toLatin1().constData()); } diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 09117f663d..32bd29a842 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -162,7 +162,7 @@ bool parseIntOption(const QString ¶meter,const QLatin1String &option, IntType minimumValue, IntType maximumValue, IntType *target) { const int valueLength = parameter.size() - option.size() - 1; - if (valueLength < 1 || !parameter.startsWith(option) || parameter.at(option.size()) != QLatin1Char('=')) + if (valueLength < 1 || !parameter.startsWith(option) || parameter.at(option.size()) != u'=') return false; bool ok; const QStringRef valueRef = parameter.rightRef(valueLength); @@ -186,38 +186,38 @@ static inline unsigned parseOptions(const QStringList ¶mList, { unsigned options = 0; for (const QString ¶m : paramList) { - if (param.startsWith(QLatin1String("fontengine="))) { - if (param.endsWith(QLatin1String("freetype"))) { + if (param.startsWith(u"fontengine=")) { + if (param.endsWith(u"freetype")) { options |= QWindowsIntegration::FontDatabaseFreeType; - } else if (param.endsWith(QLatin1String("native"))) { + } else if (param.endsWith(u"native")) { options |= QWindowsIntegration::FontDatabaseNative; } - } else if (param.startsWith(QLatin1String("dialogs="))) { - if (param.endsWith(QLatin1String("xp"))) { + } else if (param.startsWith(u"dialogs=")) { + if (param.endsWith(u"xp")) { options |= QWindowsIntegration::XpNativeDialogs; - } else if (param.endsWith(QLatin1String("none"))) { + } else if (param.endsWith(u"none")) { options |= QWindowsIntegration::NoNativeDialogs; } - } else if (param == QLatin1String("altgr")) { + } else if (param == u"altgr") { options |= QWindowsIntegration::DetectAltGrModifier; - } else if (param == QLatin1String("gl=gdi")) { + } else if (param == u"gl=gdi") { options |= QWindowsIntegration::DisableArb; - } else if (param == QLatin1String("nodirectwrite")) { + } else if (param == u"nodirectwrite") { options |= QWindowsIntegration::DontUseDirectWriteFonts; - } else if (param == QLatin1String("nocolorfonts")) { + } else if (param == u"nocolorfonts") { options |= QWindowsIntegration::DontUseColorFonts; - } else if (param == QLatin1String("nomousefromtouch")) { + } else if (param == u"nomousefromtouch") { options |= QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch; } else if (parseIntOption(param, QLatin1String("verbose"), 0, INT_MAX, &QWindowsContext::verbose) || parseIntOption(param, QLatin1String("tabletabsoluterange"), 0, INT_MAX, tabletAbsoluteRange) || parseIntOption(param, QLatin1String("dpiawareness"), QtWindows::ProcessDpiUnaware, QtWindows::ProcessPerMonitorDpiAware, dpiAwareness)) { - } else if (param == QLatin1String("menus=native")) { + } else if (param == u"menus=native") { options |= QWindowsIntegration::AlwaysUseNativeMenus; - } else if (param == QLatin1String("menus=none")) { + } else if (param == u"menus=none") { options |= QWindowsIntegration::NoNativeMenus; - } else if (param == QLatin1String("nowmpointer")) { + } else if (param == u"nowmpointer") { options |= QWindowsIntegration::DontUseWMPointer; - } else if (param == QLatin1String("reverse")) { + } else if (param == u"reverse") { options |= QWindowsIntegration::RtlEnabled; } else { qWarning() << "Unknown option" << param; diff --git a/src/plugins/platforms/windows/qwindowsmenu.cpp b/src/plugins/platforms/windows/qwindowsmenu.cpp index d20edd685e..7c3e87eec1 100644 --- a/src/plugins/platforms/windows/qwindowsmenu.cpp +++ b/src/plugins/platforms/windows/qwindowsmenu.cpp @@ -445,7 +445,7 @@ QString QWindowsMenuItem::nativeText() const QString result = m_text; #if QT_CONFIG(shortcut) if (!m_shortcut.isEmpty()) { - result += QLatin1Char('\t'); + result += u'\t'; result += m_shortcut.toString(QKeySequence::NativeText); } #endif diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp index 1c6c999f05..fe9e1fe31f 100644 --- a/src/plugins/platforms/windows/qwindowsmime.cpp +++ b/src/plugins/platforms/windows/qwindowsmime.cpp @@ -635,11 +635,11 @@ bool QWindowsMimeText::convertFromMime(const FORMATETC &formatetc, const QMimeDa int ri = 0; bool cr = false; for (int i=0; i < s; ++i) { - if (*u == QLatin1Char('\r')) + if (*u == u'\r') cr = true; else { - if (*u == QLatin1Char('\n') && !cr) - res[ri++] = QLatin1Char('\r'); + if (*u == u'\n' && !cr) + res[ri++] = u'\r'; cr = false; } res[ri++] = *u; @@ -663,7 +663,7 @@ bool QWindowsMimeText::convertFromMime(const FORMATETC &formatetc, const QMimeDa bool QWindowsMimeText::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const { - return mimeType.startsWith(QLatin1String("text/plain")) + return mimeType.startsWith(u"text/plain") && (canGetData(CF_UNICODETEXT, pDataObj) || canGetData(CF_TEXT, pDataObj)); } @@ -680,7 +680,7 @@ QString QWindowsMimeText::mimeForFormat(const FORMATETC &formatetc) const QVector QWindowsMimeText::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const { QVector formatics; - if (mimeType.startsWith(QLatin1String("text/plain")) && mimeData->hasText()) { + if (mimeType.startsWith(u"text/plain") && mimeData->hasText()) { formatics += setCf(CF_UNICODETEXT); formatics += setCf(CF_TEXT); } @@ -816,7 +816,7 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat bool QWindowsMimeURI::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const { - return mimeType == QLatin1String("text/uri-list") + return mimeType == u"text/uri-list" && (canGetData(CF_HDROP, pDataObj) || canGetData(CF_INETURL_W, pDataObj) || canGetData(CF_INETURL, pDataObj)); } @@ -831,7 +831,7 @@ QString QWindowsMimeURI::mimeForFormat(const FORMATETC &formatetc) const QVector QWindowsMimeURI::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const { QVector formatics; - if (mimeType == QLatin1String("text/uri-list")) { + if (mimeType == u"text/uri-list") { if (canConvertFromMime(setCf(CF_HDROP), mimeData)) formatics += setCf(CF_HDROP); if (canConvertFromMime(setCf(CF_INETURL_W), mimeData)) @@ -844,7 +844,7 @@ QVector QWindowsMimeURI::formatsForMime(const QString &mimeType, cons QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pDataObj, QVariant::Type preferredType) const { - if (mimeType == QLatin1String("text/uri-list")) { + if (mimeType == u"text/uri-list") { if (canGetData(CF_HDROP, pDataObj)) { QList urls; @@ -916,7 +916,7 @@ QWindowsMimeHtml::QWindowsMimeHtml() QVector QWindowsMimeHtml::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const { QVector formatetcs; - if (mimeType == QLatin1String("text/html") && (!mimeData->html().isEmpty())) + if (mimeType == u"text/html" && (!mimeData->html().isEmpty())) formatetcs += setCf(CF_HTML); return formatetcs; } @@ -930,7 +930,7 @@ QString QWindowsMimeHtml::mimeForFormat(const FORMATETC &formatetc) const bool QWindowsMimeHtml::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const { - return mimeType == QLatin1String("text/html") && canGetData(CF_HTML, pDataObj); + return mimeType == u"text/html" && canGetData(CF_HTML, pDataObj); } @@ -1053,7 +1053,7 @@ QWindowsMimeImage::QWindowsMimeImage() QVector QWindowsMimeImage::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const { QVector formatetcs; - if (mimeData->hasImage() && mimeType == QLatin1String("application/x-qt-image")) { + if (mimeData->hasImage() && mimeType == u"application/x-qt-image") { //add DIBV5 if image has alpha channel. Do not add CF_PNG here as it will confuse MS Office (QTBUG47656). auto image = qvariant_cast(mimeData->imageData()); if (!image.isNull() && image.hasAlphaChannel()) @@ -1075,7 +1075,7 @@ QString QWindowsMimeImage::mimeForFormat(const FORMATETC &formatetc) const bool QWindowsMimeImage::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const { - return mimeType == QLatin1String("application/x-qt-image") + return mimeType == u"application/x-qt-image" && (canGetData(CF_DIB, pDataObj) || canGetData(CF_PNG, pDataObj)); } @@ -1149,7 +1149,7 @@ QVariant QWindowsMimeImage::convertToMime(const QString &mimeType, IDataObject * { Q_UNUSED(preferredType); QVariant result; - if (mimeType != QLatin1String("application/x-qt-image")) + if (mimeType != u"application/x-qt-image") return result; //Try to convert from a format which has more data //DIBV5, use only if its is not synthesized @@ -1220,7 +1220,7 @@ bool QBuiltInMimes::convertFromMime(const FORMATETC &formatetc, const QMimeData { if (canConvertFromMime(formatetc, mimeData)) { QByteArray data; - if (outFormats.value(getCf(formatetc)) == QLatin1String("text/html")) { + if (outFormats.value(getCf(formatetc)) == u"text/html") { // text/html is in wide chars on windows (compatible with mozillia) QString html = mimeData->html(); // same code as in the text converter up above @@ -1232,11 +1232,11 @@ bool QBuiltInMimes::convertFromMime(const FORMATETC &formatetc, const QMimeData int ri = 0; bool cr = false; for (int i=0; i < s; ++i) { - if (*u == QLatin1Char('\r')) + if (*u == u'\r') cr = true; else { - if (*u == QLatin1Char('\n') && !cr) - res[ri++] = QLatin1Char('\r'); + if (*u == u'\n' && !cr) + res[ri++] = u'\r'; cr = false; } res[ri++] = *u; @@ -1285,7 +1285,7 @@ QVariant QBuiltInMimes::convertToMime(const QString &mimeType, IDataObject *pDat QByteArray data = getData(inFormats.key(mimeType), pDataObj); if (!data.isEmpty()) { qCDebug(lcQpaMime) << __FUNCTION__; - if (mimeType == QLatin1String("text/html") && preferredType == QVariant::String) { + if (mimeType == u"text/html" && preferredType == QVariant::String) { // text/html is in wide chars on windows (compatible with Mozilla) val = QString::fromWCharArray(reinterpret_cast(data.constData())); } else { @@ -1404,12 +1404,12 @@ static bool isCustomMimeType(const QString &mimeType) static QString customMimeType(const QString &mimeType, int *lindex = nullptr) { int len = sizeof(x_qt_windows_mime) - 1; - int n = mimeType.lastIndexOf(QLatin1Char('\"')) - len; + int n = mimeType.lastIndexOf(u'\"') - len; QString ret = mimeType.mid(len, n); - const int beginPos = mimeType.indexOf(QLatin1String(";index=")); + const int beginPos = mimeType.indexOf(u";index="); if (beginPos > -1) { - const int endPos = mimeType.indexOf(QLatin1Char(';'), beginPos + 1); + const int endPos = mimeType.indexOf(u';', beginPos + 1); const int indexStartPos = beginPos + 7; if (lindex) *lindex = mimeType.midRef(indexStartPos, endPos == -1 ? endPos : endPos - indexStartPos).toInt(); @@ -1480,7 +1480,7 @@ QString QLastResortMimes::mimeForFormat(const FORMATETC &formatetc) const } } if (!ianaType) - format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"'); + format = QLatin1String(x_qt_windows_mime) + clipFormat + u'"'; else format = clipFormat; } diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index afc1991e2c..72092a4481 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -206,7 +206,7 @@ QString GpuDescription::toString() const str << " Card name : " << description << "\n Driver Name : " << driverName << "\n Driver Version : " << driverVersion.toString() - << "\n Vendor ID : 0x" << qSetPadChar(QLatin1Char('0')) + << "\n Vendor ID : 0x" << qSetPadChar(u'0') << Qt::uppercasedigits << Qt::hex << qSetFieldWidth(4) << vendorId << "\n Device ID : 0x" << qSetFieldWidth(4) << deviceId << "\n SubSys ID : 0x" << qSetFieldWidth(8) << subSysId @@ -285,7 +285,7 @@ static inline QString resolveBugListFile(const QString &fileName) // then resolve via QStandardPaths::ConfigLocation. const QString settingsPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); if (!settingsPath.isEmpty()) { // SettingsPath is empty unless specified in qt.conf. - const QFileInfo fi(settingsPath + QLatin1Char('/') + fileName); + const QFileInfo fi(settingsPath + u'/' + fileName); if (fi.isFile()) return fi.absoluteFilePath(); } diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 4f76a82544..c7a0c2e62e 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -87,7 +87,7 @@ static bool monitorData(HMONITOR hMonitor, QWindowsScreenData *data) data->geometry = QRect(QPoint(info.rcMonitor.left, info.rcMonitor.top), QPoint(info.rcMonitor.right - 1, info.rcMonitor.bottom - 1)); data->availableGeometry = QRect(QPoint(info.rcWork.left, info.rcWork.top), QPoint(info.rcWork.right - 1, info.rcWork.bottom - 1)); data->name = QString::fromWCharArray(info.szDevice); - if (data->name == QLatin1String("WinDisc")) { + if (data->name == u"WinDisc") { data->flags |= QWindowsScreenData::LockScreen; } else { if (const HDC hdc = CreateDC(info.szDevice, nullptr, nullptr, nullptr)) { diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp index 83b052bb49..6a2708ee26 100644 --- a/src/plugins/platforms/windows/qwindowsservices.cpp +++ b/src/plugins/platforms/windows/qwindowsservices.cpp @@ -92,7 +92,7 @@ static inline QString mailCommand() // "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it // silently fails or brings up a broken dialog after a long time, so exclude it and // fall back to ShellExecute() which brings up the URL assocation dialog. - if (command.isEmpty() || command.contains(QLatin1String(",MailToProtocolHandler"))) + if (command.isEmpty() || command.contains(u",MailToProtocolHandler")) return QString(); wchar_t expandedCommand[MAX_PATH] = {0}; return ExpandEnvironmentStrings(reinterpret_cast(command.utf16()), @@ -108,7 +108,7 @@ static inline bool launchMail(const QUrl &url) return false; } //Make sure the path for the process is in quotes - const QChar doubleQuote = QLatin1Char('"'); + const QChar doubleQuote = u'"'; if (!command.startsWith(doubleQuote)) { const int exeIndex = command.indexOf(QStringLiteral(".exe "), 0, Qt::CaseInsensitive); if (exeIndex != -1) { @@ -140,7 +140,7 @@ static inline bool launchMail(const QUrl &url) bool QWindowsServices::openUrl(const QUrl &url) { const QString scheme = url.scheme(); - if (scheme == QLatin1String("mailto") && launchMail(url)) + if (scheme == u"mailto" && launchMail(url)) return true; return shellExecute(url); } diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index ab830e1461..66c558df1e 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -261,7 +261,7 @@ void QWindowsSystemTrayIcon::showMessage(const QString &title, const QString &me // For empty messages, ensures that they show when only title is set QString message = messageIn; if (message.isEmpty() && !title.isEmpty()) - message.append(QLatin1Char(' ')); + message.append(u' '); NOTIFYICONDATA tnd; initNotifyIconData(tnd); diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 32a65109af..010aea2068 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -96,7 +96,7 @@ static inline QTextStream& operator<<(QTextStream &str, const QColor &c) { str.setIntegerBase(16); str.setFieldWidth(2); - str.setPadChar(QLatin1Char('0')); + str.setPadChar(u'0'); str << " rgb: #" << c.red() << c.green() << c.blue(); str.setIntegerBase(10); str.setFieldWidth(0); @@ -731,13 +731,13 @@ static QString dirIconPixmapCacheKey(int iIcon, int iconSize, int imageListSize) { QString key = QLatin1String("qt_dir_") + QString::number(iIcon); if (iconSize == SHGFI_LARGEICON) - key += QLatin1Char('l'); + key += u'l'; switch (imageListSize) { case sHIL_EXTRALARGE: - key += QLatin1Char('e'); + key += u'e'; break; case sHIL_JUMBO: - key += QLatin1Char('j'); + key += u'j'; break; } return key; @@ -815,9 +815,9 @@ QString QWindowsFileIconEngine::cacheKey() const // It is faster to just look at the file extensions; // avoiding slow QFileInfo::isExecutable() (QTBUG-13182) QString suffix = fileInfo().suffix(); - if (!suffix.compare(QLatin1String("exe"), Qt::CaseInsensitive) - || !suffix.compare(QLatin1String("lnk"), Qt::CaseInsensitive) - || !suffix.compare(QLatin1String("ico"), Qt::CaseInsensitive)) { + if (!suffix.compare(u"exe", Qt::CaseInsensitive) + || !suffix.compare(u"lnk", Qt::CaseInsensitive) + || !suffix.compare(u"ico", Qt::CaseInsensitive)) { return QString(); } return QLatin1String("qt_.") diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 5a4f879d0f..a7aad15749 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -253,7 +253,7 @@ QDebug operator<<(QDebug d, const GUID &guid) { QDebugStateSaver saver(d); d.nospace(); - d << '{' << Qt::hex << Qt::uppercasedigits << qSetPadChar(QLatin1Char('0')) + d << '{' << Qt::hex << Qt::uppercasedigits << qSetPadChar(u'0') << qSetFieldWidth(8) << guid.Data1 << qSetFieldWidth(0) << '-' << qSetFieldWidth(4) << guid.Data2 << qSetFieldWidth(0) << '-' << qSetFieldWidth(4) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index cc293b777c..a0a976545f 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -473,7 +473,7 @@ QString QWindowsUiaMainProvider::automationIdForAccessible(const QAccessibleInte if (name.isEmpty()) return QString(); if (!result.isEmpty()) - result.prepend(QLatin1Char('.')); + result.prepend(u'.'); result.prepend(name); obj = obj->parent(); } -- cgit v1.2.3 From 18f22fea7c89da59b040da6361026593c8557a74 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Wed, 13 Nov 2019 16:39:52 +0100 Subject: Windows QPA: Allow the native Windows virtual keyboard to be disabled This change provides a way to disable the automatic showing of the native Windows on-screen virtual keyboard when a text editing widget is selected on a system without a physical keyboard, by enabling the new AA_MSWindowsDisableVirtualKeyboard application attribute, allowing applications to use a custom virtual keyboard implementation. Fixes: QTBUG-76088 Change-Id: Id76f9673a2e4081e5325662f3e3b4b102d133b9a Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsinputcontext.cpp | 3 ++- .../platforms/windows/uiautomation/qwindowsuiamainprovider.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp index 19d632dc10..f1f5d3a96e 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp @@ -285,7 +285,8 @@ void QWindowsInputContext::showInputPanel() // the Surface seems unnecessary there anyway. But leave it hidden for IME. // Only trigger the native OSK if the Qt OSK is not in use. static bool imModuleEmpty = qEnvironmentVariableIsEmpty("QT_IM_MODULE"); - if (imModuleEmpty + bool nativeVKDisabled = QCoreApplication::testAttribute(Qt::AA_MSWindowsDisableVirtualKeyboard); + if ((imModuleEmpty && !nativeVKDisabled) && QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 16299)) { ShowCaret(platformWindow->handle()); diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index a0a976545f..5f564f81c2 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -393,12 +393,14 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR // Control type converted from role. auto controlType = roleToControlTypeId(accessible->role()); - // The native OSK should be disbled if the Qt OSK is in use. + // The native OSK should be disbled if the Qt OSK is in use, + // or if disabled via application attribute. static bool imModuleEmpty = qEnvironmentVariableIsEmpty("QT_IM_MODULE"); + bool nativeVKDisabled = QCoreApplication::testAttribute(Qt::AA_MSWindowsDisableVirtualKeyboard); // If we want to disable the native OSK auto-showing // we have to report text fields as non-editable. - if (controlType == UIA_EditControlTypeId && !imModuleEmpty) + if (controlType == UIA_EditControlTypeId && (!imModuleEmpty || nativeVKDisabled)) controlType = UIA_TextControlTypeId; setVariantI4(controlType, pRetVal); -- cgit v1.2.3 From b2e3a5502afc0398cb8a732c366253e72a64b744 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 6 Dec 2019 13:30:40 +0100 Subject: Parse Xft.dpi with fraction Some versions of GNOME 3 would set Xft.dpi with fraction though that is technically not valid. Change-Id: Ib1027283cc78fd5d9869cd337864a92e28cd7e88 Fixes: QTBUG-64738 Reviewed-by: Gatis Paeglis --- src/plugins/platforms/xcb/qxcbscreen.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 7c60ca06f9..44d0bb3f55 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -320,12 +320,22 @@ bool QXcbVirtualDesktop::xResource(const QByteArray &identifier, static bool parseXftInt(const QByteArray& stringValue, int *value) { - Q_ASSERT(value != 0); + Q_ASSERT(value); bool ok; *value = stringValue.toInt(&ok); return ok; } +static bool parseXftDpi(const QByteArray& stringValue, int *value) +{ + Q_ASSERT(value); + bool ok = parseXftInt(stringValue, value); + // Support GNOME 3 bug that wrote DPI with fraction: + if (!ok) + *value = qRound(stringValue.toDouble(&ok)); + return ok; +} + static QFontEngine::HintStyle parseXftHintStyle(const QByteArray& stringValue) { if (stringValue == "hintfull") @@ -391,7 +401,7 @@ void QXcbVirtualDesktop::readXResources() int value; QByteArray stringValue; if (xResource(r, "Xft.dpi:\t", stringValue)) { - if (parseXftInt(stringValue, &value)) + if (parseXftDpi(stringValue, &value)) m_forcedDpi = value; } else if (xResource(r, "Xft.hintstyle:\t", stringValue)) { m_hintStyle = parseXftHintStyle(stringValue); -- cgit v1.2.3 From 9a77beaea36bf6c8b44086a15bed0e9903a06944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 18 Dec 2019 18:01:27 +0100 Subject: macOS: Deliver theme changes synchronously Otherwise the expose event that AppKit triggers will be delivered before we've propagated the theme change, and we fail to draw the UI using the new theme. Change-Id: I502122a2bf02a866d136106d831f0c2a0dfe26f2 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoatheme.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 7c10456824..387df65721 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -129,7 +129,7 @@ void QCocoaTheme::handleSystemThemeChange() QFontCache::instance()->clear(); } - QWindowSystemInterface::handleThemeChange(nullptr); + QWindowSystemInterface::handleThemeChange(nullptr); } bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const -- cgit v1.2.3 From 7ac4e55cb979dff890f1575e771e5f2def9e3131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 20 Dec 2019 16:46:24 +0100 Subject: macOS Don't throw away backingstore buffers when backing properties change Clients such as QtWidgets that do their own dirty tracking will assume they can just flush in response to the expose event, without repainting anything. Since we have no way at the moment to inform these clients that the backingstore content might be invalid we can't just throw it away. It turns out that to pick up changes in color spaces we can just tag the existing buffers with the new color space, so we don't need to throw it away. And for the older surface-backed mode we tag the color space on flush, so we didn't need to invalidate anything in the first place. Fixes: QTBUG-80844 Task-number: QTBUG-77749 Change-Id: Icb1ceb178894bb43887cdf03fb855d2d614b5ab0 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoabackingstore.h | 6 ++-- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 36 ++++++++++------------ src/plugins/platforms/cocoa/qcocoaintegration.mm | 2 ++ .../platforms/cocoa/qiosurfacegraphicsbuffer.h | 4 ++- .../platforms/cocoa/qiosurfacegraphicsbuffer.mm | 14 +++++---- 5 files changed, 32 insertions(+), 30 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index a874936ce6..b57deacb57 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -54,8 +54,6 @@ class QCocoaBackingStore : public QRasterBackingStore protected: QCocoaBackingStore(QWindow *window); QCFType colorSpace() const; - QMacNotificationObserver m_backingPropertiesObserver; - virtual void backingPropertiesChanged() = 0; }; class QNSWindowBackingStore : public QCocoaBackingStore @@ -71,7 +69,6 @@ private: bool windowHasUnifiedToolbar() const; QImage::Format format() const override; void redrawRoundedBottomCorners(CGRect) const; - void backingPropertiesChanged() override; }; class QCALayerBackingStore : public QCocoaBackingStore @@ -118,7 +115,8 @@ private: bool recreateBackBufferIfNeeded(); bool prepareForFlush(); - void backingPropertiesChanged() override; + void backingPropertiesChanged(); + QMacNotificationObserver m_backingPropertiesObserver; std::list> m_buffers; }; diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index b17302a640..8a815a7665 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -51,17 +51,6 @@ QT_BEGIN_NAMESPACE QCocoaBackingStore::QCocoaBackingStore(QWindow *window) : QRasterBackingStore(window) { - // Ideally this would be plumbed from the platform layer to QtGui, and - // the QBackingStore would be recreated, but we don't have that code yet, - // so at least make sure we invalidate our backingstore when the backing - // properties (color space e.g.) are changed. - NSView *view = static_cast(window->handle())->view(); - m_backingPropertiesObserver = QMacNotificationObserver(view.window, - NSWindowDidChangeBackingPropertiesNotification, [this]() { - qCDebug(lcQpaBackingStore) << "Backing properties for" - << this->window() << "did change"; - backingPropertiesChanged(); - }); } QCFType QCocoaBackingStore::colorSpace() const @@ -341,11 +330,6 @@ void QNSWindowBackingStore::redrawRoundedBottomCorners(CGRect windowRect) const #endif } -void QNSWindowBackingStore::backingPropertiesChanged() -{ - m_image = QImage(); -} - // ---------------------------------------------------------------------------- QCALayerBackingStore::QCALayerBackingStore(QWindow *window) @@ -353,6 +337,18 @@ QCALayerBackingStore::QCALayerBackingStore(QWindow *window) { qCDebug(lcQpaBackingStore) << "Creating QCALayerBackingStore for" << window; m_buffers.resize(1); + + // Ideally this would be plumbed from the platform layer to QtGui, and + // the QBackingStore would be recreated, but we don't have that code yet, + // so at least make sure we update our backingstore when the backing + // properties (color space e.g.) are changed. + NSView *view = static_cast(window->handle())->view(); + m_backingPropertiesObserver = QMacNotificationObserver(view.window, + NSWindowDidChangeBackingPropertiesNotification, [this]() { + qCDebug(lcQpaBackingStore) << "Backing properties for" + << this->window() << "did change"; + backingPropertiesChanged(); + }); } QCALayerBackingStore::~QCALayerBackingStore() @@ -620,8 +616,9 @@ QImage QCALayerBackingStore::toImage() const void QCALayerBackingStore::backingPropertiesChanged() { - m_buffers.clear(); - m_buffers.resize(1); + qCDebug(lcQpaBackingStore) << "Updating color space of existing buffers"; + for (auto &buffer : m_buffers) + buffer->setColorSpace(colorSpace()); } QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const @@ -698,10 +695,11 @@ bool QCALayerBackingStore::prepareForFlush() QCALayerBackingStore::GraphicsBuffer::GraphicsBuffer(const QSize &size, qreal devicePixelRatio, const QPixelFormat &format, QCFType colorSpace) - : QIOSurfaceGraphicsBuffer(size, format, colorSpace) + : QIOSurfaceGraphicsBuffer(size, format) , dirtyRegion(0, 0, size.width() / devicePixelRatio, size.height() / devicePixelRatio) , m_devicePixelRatio(devicePixelRatio) { + setColorSpace(colorSpace); } QImage *QCALayerBackingStore::GraphicsBuffer::asImage() diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index b7f15a2bf1..d8c931e9a1 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -396,6 +396,8 @@ QVariant QCocoaIntegration::styleHint(StyleHint hint) const return QCoreTextFontEngine::fontSmoothingGamma(); case ShowShortcutsInContextMenus: return QVariant(false); + // case CursorFlashTime: + // return 50000; default: break; } diff --git a/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.h b/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.h index 872773cb7a..e070ba977d 100644 --- a/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.h +++ b/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.h @@ -48,9 +48,11 @@ QT_BEGIN_NAMESPACE class QIOSurfaceGraphicsBuffer : public QPlatformGraphicsBuffer { public: - QIOSurfaceGraphicsBuffer(const QSize &size, const QPixelFormat &format, QCFType colorSpace); + QIOSurfaceGraphicsBuffer(const QSize &size, const QPixelFormat &format); ~QIOSurfaceGraphicsBuffer(); + void setColorSpace(QCFType colorSpace); + const uchar *data() const override; uchar *data() override; int bytesPerLine() const override; diff --git a/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.mm b/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.mm index a367487e85..285e316d4a 100644 --- a/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.mm +++ b/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.mm @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaIOSurface, "qt.qpa.backingstore.iosurface"); -QIOSurfaceGraphicsBuffer::QIOSurfaceGraphicsBuffer(const QSize &size, const QPixelFormat &format, QCFType colorSpace) +QIOSurfaceGraphicsBuffer::QIOSurfaceGraphicsBuffer(const QSize &size, const QPixelFormat &format) : QPlatformGraphicsBuffer(size, format) { const size_t width = size.width(); @@ -81,17 +81,19 @@ QIOSurfaceGraphicsBuffer::QIOSurfaceGraphicsBuffer(const QSize &size, const QPix Q_ASSERT(size_t(bytesPerLine()) == bytesPerRow); Q_ASSERT(size_t(byteCount()) == totalBytes); - - if (colorSpace) { - IOSurfaceSetValue(m_surface, CFSTR("IOSurfaceColorSpace"), - QCFType(CGColorSpaceCopyPropertyList(colorSpace))); - } } QIOSurfaceGraphicsBuffer::~QIOSurfaceGraphicsBuffer() { } +void QIOSurfaceGraphicsBuffer::setColorSpace(QCFType colorSpace) +{ + Q_ASSERT(colorSpace); + IOSurfaceSetValue(m_surface, CFSTR("IOSurfaceColorSpace"), + QCFType(CGColorSpaceCopyPropertyList(colorSpace))); +} + const uchar *QIOSurfaceGraphicsBuffer::data() const { return (const uchar *)IOSurfaceGetBaseAddress(m_surface); -- cgit v1.2.3 From a63969081c2f1656636f6fbc24b402a0f72c410b Mon Sep 17 00:00:00 2001 From: Alexandra Cherdantseva Date: Thu, 26 Dec 2019 16:17:20 +0300 Subject: wasm: support all cursor shapes Every Qt::CursorShape is supported. Tested in Chrome, Firefox and Safari. Change-Id: I38c9024dba4af70af789ac84ad7e38f749c847d7 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmcursor.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp index 2b3f37300d..28ec3b58dd 100644 --- a/src/plugins/platforms/wasm/qwasmcursor.cpp +++ b/src/plugins/platforms/wasm/qwasmcursor.cpp @@ -68,6 +68,7 @@ QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape) cursorName = "default"; break; case Qt::UpArrowCursor: + cursorName = "n-resize"; break; case Qt::CrossCursor: cursorName = "crosshair"; @@ -91,7 +92,8 @@ QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape) cursorName = "nwse-resize"; break; case Qt::SizeAllCursor: - break; // no equivalent? + cursorName = "move"; + break; case Qt::BlankCursor: cursorName = "none"; break; @@ -111,18 +113,23 @@ QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape) cursorName = "help"; break; case Qt::BusyCursor: - cursorName = "wait"; + cursorName = "progress"; break; case Qt::OpenHandCursor: - break; // no equivalent? + cursorName = "grab"; + break; case Qt::ClosedHandCursor: - break; // no equivalent? + cursorName = "grabbing"; + break; case Qt::DragCopyCursor: - break; // no equivalent? + cursorName = "copy"; + break; case Qt::DragMoveCursor: - break; // no equivalent? + cursorName = "default"; + break; case Qt::DragLinkCursor: - break; // no equivalent? + cursorName = "alias"; + break; default: break; } -- cgit v1.2.3 From 809a96d6d94a93046dc63dd6f52c51ae90c374f8 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 18 Dec 2019 19:06:18 +1000 Subject: wasm: fix setting translucent background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to set the requested SurfaceFormat which may contain the alphaBufferSize in order for the GL context to have the alpha attribute Fixes: QTBUG-77303 Change-Id: I39860e24de49a255ab7e73bca78af92e6c074d0d Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/wasm/qwasmcompositor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index a810880c43..e9c4559971 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -694,7 +694,7 @@ void QWasmCompositor::frame() if (m_context.isNull()) { m_context.reset(new QOpenGLContext()); - //mContext->setFormat(mScreen->format()); + m_context->setFormat(someWindow->window()->requestedFormat()); m_context->setScreen(screen()->screen()); m_context->create(); } -- cgit v1.2.3