summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp14
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm5
-rw-r--r--src/corelib/kernel/qcore_mac_p.h10
-rw-r--r--src/corelib/serialization/qcborstream.cpp10
-rw-r--r--src/gui/painting/qdrawhelper.cpp27
-rw-r--r--src/plugins/platforms/cocoa/cocoa.pro2
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm19
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm11
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm36
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowmanager.h63
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindowmanager.mm108
11 files changed, 262 insertions, 43 deletions
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index b23ee3ad8d..07c80dda7c 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -468,8 +468,18 @@ inline bool QStorageIterator::next()
size_t len = strlen(buffer.data());
if (len == 0)
return false;
- if (ptr[len - 1] == '\n')
- ptr[len - 1] = '\0';
+ while (Q_UNLIKELY(ptr[len - 1] != '\n' && !feof(fp))) {
+ // buffer wasn't large enough. Enlarge and try again.
+ // (we're readidng from the kernel, so OOM is unlikely)
+ buffer.resize((buffer.size() + 4096) & ~4095);
+ ptr = buffer.data();
+ if (fgets(ptr + len, buffer.size() - len, fp) == nullptr)
+ return false;
+
+ len += strlen(ptr + len);
+ Q_ASSERT(len < size_t(buffer.size()));
+ }
+ ptr[len - 1] = '\0';
// parse the line
bool ok;
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index 7b6ca4f684..15df303502 100644
--- a/src/corelib/kernel/qcore_mac_objc.mm
+++ b/src/corelib/kernel/qcore_mac_objc.mm
@@ -514,10 +514,9 @@ Q_CONSTRUCTOR_FUNCTION(qt_apple_check_os_version);
// -------------------------------------------------------------------------
-void QMacKeyValueObserver::addObserver()
+void QMacKeyValueObserver::addObserver(NSKeyValueObservingOptions options)
{
- [object addObserver:observer forKeyPath:keyPath
- options:NSKeyValueObservingOptionNew context:callback.get()];
+ [object addObserver:observer forKeyPath:keyPath options:options context:callback.get()];
}
void QMacKeyValueObserver::removeObserver() {
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 8f4c96bbd6..168e0418e4 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -350,8 +350,12 @@ public:
QMacKeyValueObserver() {}
// Note: QMacKeyValueObserver must not outlive the object observed!
- QMacKeyValueObserver(id object, NSString *keyPath, Callback callback)
- : object(object), keyPath(keyPath), callback(new Callback(callback)) { addObserver(); }
+ QMacKeyValueObserver(id object, NSString *keyPath, Callback callback,
+ NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew)
+ : object(object), keyPath(keyPath), callback(new Callback(callback))
+ {
+ addObserver(options);
+ }
QMacKeyValueObserver(const QMacKeyValueObserver &other)
: QMacKeyValueObserver(other.object, other.keyPath, *other.callback.get()) {}
@@ -381,7 +385,7 @@ private:
std::swap(first.callback, second.callback);
}
- void addObserver();
+ void addObserver(NSKeyValueObservingOptions options);
id object = nil;
NSString *keyPath = nullptr;
diff --git a/src/corelib/serialization/qcborstream.cpp b/src/corelib/serialization/qcborstream.cpp
index 078c14a32d..c598eee213 100644
--- a/src/corelib/serialization/qcborstream.cpp
+++ b/src/corelib/serialization/qcborstream.cpp
@@ -1972,7 +1972,15 @@ inline void QCborStreamReader::preparse()
if (lastError() == QCborError::NoError) {
type_ = cbor_value_get_type(&d->currentElement);
- if (type_ != CborInvalidType) {
+ if (type_ == CborInvalidType) {
+ // We may have reached the end.
+ if (d->device && d->containerStack.isEmpty()) {
+ d->buffer.clear();
+ if (d->bufferStart)
+ d->device->skip(d->bufferStart);
+ d->bufferStart = 0;
+ }
+ } else {
d->lastError = {};
// Undo the type mapping that TinyCBOR does (we have an explicit type
// for negative integer and we don't have separate types for Boolean,
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 10d97556bc..36fb091ff8 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -2045,6 +2045,23 @@ inline void fetchTransformed_pixelBounds(int max, int l1, int l2, int &v)
}
}
+static inline bool canUseFastMatrixPath(const qreal cx, const qreal cy, const qsizetype length, const QSpanData *data)
+{
+ if (Q_UNLIKELY(!data->fast_matrix))
+ return false;
+
+ qreal fx = (data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale;
+ qreal fy = (data->m22 * cy + data->m12 * cx + data->dy) * fixed_scale;
+ qreal minc = std::min(fx, fy);
+ qreal maxc = std::max(fx, fy);
+ fx += std::trunc(data->m11 * fixed_scale) * length;
+ fy += std::trunc(data->m12 * fixed_scale) * length;
+ minc = std::min(minc, std::min(fx, fy));
+ maxc = std::max(maxc, std::max(fx, fy));
+
+ return minc >= std::numeric_limits<int>::min() && maxc <= std::numeric_limits<int>::max();
+}
+
template<TextureBlendType blendType, QPixelLayout::BPP bpp, typename T>
static void QT_FASTCALL fetchTransformed_fetcher(T *buffer, const QSpanData *data,
int y, int x, int length)
@@ -2062,7 +2079,7 @@ static void QT_FASTCALL fetchTransformed_fetcher(T *buffer, const QSpanData *dat
// When templated 'fetch' should be inlined at compile time:
const FetchPixelFunc fetch = (bpp == QPixelLayout::BPPNone) ? qFetchPixel[layout->bpp] : FetchPixelFunc(fetchPixel<bpp>);
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3016,7 +3033,7 @@ static const uint * QT_FASTCALL fetchTransformedBilinearARGB32PM(uint *buffer, c
uint *end = buffer + length;
uint *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3373,7 +3390,7 @@ static const uint *QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Oper
const qreal cx = x + qreal(0.5);
const qreal cy = y + qreal(0.5);
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
int fdx = (int)(data->m11 * fixed_scale);
int fdy = (int)(data->m12 * fixed_scale);
@@ -3559,7 +3576,7 @@ static const QRgba64 *QT_FASTCALL fetchTransformedBilinear64_uint32(QRgba64 *buf
QRgba64 *end = buffer + length;
QRgba64 *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
const int fdx = (int)(data->m11 * fixed_scale);
const int fdy = (int)(data->m12 * fixed_scale);
@@ -3717,7 +3734,7 @@ static const QRgba64 *QT_FASTCALL fetchTransformedBilinear64_uint64(QRgba64 *buf
QRgba64 *end = buffer + length;
QRgba64 *b = buffer;
- if (data->fast_matrix) {
+ if (canUseFastMatrixPath(cx, cy, length, data)) {
// The increment pr x in the scanline
const int fdx = (int)(data->m11 * fixed_scale);
const int fdy = (int)(data->m12 * fixed_scale);
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro
index 083b7c1655..02e00039ae 100644
--- a/src/plugins/platforms/cocoa/cocoa.pro
+++ b/src/plugins/platforms/cocoa/cocoa.pro
@@ -6,6 +6,7 @@ SOURCES += main.mm \
qcocoatheme.mm \
qcocoabackingstore.mm \
qcocoawindow.mm \
+ qcocoawindowmanager.mm \
qnsview.mm \
qnswindow.mm \
qnswindowdelegate.mm \
@@ -41,6 +42,7 @@ HEADERS += qcocoaintegration.h \
qcocoatheme.h \
qcocoabackingstore.h \
qcocoawindow.h \
+ qcocoawindowmanager.h \
qnsview.h \
qnswindow.h \
qnswindowdelegate.h \
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 009074a5f3..9a2f19c2f2 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -215,25 +215,6 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
connect(qGuiApp, &QGuiApplication::focusWindowChanged,
this, &QCocoaIntegration::focusWindowChanged);
-
- static auto splashScreenHider = QMacKeyValueObserver(NSApp, @"modalWindow", []{
- const QWindowList allWindows = QGuiApplication::topLevelWindows();
- for (QWindow *window : allWindows) {
- if ((window->flags() & Qt::SplashScreen) == Qt::SplashScreen) {
- QCocoaWindow *platformWindow = static_cast<QCocoaWindow*>(window->handle());
- NSWindow *splashWindow = platformWindow->view().window;
- if (!splashWindow)
- continue;
- if (NSApp.modalWindow) {
- NSInteger originalLevel = splashWindow.level;
- splashWindow.level = NSNormalWindowLevel;
- window->setProperty("_q_levelBeforeModalSession", (qlonglong)originalLevel);
- } else if (NSInteger originalLevel = window->property("_q_levelBeforeModalSession").toLongLong()) {
- splashWindow.level = originalLevel;
- }
- }
- }
- });
}
QCocoaIntegration::~QCocoaIntegration()
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
index 464c16d66f..db64702b8d 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
@@ -118,11 +118,13 @@ class QSystemTrayIconSys
public:
QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) {
item = [[QNSStatusItem alloc] initWithSysTray:sys];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
+ NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item;
}
~QSystemTrayIconSys() {
[[[item item] view] setHidden: YES];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ if (center.delegate == item)
+ center.delegate = nil;
[item release];
}
QNSStatusItem *item;
@@ -277,7 +279,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
notification.contentImage = [nsimage autorelease];
}
- [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ center.delegate = m_sys->item;
+ [center deliverNotification:notification];
+ [notification release];
}
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 363a026e71..26df604f1c 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -454,13 +454,35 @@ NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
if (type == Qt::ToolTip)
windowLevel = NSScreenSaverWindowLevel;
- // Any "special" window should be in at least the same level as its parent.
- if (type != Qt::Window) {
- const QWindow * const transientParent = window()->transientParent();
- const QCocoaWindow * const transientParentWindow = transientParent ?
- static_cast<QCocoaWindow *>(transientParent->handle()) : nullptr;
- if (transientParentWindow)
- windowLevel = qMax([transientParentWindow->nativeWindow() level], windowLevel);
+ auto *transientParent = window()->transientParent();
+ if (transientParent && transientParent->handle()) {
+ // We try to keep windows in at least the same window level as
+ // their transient parent. Unfortunately this only works when the
+ // window is created. If the window level changes after that, as
+ // a result of a call to setWindowFlags, or by changing the level
+ // of the native window, we will not pick this up, and the window
+ // will be left behind (or in a different window level than) its
+ // parent. We could KVO-observe the window level of our transient
+ // parent, but that requires us to know when the parent goes away
+ // so that we can unregister the observation before the parent is
+ // dealloced, something we can't do for generic NSWindows. Another
+ // way would be to override [NSWindow setLevel:] and notify child
+ // windows about the change, but that doesn't work for foreign
+ // windows, which can still be transient parents via fromWinId().
+ // One area where this problem is apparent is when AppKit tweaks
+ // the window level of modal windows during application activation
+ // and deactivation. Since we don't pick up on these window level
+ // changes in a generic way, we need to add logic explicitly to
+ // re-evaluate the window level after AppKit has done its tweaks.
+
+ auto *transientCocoaWindow = static_cast<QCocoaWindow *>(transientParent->handle());
+ auto *nsWindow = transientCocoaWindow->nativeWindow();
+
+ // We only upgrade the window level for "special" windows, to work
+ // around Qt Designer parenting the designer windows to the widget
+ // palette window (QTBUG-31779). This should be fixed in designer.
+ if (type != Qt::Window)
+ windowLevel = qMax(windowLevel, nsWindow.level);
}
return windowLevel;
diff --git a/src/plugins/platforms/cocoa/qcocoawindowmanager.h b/src/plugins/platforms/cocoa/qcocoawindowmanager.h
new file mode 100644
index 0000000000..54f17eeccd
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOCOAWINDOWMANAGER_H
+#define QCOCOAWINDOWMANAGER_H
+
+#include <QtCore/qglobal.h>
+
+#include <AppKit/AppKit.h>
+
+QT_BEGIN_NAMESPACE
+
+class QCocoaWindowManager
+{
+public:
+ static QCocoaWindowManager *instance();
+
+private:
+ QCocoaWindowManager();
+ void initialize();
+
+ void modalSessionChanged();
+};
+
+QT_END_NAMESPACE
+
+#endif // QCOCOAWINDOWMANAGER_H
diff --git a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm
new file mode 100644
index 0000000000..879bfaa546
--- /dev/null
+++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoawindowmanager.h"
+#include "qcocoawindow.h"
+
+#include <QtCore/private/qcore_mac_p.h>
+
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qwindow.h>
+
+QT_BEGIN_NAMESPACE
+
+QCocoaWindowManager *QCocoaWindowManager::instance()
+{
+ static auto *instance = new QCocoaWindowManager;
+ return instance;
+}
+
+QCocoaWindowManager::QCocoaWindowManager()
+{
+ if (NSApp) {
+ initialize();
+ } else {
+ static auto applicationDidFinishLaunching(QMacNotificationObserver(nil,
+ NSApplicationDidFinishLaunchingNotification, [this] { initialize(); }));
+ }
+}
+
+void QCocoaWindowManager::initialize()
+{
+ Q_ASSERT(NSApp);
+
+ // Whenever the modalWindow property of NSApplication changes we have a new
+ // modal session running. Observing the app modal window instead of our own
+ // event dispatcher sessions allows us to track session started by native
+ // APIs as well. We need to check the initial state as well, in case there
+ // is already a modal session running.
+ static auto modalSessionObserver(QMacKeyValueObserver(
+ NSApp, @"modalWindow", [this] { modalSessionChanged(); },
+ NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew));
+}
+
+void QCocoaWindowManager::modalSessionChanged()
+{
+ // Make sure that no window is overlapping the modal window. This can
+ // happen for e.g. splash screens, which have the NSPopUpMenuWindowLevel.
+ for (auto *window : QGuiApplication::topLevelWindows()) {
+ auto *platformWindow = static_cast<QCocoaWindow*>(window->handle());
+ if (!platformWindow)
+ continue;
+
+ auto naturalWindowLevel = platformWindow->windowLevel(window->flags());
+ if (naturalWindowLevel > NSModalPanelWindowLevel) {
+ NSWindow *nativeWindow = platformWindow->nativeWindow();
+ if (NSApp.modalWindow) {
+ // Lower window to that of the modal windows, but no less
+ nativeWindow.level = NSModalPanelWindowLevel;
+ [nativeWindow orderBack:nil];
+ } else {
+ // Restore window's natural window level, whatever that was
+ nativeWindow.level = naturalWindowLevel;
+ }
+ }
+ }
+}
+
+static void initializeWindowManager() { Q_UNUSED(QCocoaWindowManager::instance()); }
+Q_CONSTRUCTOR_FUNCTION(initializeWindowManager)
+
+QT_END_NAMESPACE
+