summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatformscreen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel/qplatformscreen.cpp')
-rw-r--r--src/gui/kernel/qplatformscreen.cpp111
1 files changed, 25 insertions, 86 deletions
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index a89d4d007b..0369a0b12a 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qplatformscreen.h"
#include <QtCore/qdebug.h>
@@ -47,6 +11,7 @@
#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
#include <private/qhighdpiscaling_p.h>
+#include <private/qwindow_p.h>
QT_BEGIN_NAMESPACE
@@ -60,10 +25,8 @@ QPlatformScreen::QPlatformScreen()
QPlatformScreen::~QPlatformScreen()
{
Q_D(QPlatformScreen);
- if (d->screen) {
- qWarning("Manually deleting a QPlatformScreen. Call QWindowSystemInterface::handleScreenRemoved instead.");
- delete d->screen;
- }
+ Q_ASSERT_X(!d->screen, "QPlatformScreen",
+ "QPlatformScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
}
/*!
@@ -91,8 +54,9 @@ QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int hei
QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const
{
const QWindowList list = QGuiApplication::topLevelWindows();
- for (int i = list.size()-1; i >= 0; --i) {
- QWindow *w = list[i];
+ const auto crend = list.crend();
+ for (auto it = list.crbegin(); it != crend; ++it) {
+ QWindow *w = *it;
if (w->isVisible() && QHighDpi::toNativePixels(w->geometry(), w).contains(pos))
return w;
}
@@ -174,21 +138,16 @@ QSizeF QPlatformScreen::physicalSize() const
Reimplement this function in subclass to return the logical horizontal
and vertical dots per inch metrics of the screen.
- The logical dots per inch metrics are used by QFont to convert point sizes
- to pixel sizes.
+ The logical dots per inch metrics are used by Qt to scale the user interface.
- The default implementation uses the screen pixel size and physical size to
- compute the metrics.
+ The default implementation returns logicalBaseDpi(), which results in a
+ UI scale factor of 1.0.
\sa physicalSize
*/
QDpi QPlatformScreen::logicalDpi() const
{
- QSizeF ps = physicalSize();
- QSize s = geometry().size();
-
- return QDpi(25.4 * s.width() / ps.width(),
- 25.4 * s.height() / ps.height());
+ return logicalBaseDpi();
}
// Helper function for accessing the platform screen logical dpi
@@ -205,7 +164,7 @@ QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in)
default implementation returns 96.
QtGui will use this value (together with logicalDpi) to compute
- the scale factor when high-DPI scaling is enabled:
+ the scale factor when high-DPI scaling is enabled, as follows:
factor = logicalDPI / baseDPI
*/
QDpi QPlatformScreen::logicalBaseDpi() const
@@ -220,7 +179,6 @@ QDpi QPlatformScreen::logicalBaseDpi() const
implementation returns 1.0.
\sa QPlatformWindow::devicePixelRatio()
- \sa QPlatformScreen::pixelDensity()
*/
qreal QPlatformScreen::devicePixelRatio() const
{
@@ -228,24 +186,6 @@ qreal QPlatformScreen::devicePixelRatio() const
}
/*!
- Reimplement this function in subclass to return the pixel density of the
- screen. This is the scale factor needed to make a low-dpi application
- usable on this screen. The default implementation returns 1.0.
-
- Returning something else than 1.0 from this function causes Qt to
- apply the scale factor to the application's coordinate system.
- This is different from devicePixelRatio, which reports a scale
- factor already applied by the windowing system. A platform plugin
- typically implements one (or none) of these two functions.
-
- \sa QPlatformWindow::devicePixelRatio()
-*/
-qreal QPlatformScreen::pixelDensity() const
-{
- return 1.0;
-}
-
-/*!
Reimplement this function in subclass to return the vertical refresh rate
of the screen, in Hz.
@@ -377,11 +317,12 @@ QPlatformCursor *QPlatformScreen::cursor() const
*/
void QPlatformScreen::resizeMaximizedWindows()
{
- // 'screen()' still has the old geometry info while 'this' has the new geometry info
+ // 'screen()' still has the old geometry (in device independent pixels),
+ // while 'this' has the new geometry (in native pixels)
const QRect oldGeometry = screen()->geometry();
const QRect oldAvailableGeometry = screen()->availableGeometry();
- const QRect newGeometry = deviceIndependentGeometry();
- const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft());
+ const QRect newNativeGeometry = this->geometry();
+ const QRect newNativeAvailableGeometry = this->availableGeometry();
const bool supportsMaximizeUsingFullscreen = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MaximizeUsingFullscreenGeometry);
@@ -390,14 +331,19 @@ void QPlatformScreen::resizeMaximizedWindows()
if (!w->handle())
continue;
+ // Set QPlatformWindow size in native pixels, and let the platform's geometry
+ // change signals update the QWindow geomeyry. This way we make sure that the
+ // platform window geometry covers the entire (available) platform screen geometry,
+ // also when fractional DPRs introduce rounding errors in the device independent
+ // QWindow and QScreen sizes.
if (supportsMaximizeUsingFullscreen
&& w->windowState() & Qt::WindowMaximized
&& w->flags() & Qt::MaximizeUsingFullscreenGeometryHint) {
- w->setGeometry(newGeometry);
+ w->handle()->setGeometry(newNativeGeometry);
} else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) {
- w->setGeometry(newAvailableGeometry);
+ w->handle()->setGeometry(newNativeAvailableGeometry);
} else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) {
- w->setGeometry(newGeometry);
+ w->handle()->setGeometry(newNativeGeometry);
}
}
}
@@ -488,13 +434,6 @@ QRect QPlatformScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation
return rect;
}
-QRect QPlatformScreen::deviceIndependentGeometry() const
-{
- qreal scaleFactor = QHighDpiScaling::factor(this);
- QRect nativeGeometry = geometry();
- return QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
-}
-
/*!
Returns a hint about this screen's subpixel layout structure.