summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-12 13:53:21 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-12 13:53:22 +0100
commitd3b3be6865b78479da6c7e822b80064a6ea08554 (patch)
tree4843426950d1bc933ee8685c94f8905f20f3d678 /src/plugins/platforms/cocoa
parent7472415f3f331ccd415cc644cc210d2457ef690c (diff)
parentfd88c152db0949e47613858a914a6ae4a825781d (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoascreen.mm4
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm16
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm8
-rw-r--r--src/plugins/platforms/cocoa/qnsview_mouse.mm66
5 files changed, 56 insertions, 39 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm
index afe14e623c..36c11ba8af 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.mm
+++ b/src/plugins/platforms/cocoa/qcocoascreen.mm
@@ -330,7 +330,7 @@ void QCocoaScreen::deliverUpdateRequests()
auto windows = QGuiApplication::allWindows();
for (int i = 0; i < windows.size(); ++i) {
QWindow *window = windows.at(i);
- QPlatformWindow *platformWindow = window->handle();
+ auto *platformWindow = static_cast<QCocoaWindow*>(window->handle());
if (!platformWindow)
continue;
@@ -341,7 +341,7 @@ void QCocoaScreen::deliverUpdateRequests()
continue;
// Skip windows that are not doing update requests via display link
- if (!(window->format().swapInterval() > 0))
+ if (!platformWindow->updatesWithDisplayLink())
continue;
platformWindow->deliverUpdateRequest();
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index 8f1bdb8af0..0a913ef66e 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -129,6 +129,7 @@ public:
bool isForeignWindow() const override;
void requestUpdate() override;
+ bool updatesWithDisplayLink() const;
void deliverUpdateRequest() override;
void requestActivateWindow() override;
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index beb17ec44e..bf0a1216be 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1102,6 +1102,9 @@ void QCocoaWindow::setEmbeddedInForeignView()
void QCocoaWindow::viewDidChangeFrame()
{
+ if (isContentView())
+ return; // Handled below
+
handleGeometryChange();
}
@@ -1474,11 +1477,10 @@ void QCocoaWindow::recreateWindowIfNeeded()
void QCocoaWindow::requestUpdate()
{
- const int swapInterval = format().swapInterval();
- qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window() << "swapInterval" << swapInterval;
+ qCDebug(lcQpaDrawing) << "QCocoaWindow::requestUpdate" << window()
+ << "using" << (updatesWithDisplayLink() ? "display-link" : "timer");
- if (swapInterval > 0) {
- // Vsync is enabled, deliver via CVDisplayLink
+ if (updatesWithDisplayLink()) {
static_cast<QCocoaScreen *>(screen())->requestUpdate();
} else {
// Fall back to the un-throttled timer-based callback
@@ -1486,6 +1488,12 @@ void QCocoaWindow::requestUpdate()
}
}
+bool QCocoaWindow::updatesWithDisplayLink() const
+{
+ // Update via CVDisplayLink if Vsync is enabled
+ return format().swapInterval() != 0;
+}
+
void QCocoaWindow::deliverUpdateRequest()
{
// Don't send update requests for views that need display, as the update
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 7f826942f3..17063f6e92 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -85,6 +85,7 @@
@end
@interface QT_MANGLE_NAMESPACE(QNSView) (Mouse)
+- (void)initMouse;
- (NSPoint)screenMousePoint:(NSEvent *)theEvent;
- (void)mouseMovedImpl:(NSEvent *)theEvent;
- (void)mouseEnteredImpl:(NSEvent *)theEvent;
@@ -114,7 +115,6 @@
@implementation QT_MANGLE_NAMESPACE(QNSView) {
QPointer<QCocoaWindow> m_platformWindow;
- NSTrackingArea *m_trackingArea;
Qt::MouseButtons m_buttons;
Qt::MouseButtons m_acceptedMouseDowns;
Qt::MouseButtons m_frameStrutButtons;
@@ -150,7 +150,6 @@
m_currentlyInterpretedKeyEvent = nil;
m_dontOverrideCtrlLMB = qt_mac_resolveOption(false, platformWindow->window(),
"_q_platform_MacDontOverrideCtrlLMB", "QT_MAC_DONT_OVERRIDE_CTRL_LMB");
- m_trackingArea = nil;
self.focusRingType = NSFocusRingTypeNone;
self.cursor = nil;
@@ -159,6 +158,7 @@
self.previousWindow = nil;
[self initDrawing];
+ [self initMouse];
[self registerDragTypes];
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -173,10 +173,6 @@
{
qCDebug(lcQpaWindow) << "Deallocating" << self;
- if (m_trackingArea) {
- [self removeTrackingArea:m_trackingArea];
- [m_trackingArea release];
- }
[m_inputSource release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[m_mouseMoveHelper release];
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm
index 3d6471005d..49c94f18db 100644
--- a/src/plugins/platforms/cocoa/qnsview_mouse.mm
+++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm
@@ -39,6 +39,22 @@
// This file is included from qnsview.mm, and only used to organize the code
+/*
+ The reason for using this helper is to ensure that QNSView doesn't implement
+ the NSResponder callbacks for mouseEntered, mouseExited, and mouseMoved.
+
+ If it did, we would get mouse events though the responder chain as well,
+ for example if a subview has a tracking area of its own and calls super
+ in the handler, which results in forwarding the event though the responder
+ chain. The same applies if NSWindow.acceptsMouseMovedEvents is YES.
+
+ By having a helper as the target for our tracking areas, we know for sure
+ that the events we are getting stem from our own tracking areas.
+
+ FIXME: Ideally we wouldn't need this workaround, and would correctly
+ interact with the responder chain by e.g. calling super if Qt does not
+ accept the mouse event
+*/
@implementation QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) {
QNSView *view;
}
@@ -135,6 +151,28 @@
@implementation QT_MANGLE_NAMESPACE(QNSView) (Mouse)
+- (void)initMouse
+{
+ NSUInteger trackingOptions = NSTrackingActiveInActiveApp
+ | NSTrackingMouseEnteredAndExited | NSTrackingCursorUpdate;
+
+ // Ideally, NSTrackingMouseMoved should be turned on only if QWidget::mouseTracking
+ // is enabled, hover is on, or a tool tip is set. Unfortunately, Qt will send "tooltip"
+ // events on mouse moves, so we need to turn it on in ALL case. That means EVERY QWindow
+ // gets to pay the cost of mouse moves delivered to it (Apple recommends keeping it OFF
+ // because there is a performance hit).
+ trackingOptions |= NSTrackingMouseMoved;
+
+ // Using NSTrackingInVisibleRect means AppKit will automatically synchronize the
+ // tracking rect with changes in the view's visible area, so leave it undefined.
+ trackingOptions |= NSTrackingInVisibleRect;
+ static const NSRect trackingRect = NSZeroRect;
+
+ QMacAutoReleasePool pool;
+ [self addTrackingArea:[[[NSTrackingArea alloc] initWithRect:trackingRect
+ options:trackingOptions owner:m_mouseMoveHelper userInfo:nil] autorelease]];
+}
+
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
Q_UNUSED(theEvent)
@@ -406,35 +444,9 @@
[super otherMouseUp:theEvent];
}
-- (void)updateTrackingAreas
-{
- [super updateTrackingAreas];
-
- QMacAutoReleasePool pool;
-
- // NSTrackingInVisibleRect keeps care of updating once the tracking is set up, so bail out early
- if (m_trackingArea && [[self trackingAreas] containsObject:m_trackingArea])
- return;
-
- // Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should
- // only be turned on if mouseTracking, hover is on or a tool tip is set.
- // Unfortunately, Qt will send "tooltip" events on mouse moves, so we need to
- // turn it on in ALL case. That means EVERY QWindow gets to pay the cost of
- // mouse moves delivered to it (Apple recommends keeping it OFF because there
- // is a performance hit). So it goes.
- NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
- | NSTrackingInVisibleRect | NSTrackingMouseMoved | NSTrackingCursorUpdate;
- [m_trackingArea release];
- m_trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame]
- options:trackingOptions
- owner:m_mouseMoveHelper
- userInfo:nil];
- [self addTrackingArea:m_trackingArea];
-}
-
- (void)cursorUpdate:(NSEvent *)theEvent
{
- qCDebug(lcQpaMouse) << "[QNSView cursorUpdate:]" << self.cursor;
+ qCDebug(lcQpaMouse) << "Updating cursor for" << self << "to" << self.cursor;
// Note: We do not get this callback when moving from a subview that
// uses the legacy cursorRect API, so the cursor is reset to the arrow