0001-Windows-Add-checks-to-usages-of-QWindow-screen.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 78b2719b04f1177b5af0f52fce98316505f9000b Mon Sep 17 00:00:00 2001
  2. From: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
  3. Date: Tue, 22 Sep 2015 12:21:29 +0200
  4. Subject: [PATCH] Windows: Add checks to usages of QWindow::screen().
  5. Default to primary screen and handle situations where the screen
  6. is null consistently. Remove unused QWindowsScreen::screenOf() method.
  7. Task-number: QTBUG-48288
  8. Change-Id: I91b3c2331521d9d3be8ac77606ee820cd35ebb0f
  9. Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
  10. ---
  11. src/plugins/platforms/windows/qwindowsmousehandler.cpp | 14 ++++++++++++--
  12. src/plugins/platforms/windows/qwindowsscreen.cpp | 12 ------------
  13. src/plugins/platforms/windows/qwindowsscreen.h | 2 --
  14. src/plugins/platforms/windows/qwindowswindow.cpp | 12 +++++++++---
  15. 4 files changed, 21 insertions(+), 19 deletions(-)
  16. diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
  17. index 4ab861a..90cb6fe 100644
  18. --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp
  19. +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
  20. @@ -477,7 +477,12 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
  21. typedef QList<QWindowSystemInterface::TouchPoint> QTouchPointList;
  22. Q_ASSERT(m_touchDevice);
  23. - const QRect screenGeometry = window->screen()->geometry();
  24. + const QScreen *screen = window->screen();
  25. + if (!screen)
  26. + screen = QGuiApplication::primaryScreen();
  27. + if (!screen)
  28. + return true;
  29. + const QRect screenGeometry = screen->geometry();
  30. const int winTouchPointCount = msg.wParam;
  31. QScopedArrayPointer<TOUCHINPUT> winTouchInputs(new TOUCHINPUT[winTouchPointCount]);
  32. @@ -569,7 +574,12 @@ bool QWindowsMouseHandler::translateGestureEvent(QWindow *window, HWND hwnd,
  33. if (gi.dwID != GID_DIRECTMANIPULATION)
  34. return true;
  35. static QPoint lastTouchPos;
  36. - const QRect screenGeometry = window->screen()->geometry();
  37. + const QScreen *screen = window->screen();
  38. + if (!screen)
  39. + screen = QGuiApplication::primaryScreen();
  40. + if (!screen)
  41. + return true;
  42. + const QRect screenGeometry = screen->geometry();
  43. QWindowSystemInterface::TouchPoint touchPoint;
  44. static QWindowSystemInterface::TouchPoint touchPoint2;
  45. touchPoint.id = 0;//gi.dwInstanceID;
  46. diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
  47. index 391735a..e6abfb2 100644
  48. --- a/src/plugins/platforms/windows/qwindowsscreen.cpp
  49. +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
  50. @@ -276,18 +276,6 @@ QWindow *QWindowsScreen::windowAt(const QPoint &screenPoint, unsigned flags)
  51. return result;
  52. }
  53. -QWindowsScreen *QWindowsScreen::screenOf(const QWindow *w)
  54. -{
  55. - if (w)
  56. - if (const QScreen *s = w->screen())
  57. - if (QPlatformScreen *pscr = s->handle())
  58. - return static_cast<QWindowsScreen *>(pscr);
  59. - if (const QScreen *ps = QGuiApplication::primaryScreen())
  60. - if (QPlatformScreen *ppscr = ps->handle())
  61. - return static_cast<QWindowsScreen *>(ppscr);
  62. - return 0;
  63. -}
  64. -
  65. qreal QWindowsScreen::pixelDensity() const
  66. {
  67. const qreal physicalDpi = m_data.geometry.width() / m_data.physicalSizeMM.width() * qreal(25.4);
  68. diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h
  69. index 67e7ff6..bc8fbf5 100644
  70. --- a/src/plugins/platforms/windows/qwindowsscreen.h
  71. +++ b/src/plugins/platforms/windows/qwindowsscreen.h
  72. @@ -79,8 +79,6 @@ public:
  73. explicit QWindowsScreen(const QWindowsScreenData &data);
  74. - static QWindowsScreen *screenOf(const QWindow *w = 0);
  75. -
  76. QRect geometry() const Q_DECL_OVERRIDE { return m_data.geometry; }
  77. QRect availableGeometry() const Q_DECL_OVERRIDE { return m_data.availableGeometry; }
  78. int depth() const Q_DECL_OVERRIDE { return m_data.depth; }
  79. diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
  80. index 5318360..abfddcf 100644
  81. --- a/src/plugins/platforms/windows/qwindowswindow.cpp
  82. +++ b/src/plugins/platforms/windows/qwindowswindow.cpp
  83. @@ -1637,8 +1637,12 @@ void QWindowsWindow::setWindowState(Qt::WindowState state)
  84. bool QWindowsWindow::isFullScreen_sys() const
  85. {
  86. const QWindow *w = window();
  87. - return w->isTopLevel()
  88. - && geometry_sys() == QHighDpi::toNativePixels(w->screen()->geometry(), w);
  89. + if (!w->isTopLevel())
  90. + return false;
  91. + const QScreen *screen = w->screen();
  92. + if (!screen)
  93. + screen = QGuiApplication::primaryScreen();
  94. + return screen && geometry_sys() == QHighDpi::toNativePixels(screen->geometry(), w);
  95. }
  96. /*!
  97. @@ -1708,7 +1712,9 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState)
  98. // Use geometry of QWindow::screen() within creation or the virtual screen the
  99. // window is in (QTBUG-31166, QTBUG-30724).
  100. const QScreen *screen = window()->screen();
  101. - const QRect r = QHighDpi::toNativePixels(screen->geometry(), window());
  102. + if (!screen)
  103. + screen = QGuiApplication::primaryScreen();
  104. + const QRect r = screen ? QHighDpi::toNativePixels(screen->geometry(), window()) : m_savedFrameGeometry;
  105. const UINT swpf = SWP_FRAMECHANGED | SWP_NOACTIVATE;
  106. const bool wasSync = testFlag(SynchronousGeometryChangeEvent);
  107. setFlag(SynchronousGeometryChangeEvent);
  108. --
  109. 2.5.1