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.cpp142
1 files changed, 27 insertions, 115 deletions
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index 7c1e2158b1..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,15 +25,11 @@ 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()");
}
/*!
- \fn QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int height) const
-
This function is called when Qt needs to be able to grab the content of a window.
Returns the content of the window specified with the WId handle within the boundaries of
@@ -93,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;
}
@@ -176,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
@@ -207,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
@@ -222,7 +179,6 @@ QDpi QPlatformScreen::logicalBaseDpi() const
implementation returns 1.0.
\sa QPlatformWindow::devicePixelRatio()
- \sa QPlatformScreen::pixelDensity()
*/
qreal QPlatformScreen::devicePixelRatio() const
{
@@ -230,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.
@@ -282,29 +220,6 @@ Qt::ScreenOrientation QPlatformScreen::orientation() const
return Qt::PrimaryOrientation;
}
-/*
- Reimplement this function in subclass to filter out unneeded screen
- orientation updates.
-
- The orientations will anyway be filtered before QScreen::orientationChanged()
- is emitted, but the mask can be used by the platform plugin for example to
- prevent having to have an accelerometer sensor running all the time, or to
- improve the reported values. As an example of the latter, in case of only
- Landscape | InvertedLandscape being set in the mask, on a platform that gets
- its orientation readings from an accelerometer sensor embedded in a handheld
- device, the platform can report transitions between the two even when the
- device is held in an orientation that's closer to portrait.
-
- By default, the orientation update mask is empty, so unless this function
- has been called with a non-empty mask the platform does not need to report
- any orientation updates through
- QWindowSystemInterface::handleScreenOrientationChange().
-*/
-void QPlatformScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
-{
- Q_UNUSED(mask);
-}
-
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)
{
// QTBUG 32681: It can happen during the transition between screens
@@ -367,8 +282,6 @@ QString QPlatformScreen::serialNumber() const
physicalSize() function, since this is the function it uses to calculate the dpi to use when
converting point sizes to pixels sizes. However, this is unfortunate on some systems, as the
native system fakes its dpi size.
-
- QPlatformScreen is also used by the public api QDesktopWidget for information about the desktop.
*/
/*! \fn QRect QPlatformScreen::geometry() const = 0
@@ -404,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);
@@ -417,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);
}
}
}
@@ -515,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.
@@ -579,9 +491,9 @@ void QPlatformScreen::setPowerState(PowerState state)
\since 5.9
*/
-QVector<QPlatformScreen::Mode> QPlatformScreen::modes() const
+QList<QPlatformScreen::Mode> QPlatformScreen::modes() const
{
- QVector<QPlatformScreen::Mode> list;
+ QList<QPlatformScreen::Mode> list;
list.append({geometry().size(), refreshRate()});
return list;
}