summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.h2
-rw-r--r--src/plugins/platforms/cocoa/qcocoabackingstore.mm2
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm45
-rw-r--r--src/plugins/platforms/cocoa/qnsview_mouse.mm42
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.mm4
5 files changed, 70 insertions, 25 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h
index 6f24598250..470da63e3d 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.h
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h
@@ -76,8 +76,10 @@ public:
void endPaint() override;
void flush(QWindow *, const QRegion &, const QPoint &) override;
+#ifndef QT_NO_OPENGL
void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
QPlatformTextureList *textures, bool translucentBackground) override;
+#endif
QPlatformGraphicsBuffer *graphicsBuffer() const override;
diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
index d42a723b47..e786ecb5a5 100644
--- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm
+++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm
@@ -523,6 +523,7 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion &region,
// the window server.
}
+#ifndef QT_NO_OPENGL
void QCALayerBackingStore::composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
QPlatformTextureList *textures, bool translucentBackground)
{
@@ -531,6 +532,7 @@ void QCALayerBackingStore::composeAndFlush(QWindow *window, const QRegion &regio
QPlatformBackingStore::composeAndFlush(window, region, offset, textures, translucentBackground);
}
+#endif
QPlatformGraphicsBuffer *QCALayerBackingStore::graphicsBuffer() const
{
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 298d11fe08..0d7eab9a94 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1208,23 +1208,34 @@ void QCocoaWindow::windowDidChangeScreen()
if (!window())
return;
- const bool wasRunningDisplayLink = static_cast<QCocoaScreen *>(screen())->isRunningDisplayLink();
-
- if (QCocoaScreen *newScreen = QCocoaIntegration::instance()->screenForNSScreen(m_view.window.screen)) {
- if (newScreen == screen()) {
- // Screen properties have changed. Will be handled by
- // NSApplicationDidChangeScreenParametersNotification
- // in QCocoaIntegration::updateScreens().
- return;
- }
-
- qCDebug(lcQpaWindow) << window() << "moved to" << newScreen;
- QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(window(), newScreen->screen());
-
- if (hasPendingUpdateRequest() && wasRunningDisplayLink)
- requestUpdate(); // Restart display-link on new screen
- } else {
- qCWarning(lcQpaWindow) << "Failed to get QCocoaScreen for" << m_view.window.screen;
+ // Note: When a window is resized to 0x0 Cocoa will report the window's screen as nil
+ auto *currentScreen = QCocoaIntegration::instance()->screenForNSScreen(m_view.window.screen);
+ auto *previousScreen = static_cast<QCocoaScreen*>(screen());
+
+ Q_ASSERT_X(!m_view.window.screen || currentScreen,
+ "QCocoaWindow", "Failed to get QCocoaScreen for NSScreen");
+
+ // Note: The previous screen may be the same as the current screen, either because
+ // the screen was just reconfigured, which still results in AppKit sending an
+ // NSWindowDidChangeScreenNotification, because the previous screen was removed,
+ // and we ended up calling QWindow::setScreen to move the window, which doesn't
+ // actually move the window to the new screen, or because we've delivered the
+ // screen change to the top level window, which will make all the child windows
+ // of that window report the new screen when requested via QWindow::screen().
+ // We still need to deliver the screen change in all these cases, as the
+ // device-pixel ratio may have changed, and needs to be delivered to all
+ // windows, both top level and child windows.
+
+ qCDebug(lcQpaWindow) << "Screen changed for" << window() << "from" << previousScreen << "to" << currentScreen;
+ QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(
+ window(), currentScreen ? currentScreen->screen() : nullptr);
+
+ if (currentScreen && hasPendingUpdateRequest()) {
+ // Restart display-link on new screen. We need to do this unconditionally,
+ // since we can't rely on the previousScreen reflecting whether or not the
+ // window actually moved from one screen to another, or just stayed on the
+ // same screen.
+ currentScreen->requestUpdate();
}
}
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm
index 6e3cff2b48..d4419b42a4 100644
--- a/src/plugins/platforms/cocoa/qnsview_mouse.mm
+++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm
@@ -147,9 +147,34 @@
ulong timestamp = [theEvent timestamp] * 1000;
- auto eventType = cocoaEvent2QtMouseEvent(theEvent);
- qCInfo(lcQpaMouse) << "Frame-strut" << eventType << "at" << qtWindowPoint << "with" << m_frameStrutButtons << "in" << self.window;
- QWindowSystemInterface::handleFrameStrutMouseEvent(m_platformWindow->window(), timestamp, qtWindowPoint, qtScreenPoint, m_frameStrutButtons);
+ const auto button = cocoaButton2QtButton(theEvent);
+ auto eventType = [&]() {
+ switch (theEvent.type) {
+ case NSEventTypeLeftMouseDown:
+ case NSEventTypeRightMouseDown:
+ case NSEventTypeOtherMouseDown:
+ return QEvent::NonClientAreaMouseButtonPress;
+
+ case NSEventTypeLeftMouseUp:
+ case NSEventTypeRightMouseUp:
+ case NSEventTypeOtherMouseUp:
+ return QEvent::NonClientAreaMouseButtonRelease;
+
+ case NSEventTypeLeftMouseDragged:
+ case NSEventTypeRightMouseDragged:
+ case NSEventTypeOtherMouseDragged:
+ return QEvent::NonClientAreaMouseMove;
+
+ default:
+ break;
+ }
+
+ return QEvent::None;
+ }();
+
+ qCInfo(lcQpaMouse) << eventType << "at" << qtWindowPoint << "with" << m_frameStrutButtons << "in" << self.window;
+ QWindowSystemInterface::handleFrameStrutMouseEvent(m_platformWindow->window(),
+ timestamp, qtWindowPoint, qtScreenPoint, m_frameStrutButtons, button, eventType);
}
@end
@@ -472,12 +497,15 @@
// uses the legacy cursorRect API, so the cursor is reset to the arrow
// cursor. See rdar://34183708
- if (self.cursor && self.cursor != NSCursor.currentCursor) {
- qCInfo(lcQpaMouse) << "Updating cursor for" << self << "to" << self.cursor;
+ auto previousCursor = NSCursor.currentCursor;
+
+ if (self.cursor)
[self.cursor set];
- } else {
+ else
[super cursorUpdate:theEvent];
- }
+
+ if (NSCursor.currentCursor != previousCursor)
+ qCInfo(lcQpaMouse) << "Cursor update for" << self << "resulted in new cursor" << NSCursor.currentCursor;
}
- (void)mouseMovedImpl:(NSEvent *)theEvent
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
index 087cb3651f..9502a315d8 100644
--- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
@@ -51,7 +51,9 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
static QCocoaWindow *toPlatformWindow(NSWindow *window)
{
- return qnsview_cast(window.contentView).platformWindow;
+ if ([window conformsToProtocol:@protocol(QNSWindowProtocol)])
+ return static_cast<QCocoaNSWindow *>(window).platformWindow;
+ return nullptr;
}
@implementation QNSWindowDelegate