From 602bd9873786ccadcb67da3036329f3122555cf8 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 21 May 2013 15:09:28 +0200 Subject: Make QWindow update its screen when moved to a different one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also implements the Cocoa backend for that. Change-Id: I32977e12a04e1cf48b12333442482746c69ce133 Reviewed-by: Samuel Rødal Reviewed-by: Gunnar Sletta --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 16 +++++++++++++++- src/plugins/platforms/cocoa/qcocoaintegration.h | 1 + src/plugins/platforms/cocoa/qnsview.mm | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index f676d613bc..c40ae3d81d 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -100,11 +100,23 @@ static void cleanupCocoaApplicationDelegate() - (id)init { self = [super init]; - if (self) + if (self) { inLaunch = true; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(updateScreens:) + name:NSApplicationDidChangeScreenParametersNotification + object:NSApp]; + } return self; } +- (void)updateScreens:(NSNotification *)notification +{ + if (QCocoaIntegration *ci = dynamic_cast(QGuiApplicationPrivate::platformIntegration())) + ci->updateScreens(); +} + - (void)dealloc { sharedCocoaApplicationDelegate = nil; @@ -114,6 +126,8 @@ static void cleanupCocoaApplicationDelegate() [NSApp setDelegate:reflectionDelegate]; [reflectionDelegate release]; } + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; } diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 6e690dd51e..7831888da1 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -125,6 +125,7 @@ public: QList possibleKeys(const QKeyEvent *event) const; void updateScreens(); + QCocoaScreen *screenAtIndex(int index) const { return mScreens.at(index); } private: diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 6fd5cf59e1..0916a1faa8 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -58,6 +58,7 @@ #include #include "qcocoabackingstore.h" #include "qcocoaglcontext.h" +#include "qcocoaintegration.h" #ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR #include @@ -276,6 +277,15 @@ static QTouchDevice *touchDevice = 0; m_platformWindow->obscureWindow(); } else if ([notificationName isEqualToString: @"NSWindowDidOrderOnScreenAndFinishAnimatingNotification"]) { m_platformWindow->exposeWindow(); + } else if (notificationName == NSWindowDidChangeScreenNotification) { + if (m_window) { + QCocoaIntegration *ci = static_cast(QGuiApplicationPrivate::platformIntegration()); + NSUInteger screenIndex = [[NSScreen screens] indexOfObject:self.window.screen]; + if (screenIndex != NSNotFound) { + QCocoaScreen *cocoaScreen = ci->screenAtIndex(screenIndex); + QWindowSystemInterface::handleWindowScreenChanged(m_window, cocoaScreen->screen()); + } + } } else { #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 -- cgit v1.2.3