diff options
author | Liang Qi <liang.qi@qt.io> | 2016-11-16 07:37:38 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-11-16 12:35:36 +0100 |
commit | 90c425642dfeae4564b43dacf15f80479962e910 (patch) | |
tree | 7e51683195210b3c70c04a8a0753ee272af1cd4c /src/plugins/platforms/cocoa/qcocoawindow.mm | |
parent | 1a43199fcea1bcec1ebf1a1a12cd3dcb942d67b4 (diff) | |
parent | 9808b53fde1dfc65ad3757cc6720e430c3cc89a2 (diff) |
Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts:
mkspecs/common/linux-android.conf
src/gui/opengl/qopengl.h
src/network/socket/qnativesocketengine_winrt.cpp
src/network/socket/qnativesocketengine_winrt_p.h
src/plugins/platforms/cocoa/qcocoawindow.mm
src/plugins/platforms/eglfs/api/qeglfsintegration.cpp
src/plugins/platforms/linuxfb/qlinuxfbintegration.cpp
sync.profile
Change-Id: If70aaf2c49df91157b864cf0d7d9513546c9bec4
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index e377d8f83d..602da0a175 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1638,31 +1638,53 @@ QCocoaMenuBar *QCocoaWindow::menubar() const return m_menubar; } -void QCocoaWindow::setWindowCursor(NSCursor *cursor) +// Finds the effective cursor for this window by walking up the +// ancestor chain (including this window) until a set cursor is +// found. Returns nil if there is not set cursor. +NSCursor *QCocoaWindow::effectiveWindowCursor() const { - // This function is called (via QCocoaCursor) by Qt to set - // the cursor for this window. It can be called for a window - // that is not currenly under the mouse pointer (for example - // for a popup window.) Qt expects the set cursor to "stick": - // it should be accociated with the window until a different - // cursor is set. - if (m_windowCursor != cursor) { - [m_windowCursor release]; - m_windowCursor = [cursor retain]; - } - // 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 && window()->type() != Qt::ForeignWindow) { - [m_nsWindow invalidateCursorRectsForView:m_view]; + if (m_windowCursor) + return m_windowCursor; + if (!QPlatformWindow::parent()) + return nil; + return static_cast<QCocoaWindow *>(QPlatformWindow::parent())->effectiveWindowCursor(); +} + +// Applies the cursor as returned by effectiveWindowCursor(), handles +// the special no-cursor-set case by setting the arrow cursor. +void QCocoaWindow::applyEffectiveWindowCursor() +{ + NSCursor *effectiveCursor = effectiveWindowCursor(); + if (effectiveCursor) { + [effectiveCursor set]; } else { - if (m_windowUnderMouse) - [cursor set]; + // We wold like to _unset_ the cursor here; but there is no such + // API. Fall back to setting the default arrow cursor. + [[NSCursor arrowCursor] set]; } } +void QCocoaWindow::setWindowCursor(NSCursor *cursor) +{ + if (m_windowCursor == cursor) + return; + + // Setting a cursor in a foregin view is not supported. + if (window()->type() == Qt::ForeignWindow) + return; + + [m_windowCursor release]; + m_windowCursor = cursor; + [m_windowCursor retain]; + + // The installed view tracking area (see QNSView updateTrackingAreas) will + // handle cursor updates on mouse enter/leave. Handle the case where the + // mouse is on the this window by changing the cursor immediately. + if (m_windowUnderMouse) + applyEffectiveWindowCursor(); +} + void QCocoaWindow::registerTouch(bool enable) { m_registerTouchCount += enable ? 1 : -1; |