summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnswindowdelegate.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qnswindowdelegate.mm')
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.mm75
1 files changed, 56 insertions, 19 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
index 057a4c2943..14f1ca0114 100644
--- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
@@ -39,30 +39,27 @@
#include "qnswindowdelegate.h"
#include "qcocoahelpers.h"
+#include "qcocoawindow.h"
#include "qcocoascreen.h"
#include <QDebug>
+#include <QtCore/private/qcore_mac_p.h>
#include <qpa/qplatformscreen.h>
#include <qpa/qwindowsysteminterface.h>
static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
-@implementation QNSWindowDelegate
-
-- (id)initWithQCocoaWindow:(QCocoaWindow *)cocoaWindow
+static QCocoaWindow *toPlatformWindow(NSWindow *window)
{
- if (self = [super init])
- m_cocoaWindow = cocoaWindow;
-
- return self;
+ return qnsview_cast(window.contentView).platformWindow;
}
-- (BOOL)windowShouldClose:(NSNotification *)notification
+@implementation QNSWindowDelegate
+
+- (BOOL)windowShouldClose:(NSWindow *)window
{
- Q_UNUSED(notification);
- if (m_cocoaWindow) {
- return m_cocoaWindow->windowShouldClose();
- }
+ if (QCocoaWindow *platformWindow = toPlatformWindow(window))
+ return platformWindow->windowShouldClose();
return YES;
}
@@ -76,14 +73,16 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)proposedFrame
{
Q_UNUSED(proposedFrame);
- Q_ASSERT(window == m_cocoaWindow->nativeWindow());
- const QWindow *w = m_cocoaWindow->window();
+
+ QCocoaWindow *platformWindow = toPlatformWindow(window);
+ Q_ASSERT(platformWindow);
+ const QWindow *w = platformWindow->window();
// maximumSize() refers to the client size, but AppKit expects the full frame size
QSizeF maximumSize = w->maximumSize() + QSize(0, w->frameMargins().top());
// The window should never be larger than the current screen geometry
- const QRectF screenGeometry = m_cocoaWindow->screen()->geometry();
+ const QRectF screenGeometry = platformWindow->screen()->geometry();
maximumSize = maximumSize.boundedTo(screenGeometry.size());
// Use the current frame position for the initial maximized frame,
@@ -103,25 +102,63 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
return QCocoaScreen::mapToNative(maximizedFrame);
}
+#pragma clang diagnostic push
+// NSDisableScreenUpdates and NSEnableScreenUpdates are deprecated, but the
+// NSAnimationContext API that replaces them doesn't handle the use-case of
+// cross-thread screen update synchronization.
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)frameSize
+{
+ Q_ASSERT(toPlatformWindow(window));
+
+ qCDebug(lcQpaWindow) << window << "will resize to" << QSizeF::fromCGSize(frameSize)
+ << "- disabling screen updates temporarily";
+
+ // There may be separate threads rendering to CA layers in this window,
+ // and if any of them do a swap while the resize is still in progress,
+ // the visual bounds of that layer will be updated before the visual
+ // bounds of the window frame, resulting in flickering while resizing.
+
+ // To prevent this we disable screen updates for the whole process until
+ // the resize is complete, which makes the whole thing visually atomic.
+ NSDisableScreenUpdates();
+
+ return frameSize;
+}
+
+- (void)windowDidResize:(NSNotification *)notification
+{
+ NSWindow *window = notification.object;
+ Q_ASSERT(toPlatformWindow(window));
+
+ qCDebug(lcQpaWindow) << window << "was resized - re-enabling screen updates";
+ NSEnableScreenUpdates();
+}
+#pragma clang diagnostic pop
+
- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
{
- Q_UNUSED(window);
Q_UNUSED(menu);
+ QCocoaWindow *platformWindow = toPlatformWindow(window);
+ Q_ASSERT(platformWindow);
+
// Only pop up document path if the filename is non-empty. We allow whitespace, to
// allow faking a window icon by setting the file path to a single space character.
- return !whitespaceRegex.exactMatch(m_cocoaWindow->window()->filePath());
+ return !whitespaceRegex.exactMatch(platformWindow->window()->filePath());
}
- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard
{
- Q_UNUSED(window);
Q_UNUSED(event);
Q_UNUSED(dragImageLocation);
Q_UNUSED(pasteboard);
+ QCocoaWindow *platformWindow = toPlatformWindow(window);
+ Q_ASSERT(platformWindow);
+
// Only allow drag if the filename is non-empty. We allow whitespace, to
// allow faking a window icon by setting the file path to a single space.
- return !whitespaceRegex.exactMatch(m_cocoaWindow->window()->filePath());
+ return !whitespaceRegex.exactMatch(platformWindow->window()->filePath());
}
@end