diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-03-20 17:30:26 +0100 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-04-14 15:12:30 +0000 |
commit | 4e1b09fa8ff1a9ab42c0a29a2efe1ae7f4700d71 (patch) | |
tree | 67c75c66f6ba4b236943b254717221b959f09997 /src/plugins/platforms/xcb/qxcbscreen.cpp | |
parent | a02c04a51b34fc780fa680383f2aee3b3f37fa51 (diff) |
Keep screen geometries from overlapping
The simple mapping of dividing each position by the
devicePixelRatio does not work when screens have different
DPR. If the low-DPR screen above or to the left of the high-DPR
screen, the geometries will overlap in the Qt coordinate system.
This change introduces a new mapping where the origin of each screen
does not move. This mapping is not perfect: it will have gaps between
contiguous screens. However, it will keep non-overlapping screens
non-overlapping in the Qt coordinate system.
Since there is no longer a simple linear coordinate transform, we
have to add screen-dependent mapping functions, and distinguish between
local and non-local coordinates. A side benefit is that the code is
now easier to read, since we remove most manual coordinate transformation.
We also have to cache the screen of each window: since we send resize events
before screen change events, we cannot rely on QPlatformWindow::screen()
(which is set from the screen change event).
Task-number: QTBUG-45076
Change-Id: Ie95a0b71ae274e02903caa102a98af2050a44129
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbscreen.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbscreen.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index fcf70f3c51..bcaa13eb1e 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -273,6 +273,31 @@ QWindow *QXcbScreen::topLevelAt(const QPoint &p) const return 0; } + +QPoint QXcbScreen::mapToNative(const QPoint &pos) const +{ + const int dpr = int(devicePixelRatio()); + return (pos - m_geometry.topLeft()) * dpr + m_nativeGeometry.topLeft(); +} + +QPoint QXcbScreen::mapFromNative(const QPoint &pos) const +{ + const int dpr = int(devicePixelRatio()); + return (pos - m_nativeGeometry.topLeft()) / dpr + m_geometry.topLeft(); +} + +QRect QXcbScreen::mapToNative(const QRect &rect) const +{ + const int dpr = int(devicePixelRatio()); + return QRect(mapToNative(rect.topLeft()), rect.size() * dpr); +} + +QRect QXcbScreen::mapFromNative(const QRect &rect) const +{ + const int dpr = int(devicePixelRatio()); + return QRect(mapFromNative(rect.topLeft()), rect.size() / dpr); +} + void QXcbScreen::windowShown(QXcbWindow *window) { // Freedesktop.org Startup Notification @@ -499,9 +524,9 @@ void QXcbScreen::updateGeometry(const QRect &geom, uint8_t rotation) qreal dpi = xGeometry.width() / physicalSize().width() * qreal(25.4); m_devicePixelRatio = qRound(dpi/96); const int dpr = int(devicePixelRatio()); // we may override m_devicePixelRatio - m_geometry = QRect(xGeometry.topLeft()/dpr, xGeometry.size()/dpr); + m_geometry = QRect(xGeometry.topLeft(), xGeometry.size()/dpr); m_nativeGeometry = QRect(xGeometry.topLeft(), xGeometry.size()); - m_availableGeometry = QRect(xAvailableGeometry.topLeft()/dpr, xAvailableGeometry.size()/dpr); + m_availableGeometry = QRect(mapFromNative(xAvailableGeometry.topLeft()), xAvailableGeometry.size()/dpr); QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry); } |