diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-04 10:39:19 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-07 13:08:46 +0200 |
commit | 3f60bd305ad3b094356750c21e253704bbe62681 (patch) | |
tree | 27e3a6b3e686482326913a5e8ed0347049b06906 | |
parent | 16baadab11341e671150932fd28cff466a4fc041 (diff) |
Add convenience function for checking screen changes to QPlatformWindow.
Add function returning the screen for a new geometry for geometry
change events. This ensures that the checking is done in platform
screen coordinates (which might differ from QScreen coordinates
due to high-DPI changes) and also that no screen changes are
emitted for child windows.
Change-Id: I406750f59f006f834c386d09c0c85a804014924a
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
-rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 23 | ||||
-rw-r--r-- | src/gui/kernel/qplatformwindow.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 28 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 12 |
4 files changed, 31 insertions, 33 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index faaf418522..bb7b690992 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -474,6 +474,29 @@ QString QPlatformWindow::formatWindowTitle(const QString &title, const QString & } /*! + Helper function for finding the new screen for \a newGeometry in response to + a geometry changed event. Returns the new screen if the window was moved to + another virtual sibling. If the screen changes, the platform plugin should call + QWindowSystemInterface::handleWindowScreenChanged(). + \note: The current screen will always be returned for child windows since + they should never signal screen changes. + + \since 5.4 + \sa QWindowSystemInterface::handleWindowScreenChanged() +*/ +QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) const +{ + QPlatformScreen *currentScreen = screen(); + if (!parent() && !currentScreen->geometry().intersects(newGeometry)) { + Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) { + if (screen->geometry().intersects(newGeometry)) + return screen; + } + } + return currentScreen; +} + +/*! Reimplement this method to set whether the window demands attention (for example, by flashing the taskbar icon) depending on \a enabled. diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index 39bd8324a0..8f0e5ff352 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -139,6 +139,7 @@ public: protected: static QString formatWindowTitle(const QString &title, const QString &separator); + QPlatformScreen *screenForGeometry(const QRect &newGeometry) const; QScopedPointer<QPlatformWindowPrivate> d_ptr; private: diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7d0b00b312..51497b3300 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1376,25 +1376,6 @@ void QWindowsWindow::handleResized(int wParam) } } -// Return the effective screen for full screen mode in a virtual desktop. -static QScreen *effectiveScreen(const QWindow *w) -{ - QRect geometry = w->geometry(); - if (!w->isTopLevel()) - geometry.moveTopLeft(w->mapToGlobal(geometry.topLeft())); - - QScreen *screen = w->screen(); - if (!screen->geometry().intersects(geometry)) { - foreach (QScreen *sibling, screen->virtualSiblings()) { - if (sibling->geometry().intersects(geometry)) { - screen = sibling; - break; - } - } - } - return screen; -} - void QWindowsWindow::handleGeometryChange() { //Prevent recursive resizes for Windows CE @@ -1411,12 +1392,9 @@ void QWindowsWindow::handleGeometryChange() fireExpose(QRegion(m_data.geometry), true); } if (previousGeometry.topLeft() != m_data.geometry.topLeft()) { - QWindow *w = window(); - if (w->isTopLevel()) { - QScreen *newScreen = effectiveScreen(w); - if (newScreen != w->screen()) - QWindowSystemInterface::handleWindowScreenChanged(w, newScreen); - } + QPlatformScreen *newScreen = screenForGeometry(m_data.geometry); + if (newScreen != screen()) + QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen()); } if (testFlag(SynchronousGeometryChangeEvent)) QWindowSystemInterface::flushWindowSystemEvents(); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 0cc8c8dbfe..578b4d6ec1 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1842,14 +1842,10 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t * QPlatformWindow::setGeometry(rect); QWindowSystemInterface::handleGeometryChange(window(), rect); - if (!m_screen->availableGeometry().intersects(rect)) { - Q_FOREACH (QPlatformScreen* screen, m_screen->virtualSiblings()) { - if (screen->availableGeometry().intersects(rect)) { - m_screen = static_cast<QXcbScreen*>(screen); - QWindowSystemInterface::handleWindowScreenChanged(window(), m_screen->QPlatformScreen::screen()); - break; - } - } + QPlatformScreen *newScreen = screenForGeometry(rect); + if (newScreen != m_screen) { + m_screen = static_cast<QXcbScreen*>(newScreen); + QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen()); } m_configureNotifyPending = false; |