Make QWindow update its screen when moved to a different one
Also implements the Cocoa backend for that. Change-Id: I32977e12a04e1cf48b12333442482746c69ce133 Reviewed-by: Samuel Rødal <samuel.rodal@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
parent
f610814b05
commit
602bd98737
@ -1285,6 +1285,9 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
|
|||||||
case QWindowSystemInterfacePrivate::WindowStateChanged:
|
case QWindowSystemInterfacePrivate::WindowStateChanged:
|
||||||
QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
|
QGuiApplicationPrivate::processWindowStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
|
||||||
break;
|
break;
|
||||||
|
case QWindowSystemInterfacePrivate::WindowScreenChanged:
|
||||||
|
QGuiApplicationPrivate::processWindowScreenChangedEvent(static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
|
||||||
|
break;
|
||||||
case QWindowSystemInterfacePrivate::ApplicationStateChanged:
|
case QWindowSystemInterfacePrivate::ApplicationStateChanged:
|
||||||
QGuiApplicationPrivate::processApplicationStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e));
|
QGuiApplicationPrivate::processApplicationStateChangedEvent(static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e));
|
||||||
break;
|
break;
|
||||||
@ -1655,6 +1658,16 @@ void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
|
||||||
|
{
|
||||||
|
if (QWindow *window = wse->window.data()) {
|
||||||
|
if (QScreen *screen = wse->screen.data())
|
||||||
|
window->d_func()->setScreen(screen, false /* recreate */);
|
||||||
|
else // Fall back to default behavior, and try to find some appropriate screen
|
||||||
|
window->setScreen(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QGuiApplicationPrivate::processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e)
|
void QGuiApplicationPrivate::processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e)
|
||||||
{
|
{
|
||||||
if (e->newState == applicationState)
|
if (e->newState == applicationState)
|
||||||
|
@ -126,6 +126,7 @@ public:
|
|||||||
|
|
||||||
static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
|
static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
|
||||||
static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
|
static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
|
||||||
|
static void processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e);
|
||||||
|
|
||||||
static void processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e);
|
static void processApplicationStateChangedEvent(QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *e);
|
||||||
|
|
||||||
|
@ -345,6 +345,25 @@ void QWindowPrivate::updateVisibility()
|
|||||||
emit q->visibilityChanged(visibility);
|
emit q->visibilityChanged(visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QWindowPrivate::setScreen(QScreen *newScreen, bool recreate)
|
||||||
|
{
|
||||||
|
Q_Q(QWindow);
|
||||||
|
if (newScreen != q->screen()) {
|
||||||
|
const bool shouldRecreate = recreate && platformWindow != 0;
|
||||||
|
if (shouldRecreate)
|
||||||
|
q->destroy();
|
||||||
|
if (screen)
|
||||||
|
q->disconnect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*)));
|
||||||
|
screen = newScreen;
|
||||||
|
if (newScreen) {
|
||||||
|
q->connect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*)));
|
||||||
|
if (shouldRecreate)
|
||||||
|
q->create();
|
||||||
|
}
|
||||||
|
emit q->screenChanged(newScreen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the \a surfaceType of the window.
|
Sets the \a surfaceType of the window.
|
||||||
|
|
||||||
@ -1568,20 +1587,7 @@ void QWindow::setScreen(QScreen *newScreen)
|
|||||||
Q_D(QWindow);
|
Q_D(QWindow);
|
||||||
if (!newScreen)
|
if (!newScreen)
|
||||||
newScreen = QGuiApplication::primaryScreen();
|
newScreen = QGuiApplication::primaryScreen();
|
||||||
if (newScreen != screen()) {
|
d->setScreen(newScreen, true /* recreate */);
|
||||||
const bool wasCreated = d->platformWindow != 0;
|
|
||||||
if (wasCreated)
|
|
||||||
destroy();
|
|
||||||
if (d->screen)
|
|
||||||
disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
|
|
||||||
d->screen = newScreen;
|
|
||||||
if (newScreen) {
|
|
||||||
connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
|
|
||||||
if (wasCreated)
|
|
||||||
create();
|
|
||||||
}
|
|
||||||
emit screenChanged(newScreen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWindow::screenDestroyed(QObject *object)
|
void QWindow::screenDestroyed(QObject *object)
|
||||||
|
@ -127,6 +127,8 @@ public:
|
|||||||
void updateVisibility();
|
void updateVisibility();
|
||||||
void _q_clearAlert();
|
void _q_clearAlert();
|
||||||
|
|
||||||
|
void setScreen(QScreen *newScreen, bool recreate);
|
||||||
|
|
||||||
QWindow::SurfaceType surfaceType;
|
QWindow::SurfaceType surfaceType;
|
||||||
Qt::WindowFlags windowFlags;
|
Qt::WindowFlags windowFlags;
|
||||||
QWindow *parentWindow;
|
QWindow *parentWindow;
|
||||||
|
@ -126,6 +126,13 @@ void QWindowSystemInterface::handleWindowStateChanged(QWindow *tlw, Qt::WindowSt
|
|||||||
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
|
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QWindowSystemInterface::handleWindowScreenChanged(QWindow *tlw, QScreen *screen)
|
||||||
|
{
|
||||||
|
QWindowSystemInterfacePrivate::WindowScreenChangedEvent *e =
|
||||||
|
new QWindowSystemInterfacePrivate::WindowScreenChangedEvent(tlw, screen);
|
||||||
|
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
void QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState newState)
|
void QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState newState)
|
||||||
{
|
{
|
||||||
Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
|
Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
|
||||||
|
@ -138,6 +138,7 @@ public:
|
|||||||
static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason);
|
static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason);
|
||||||
|
|
||||||
static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
|
static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
|
||||||
|
static void handleWindowScreenChanged(QWindow *w, QScreen *newScreen);
|
||||||
|
|
||||||
static void handleApplicationStateChanged(Qt::ApplicationState newState);
|
static void handleApplicationStateChanged(Qt::ApplicationState newState);
|
||||||
|
|
||||||
|
@ -91,7 +91,8 @@ public:
|
|||||||
PlatformPanel = UserInputEvent | 0x17,
|
PlatformPanel = UserInputEvent | 0x17,
|
||||||
ContextMenu = UserInputEvent | 0x18,
|
ContextMenu = UserInputEvent | 0x18,
|
||||||
ApplicationStateChanged = 0x19,
|
ApplicationStateChanged = 0x19,
|
||||||
FlushEvents = 0x20
|
FlushEvents = 0x20,
|
||||||
|
WindowScreenChanged = 0x21
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindowSystemEvent {
|
class WindowSystemEvent {
|
||||||
@ -158,6 +159,16 @@ public:
|
|||||||
Qt::WindowState newState;
|
Qt::WindowState newState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WindowScreenChangedEvent : public WindowSystemEvent {
|
||||||
|
public:
|
||||||
|
WindowScreenChangedEvent(QWindow *w, QScreen *s)
|
||||||
|
: WindowSystemEvent(WindowScreenChanged), window(w), screen(s)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
QPointer<QWindow> window;
|
||||||
|
QPointer<QScreen> screen;
|
||||||
|
};
|
||||||
|
|
||||||
class ApplicationStateChangedEvent : public WindowSystemEvent {
|
class ApplicationStateChangedEvent : public WindowSystemEvent {
|
||||||
public:
|
public:
|
||||||
ApplicationStateChangedEvent(Qt::ApplicationState newState)
|
ApplicationStateChangedEvent(Qt::ApplicationState newState)
|
||||||
|
@ -100,11 +100,23 @@ static void cleanupCocoaApplicationDelegate()
|
|||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self)
|
if (self) {
|
||||||
inLaunch = true;
|
inLaunch = true;
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(updateScreens:)
|
||||||
|
name:NSApplicationDidChangeScreenParametersNotification
|
||||||
|
object:NSApp];
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateScreens:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
if (QCocoaIntegration *ci = dynamic_cast<QCocoaIntegration *>(QGuiApplicationPrivate::platformIntegration()))
|
||||||
|
ci->updateScreens();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
sharedCocoaApplicationDelegate = nil;
|
sharedCocoaApplicationDelegate = nil;
|
||||||
@ -114,6 +126,8 @@ static void cleanupCocoaApplicationDelegate()
|
|||||||
[NSApp setDelegate:reflectionDelegate];
|
[NSApp setDelegate:reflectionDelegate];
|
||||||
[reflectionDelegate release];
|
[reflectionDelegate release];
|
||||||
}
|
}
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +125,7 @@ public:
|
|||||||
QList<int> possibleKeys(const QKeyEvent *event) const;
|
QList<int> possibleKeys(const QKeyEvent *event) const;
|
||||||
|
|
||||||
void updateScreens();
|
void updateScreens();
|
||||||
|
QCocoaScreen *screenAtIndex(int index) const { return mScreens.at(index); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
#include <private/qguiapplication_p.h>
|
#include <private/qguiapplication_p.h>
|
||||||
#include "qcocoabackingstore.h"
|
#include "qcocoabackingstore.h"
|
||||||
#include "qcocoaglcontext.h"
|
#include "qcocoaglcontext.h"
|
||||||
|
#include "qcocoaintegration.h"
|
||||||
|
|
||||||
#ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR
|
#ifdef QT_COCOA_ENABLE_ACCESSIBILITY_INSPECTOR
|
||||||
#include <accessibilityinspector.h>
|
#include <accessibilityinspector.h>
|
||||||
@ -276,6 +277,15 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
m_platformWindow->obscureWindow();
|
m_platformWindow->obscureWindow();
|
||||||
} else if ([notificationName isEqualToString: @"NSWindowDidOrderOnScreenAndFinishAnimatingNotification"]) {
|
} else if ([notificationName isEqualToString: @"NSWindowDidOrderOnScreenAndFinishAnimatingNotification"]) {
|
||||||
m_platformWindow->exposeWindow();
|
m_platformWindow->exposeWindow();
|
||||||
|
} else if (notificationName == NSWindowDidChangeScreenNotification) {
|
||||||
|
if (m_window) {
|
||||||
|
QCocoaIntegration *ci = static_cast<QCocoaIntegration *>(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 {
|
} else {
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user