From 9e6f0f16ab9d6c5fca1ded90dd6b3feb953712e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 29 Jan 2014 17:29:39 +0100 Subject: Cocoa: Add improved cursor updating code path. It's possible to use the cursorRect API in the cases where QCocoaWindow has a NSWindow. This is true for all top-level QCococaWindows today. Task-number: QTBUG-35659 Change-Id: Iefb2c1c022448e19a9c005a808e0c81abe9281ea Reviewed-by: Gabriel de Dietrich Reviewed-by: Eike Ziller --- src/plugins/platforms/cocoa/qcocoawindow.mm | 16 +++++++++++----- src/plugins/platforms/cocoa/qnsview.mm | 12 +++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 17f5f4888d..8becfb1cc2 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1314,12 +1314,18 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) // it should be accociated with the window until a different // cursor is set. - // Cocoa has different abstractions. We can set the cursor *now*: - if (m_windowUnderMouse) - [cursor set]; - // or we can set the cursor on mouse enter/leave using tracking - // areas. This is done in QNSView, save the cursor: m_windowCursor = cursor; + + // Use the built in cursor rect API if the QCocoaWindow has a NSWindow. + // Othervise, set the cursor if this window is under the mouse. In + // this case QNSView::cursorUpdate will set the cursor as the pointer + // moves. + if (m_nsWindow && m_qtView) { + [m_nsWindow invalidateCursorRectsForView : m_qtView]; + } else { + if (m_windowUnderMouse) + [cursor set]; + } } void QCocoaWindow::registerTouch(bool enable) diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 7cd74c6725..b272b4920b 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -706,8 +706,18 @@ static QTouchDevice *touchDevice = 0; -(void)cursorUpdate:(NSEvent *)theEvent { Q_UNUSED(theEvent) - if (m_platformWindow->m_windowCursor) + // Set the cursor manually if there is no NSWindow. + if (!m_platformWindow->m_nsWindow && m_platformWindow->m_windowCursor) [m_platformWindow->m_windowCursor set]; + else + [super cursorUpdate:theEvent]; +} + +-(void)resetCursorRects +{ + // Use the cursor rect API if there is a NSWindow + if (m_platformWindow->m_nsWindow && m_platformWindow->m_windowCursor) + [self addCursorRect:[self visibleRect] cursor:m_platformWindow->m_windowCursor]; } - (void)mouseMoved:(NSEvent *)theEvent -- cgit v1.2.3