diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2012-11-26 15:47:02 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-28 21:09:42 +0100 |
commit | bb38d1b1d527b70aa2ca8d50a6a703d2faa5b8a0 (patch) | |
tree | 43e1bcf2c833b74d5fe18f525ba20b1688debd0a /src/plugins/platforms/cocoa/qnsview.mm | |
parent | a0d379bc9a76dfcce08c69abb30d1fea821fd7d7 (diff) |
Cocoa: update OpenGL viewport when nsview moves
NSOpenGLContext expexts an -update call whenever the
physical position of the view it draws to changes
on screen. Since we don't get geometry callbacks for such
views when the parent view moves, we need to
register a special notification for that case, and
tell Qt that we need to repaint the QWindow that the
view is backing.
This case does not hit very often, but is evident in
MDI applications where the subwindows are OpenGL
backed QGraphicsView widgets. Dragging the subwindows
around produces garbage inside the windows.
Change-Id: I1b162470b03cca6ed722c6c54080459f2c5e91d9
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 68117824db..d2a4685872 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -56,6 +56,7 @@ #include <QtCore/QDebug> #include <private/qguiapplication_p.h> #include "qcocoabackingstore.h" +#include "qcocoaglcontext.h" #ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR #include <accessibilityinspector.h> @@ -81,7 +82,9 @@ static QTouchDevice *touchDevice = 0; m_window = 0; m_buttons = Qt::NoButton; m_sendKeyEvent = false; + m_subscribesForGlobalFrameNotifications = false; currentCustomDragTypes = 0; + if (!touchDevice) { touchDevice = new QTouchDevice; touchDevice->setType(QTouchDevice::TouchPad); @@ -99,6 +102,12 @@ static QTouchDevice *touchDevice = 0; delete[] m_maskData; m_maskData = 0; m_window = 0; + if (m_subscribesForGlobalFrameNotifications) { + m_subscribesForGlobalFrameNotifications = false; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:NSViewGlobalFrameDidChangeNotification + object:self]; +} [super dealloc]; } @@ -140,6 +149,28 @@ static QTouchDevice *touchDevice = 0; return self; } +- (void) setQCocoaGLContext:(QCocoaGLContext *)context +{ + [context->nsOpenGLContext() setView:self]; + if (!m_subscribesForGlobalFrameNotifications) { + // NSOpenGLContext expects us to repaint (or update) the view when + // it changes position on screen. Since this happens unnoticed for + // the view when the parent view moves, we need to register a special + // notification that lets us handle this case: + m_subscribesForGlobalFrameNotifications = true; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(globalFrameChanged:) + name:NSViewGlobalFrameDidChangeNotification + object:self]; + } +} + +- (void) globalFrameChanged:(NSNotification*)notification +{ + Q_UNUSED(notification); + QWindowSystemInterface::handleExposeEvent(m_window, m_window->geometry()); +} + - (void)updateGeometry { QRect geometry; |