From 9ec028071409410dba192ec1c1e228cf3aea224b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Fiestas?= Date: Fri, 13 Jan 2017 01:33:42 +0100 Subject: Make sure QWindow screen is set before calling QPlatformWindow::create MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWindow uses device independent geometry while QXcb and QPlatform classes do not. When QXcbWindow::create is called we have no guarantee that the correct screen has been set in QWindow so the code attempts to check if "currentScreen" matches "actualscreen". To perform that operation though we need to convert the units from "Device independent" to "native pixels" that we do by calling QPlatformWindow::windowGeometry which calls QHighDpiScaling::toNativePixels which requires the correct screen to be already set. So basically we have a cyclic dependency, to get the correct screen we require the correct screen to be already set. To fix this we can: 1-Remove the dependency (Look for the actual screen using device independent pixels) This will imply adding code in QXcb to use QPlatformScreen::deviceIndependentGeometry to lookup the screen up 2-Make sure the Screen is set before calling QXcbWindow::create This patch implements the first approach that allows us to keep the changes within the QXcb backend which seems to be the only one affected. Task-number: QTBUG-53813 Change-Id: I6dc955d63e17c3b3421f3a1a9e0d841e508b2e5c Reviewed-by: David Edmundson Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/xcb/qxcbwindow.cpp | 12 ++++++++++-- src/plugins/platforms/xcb/qxcbwindow.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 6365a6e9cb..289d0720e7 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -156,6 +156,14 @@ QXcbScreen *QXcbWindow::parentScreen() return parent() ? static_cast(parent())->parentScreen() : xcbScreen(); } +//QPlatformWindow::screenForGeometry version that uses deviceIndependentGeometry +QXcbScreen *QXcbWindow::initialScreen() const +{ + QWindowPrivate *windowPrivate = qt_window_private(window()); + QScreen *screen = windowPrivate->screenForGeometry(window()->geometry()); + return static_cast(screen->handle()); +} + // Returns \c true if we should set WM_TRANSIENT_FOR on \a w static inline bool isTransient(const QWindow *w) { @@ -350,8 +358,8 @@ void QXcbWindow::create() Qt::WindowType type = window()->type(); QXcbScreen *currentScreen = xcbScreen(); - QRect rect = windowGeometry(); - QXcbScreen *platformScreen = parent() ? parentScreen() : static_cast(screenForGeometry(rect)); + QXcbScreen *platformScreen = parent() ? parentScreen() : initialScreen(); + QRect rect = QHighDpi::toNativePixels(window()->geometry(), platformScreen); if (type == Qt::Desktop) { m_window = platformScreen->root(); diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index b4d947e700..56628094ee 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -191,6 +191,7 @@ protected: QXcbScreen *parentScreen(); + QXcbScreen *initialScreen() const; void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0); NetWmStates netWmStates(); void setNetWmStates(NetWmStates); -- cgit v1.2.3