From 0c33a823c560bdf18a513ae460eea4d7bdf9e115 Mon Sep 17 00:00:00 2001
From: Alexander Volkov <a.volkov@rusbitech.ru>
Date: Tue, 24 Nov 2015 15:09:41 +0300
Subject: [PATCH] xcb: Don't cache the screen for a window
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

QXcbWindow::m_xcbScreen was introduced in 4e1b09fa8ff1a9ab42c0a29a2efe1ae7f4700d71
(Keep screen geometries from overlapping) to map the window
geometry for the right screen, because it wasn't possible to
rely on QPlatformWindow::screen().

But we don't need it since a705b4ec1f6f7133390054f8b6b8077ef0550311
(Introduce cross platform high-dpi scaling), because QGuiApplication
triggers GeometryChangeEvent right after processing WindowScreenChangedEvent.

So just use QPlatformWindow::screen() instead of cached m_xcbScreen.

m_xcbScreen was also used in d4bc56cb4218f6f8378f04c23865156b349b037d
(Fix screen detection on configureNotify) to compare the new screen
after receiving ConfigureNotify to the correct old screen. Just send
WindowScreenChangedEvent event and leave making the comparison to
QGuiApplication.

Change-Id: Ibe717ae4bf4c40b0a04cd62fe2ecaee5df5f4060
Reviewed-by: Błażej Szczygieł <spaz16@wp.pl>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
---
 src/plugins/platforms/xcb/qxcbwindow.cpp | 16 ++++++----------
 src/plugins/platforms/xcb/qxcbwindow.h   |  2 --
 2 files changed, 6 insertions(+), 12 deletions(-)

Index: b/src/plugins/platforms/xcb/qxcbwindow.cpp
===================================================================
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -142,7 +142,7 @@ const quint32 XEMBED_VERSION = 0;
 
 QXcbScreen *QXcbWindow::parentScreen()
 {
-    return parent() ? static_cast<QXcbWindow*>(parent())->parentScreen() : m_xcbScreen;
+    return parent() ? static_cast<QXcbWindow*>(parent())->parentScreen() : xcbScreen();
 }
 
 // Returns \c true if we should set WM_TRANSIENT_FOR on \a w
@@ -266,7 +266,6 @@ static const char *wm_window_role_proper
 QXcbWindow::QXcbWindow(QWindow *window)
     : QPlatformWindow(window)
     , m_window(0)
-    , m_xcbScreen(0)
     , m_syncCounter(0)
     , m_gravity(XCB_GRAVITY_STATIC)
     , m_mapped(false)
@@ -322,7 +321,6 @@ void QXcbWindow::create()
     QRect rect = windowGeometry();
     QXcbScreen *platformScreen = parent() ? parentScreen() : static_cast<QXcbScreen*>(screenForGeometry(rect));
 
-    m_xcbScreen = platformScreen;
     if (type == Qt::Desktop) {
         m_window = platformScreen->root();
         m_depth = platformScreen->screen()->root_depth;
@@ -643,13 +641,12 @@ void QXcbWindow::setGeometry(const QRect
 
     propagateSizeHints();
 
-    QXcbScreen *currentScreen = m_xcbScreen;
+    QXcbScreen *currentScreen = xcbScreen();
     QXcbScreen *newScreen = parent() ? parentScreen() : static_cast<QXcbScreen*>(screenForGeometry(rect));
 
     if (!newScreen)
         newScreen = xcbScreen();
 
-    m_xcbScreen = newScreen;
     const QRect wmGeometry = windowToWmGeometry(rect);
 
     if (newScreen && newScreen != currentScreen)
@@ -1957,8 +1954,6 @@ void QXcbWindow::handleConfigureNotifyEv
     const QRect actualGeometry = QRect(pos, QSize(event->width, event->height));
     QPlatformScreen *newScreen = parent() ? parent()->screen() : screenForGeometry(actualGeometry);
 
-    QXcbScreen *currentScreen = m_xcbScreen;
-    m_xcbScreen = static_cast<QXcbScreen*>(newScreen);
     if (!newScreen)
         return;
 
@@ -1972,8 +1967,10 @@ void QXcbWindow::handleConfigureNotifyEv
     // geometry, and may think the requested geometry was fulfilled.
     QWindowSystemInterface::handleGeometryChange(window(), actualGeometry);
 
-    if (newScreen != currentScreen)
-        QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
+    // QPlatformScreen::screen() is updated asynchronously, so we can't compare it
+    // with the newScreen. Just send the WindowScreenChanged event and QGuiApplication
+    // will make the comparison later.
+    QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
 
     // For expose events we have no way of telling QGuiApplication to used the locally
     // cached version of the previous state, so we may in some situations end up with
Index: b/src/plugins/platforms/xcb/qxcbwindow.h
===================================================================
--- a/src/plugins/platforms/xcb/qxcbwindow.h
+++ b/src/plugins/platforms/xcb/qxcbwindow.h
@@ -205,8 +205,6 @@ protected:
 
     xcb_window_t m_window;
 
-    QXcbScreen *m_xcbScreen;
-
     uint m_depth;
     QImage::Format m_imageFormat;
     bool m_imageRgbSwap;
