Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qplatformscreen.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qplatformscreen.h"
5#include <QtCore/qdebug.h>
6#include <QtGui/qguiapplication.h>
7#include <qpa/qplatformcursor.h>
8#include <QtGui/private/qguiapplication_p.h>
9#include <qpa/qplatformscreen_p.h>
10#include <qpa/qplatformintegration.h>
11#include <QtGui/qscreen.h>
12#include <QtGui/qwindow.h>
13#include <private/qhighdpiscaling_p.h>
14#include <private/qwindow_p.h>
15
17
19 : d_ptr(new QPlatformScreenPrivate)
20{
21 Q_D(QPlatformScreen);
22 d->screen = nullptr;
23}
24
26{
27 Q_D(QPlatformScreen);
28 Q_ASSERT_X(!d->screen, "QPlatformScreen",
29 "QPlatformScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
30}
31
39{
41 Q_UNUSED(x);
42 Q_UNUSED(y);
45 return QPixmap();
46}
47
55{
57 const auto crend = list.crend();
58 for (auto it = list.crbegin(); it != crend; ++it) {
59 QWindow *w = *it;
60 if (w->isVisible() && QHighDpi::toNativePixels(w->geometry(), w).contains(pos))
61 return w;
62 }
63
64 return nullptr;
65}
66
80
87{
88 if (!geometry().contains(point)) {
89 const auto screens = virtualSiblings();
90 for (const QPlatformScreen *screen : screens) {
91 if (screen->geometry().contains(point))
92 return screen;
93 }
94 }
95 return this;
96}
97
98
106QList<QPlatformScreen *> QPlatformScreen::virtualSiblings() const
107{
108 QList<QPlatformScreen *> list;
109 list << const_cast<QPlatformScreen *>(this);
110 return list;
111}
112
114{
115 Q_D(const QPlatformScreen);
116 return d->screen;
117}
118
132{
133 static const int dpi = 100;
134 return QSizeF(geometry().size()) / dpi * qreal(25.4);
135}
136
149{
150 return logicalBaseDpi();
151}
152
153// Helper function for accessing the platform screen logical dpi
154// which accounts for QT_FONT_DPI.
155QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in)
156{
157 static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI");
158 return overrideDpi > 0 ? QDpi(overrideDpi, overrideDpi) : in;
159}
160
171{
172 return QDpi(96, 96);
173}
174
184{
185 return 1.0;
186}
187
195{
196 return 60;
197}
198
210
222
224{
225 // QTBUG 32681: It can happen during the transition between screens
226 // when one screen is disconnected that the window doesn't have a screen.
227 if (!window->screen())
228 return nullptr;
229 return window->screen()->handle();
230}
231
241{
242 return QString();
243}
244
254{
255 return QString();
256}
257
267{
268 return QString();
269}
270
310{
311 return nullptr;
312}
313
319{
320 // 'screen()' still has the old geometry (in device independent pixels),
321 // while 'this' has the new geometry (in native pixels)
322 const QRect oldGeometry = screen()->geometry();
323 const QRect oldAvailableGeometry = screen()->availableGeometry();
324 const QRect newNativeGeometry = this->geometry();
325 const QRect newNativeAvailableGeometry = this->availableGeometry();
326
327 const bool supportsMaximizeUsingFullscreen = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MaximizeUsingFullscreenGeometry);
328
329 for (QWindow *w : windows()) {
330 // Skip non-platform windows, e.g., offscreen windows.
331 if (!w->handle())
332 continue;
333
334 // Set QPlatformWindow size in native pixels, and let the platform's geometry
335 // change signals update the QWindow geomeyry. This way we make sure that the
336 // platform window geometry covers the entire (available) platform screen geometry,
337 // also when fractional DPRs introduce rounding errors in the device independent
338 // QWindow and QScreen sizes.
339 if (supportsMaximizeUsingFullscreen
340 && w->windowState() & Qt::WindowMaximized
342 w->handle()->setGeometry(newNativeGeometry);
343 } else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) {
344 w->handle()->setGeometry(newNativeAvailableGeometry);
345 } else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) {
346 w->handle()->setGeometry(newNativeGeometry);
347 }
348 }
349}
350
351// i must be power of two
352static int log2(uint i)
353{
354 if (i == 0)
355 return -1;
356
357 int result = 0;
358 while (!(i & 1)) {
359 ++result;
360 i >>= 1;
361 }
362 return result;
363}
364
366{
368 qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "angle");
369 return 0;
370 }
371
372 if (a == b)
373 return 0;
374
375 int ia = log2(uint(a));
376 int ib = log2(uint(b));
377
378 int delta = ia - ib;
379
380 if (delta < 0)
381 delta = delta + 4;
382
383 int angles[] = { 0, 90, 180, 270 };
384 return angles[delta];
385}
386
388{
390 qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "transform");
391 return QTransform();
392 }
393
394 if (a == b)
395 return QTransform();
396
397 int angle = angleBetween(a, b);
398
400 switch (angle) {
401 case 90:
402 result.translate(target.width(), 0);
403 break;
404 case 180:
405 result.translate(target.width(), target.height());
406 break;
407 case 270:
408 result.translate(0, target.height());
409 break;
410 default:
411 Q_ASSERT(false);
412 }
413 result.rotate(angle);
414
415 return result;
416}
417
419{
421 qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "map");
422 return rect;
423 }
424
425 if (a == b)
426 return rect;
427
430 {
431 return QRect(rect.y(), rect.x(), rect.height(), rect.width());
432 }
433
434 return rect;
435}
436
445{
446 static int type = -1;
447 if (type == -1) {
448 QByteArray env = qgetenv("QT_SUBPIXEL_AA_TYPE");
449 if (env == "RGB")
451 else if (env == "BGR")
453 else if (env == "VRGB")
455 else if (env == "VBGR")
457 else
459 }
460
462}
463
473
481
494QList<QPlatformScreen::Mode> QPlatformScreen::modes() const
495{
496 QList<QPlatformScreen::Mode> list;
497 list.append({geometry().size(), refreshRate()});
498 return list;
499}
500
512{
513 return 0;
514}
515
527{
528 return 0;
529}
530
531QList<QPlatformScreen *> QPlatformPlaceholderScreen::virtualSiblings() const
532{
533 QList<QPlatformScreen *> siblings;
534
535 if (!m_virtualSibling)
536 return siblings;
537
539 if (screen->handle() && screen->handle() != this)
540 siblings << screen->handle();
541 }
542 return siblings;
543}
544
\inmodule QtCore
Definition qbytearray.h:57
static QPlatformIntegration * platformIntegration()
static QWindowList topLevelWindows()
Returns a list of the top-level windows in the application.
static QWindowList allWindows()
Returns a list of all the windows in the application.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
const_reverse_iterator crbegin() const noexcept
Definition qlist.h:638
void append(parameter_type t)
Definition qlist.h:458
const_reverse_iterator crend() const noexcept
Definition qlist.h:639
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPlatformCursor class provides information about pointer device events (movement,...
QList< QPlatformScreen * > virtualSiblings() const override
Returns a list of all the platform screens that are part of the same virtual desktop.
The QPlatformScreen class provides an abstraction for visual displays.
static QDpi overrideDpi(const QDpi &in)
virtual ~QPlatformScreen()
static QPlatformScreen * platformScreenForWindow(const QWindow *window)
virtual void setPowerState(PowerState state)
Sets the power state for this screen.
virtual Qt::ScreenOrientation orientation() const
Reimplement this function in subclass to return the current orientation of the screen,...
static QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect)
const QPlatformScreen * screenForPosition(const QPoint &point) const
Find the sibling screen corresponding to globalPos.
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
virtual QPlatformCursor * cursor() const
Reimplement this function in subclass to return the cursor of the screen.
virtual PowerState powerState() const
Returns the current power state.
virtual Qt::ScreenOrientation nativeOrientation() const
Reimplement this function in subclass to return the native orientation of the screen,...
virtual QString manufacturer() const
Reimplement this function in subclass to return the manufacturer of this screen.
QScreen * screen() const
void resizeMaximizedWindows()
Convenience method to resize all the maximized and fullscreen windows of this platform screen.
virtual int preferredMode() const
Reimplement this function in subclass to return the preferred mode index from the modes list.
virtual QDpi logicalDpi() const
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
virtual QList< Mode > modes() const
Reimplement this function in subclass to return the list of modes for this screen.
virtual QPixmap 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.
QWindowList windows() const
Return all windows residing on this screen.
virtual SubpixelAntialiasingType subpixelAntialiasingTypeHint() const
Returns a hint about this screen's subpixel layout structure.
virtual QRect availableGeometry() const
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
virtual QDpi logicalBaseDpi() const
Reimplement to return the base logical DPI for the platform.
virtual QWindow * topLevelAt(const QPoint &point) const
Return the given top level window for a given position.
static QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target)
virtual QString serialNumber() const
Reimplement this function in subclass to return the serial number of this screen.
virtual QSizeF physicalSize() const
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
virtual int currentMode() const
Reimplement this function in subclass to return the index of the current mode from the modes list.
virtual QList< QPlatformScreen * > virtualSiblings() const
Returns a list of all the platform screens that are part of the same virtual desktop.
virtual qreal devicePixelRatio() const
Reimplement this function in subclass to return the device pixel ratio for the screen.
static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
virtual qreal refreshRate() const
Reimplement this function in subclass to return the vertical refresh rate of the screen,...
virtual QString model() const
Reimplement this function in subclass to return the model of this screen.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect availableGeometry
the screen's available geometry in pixels
Definition qscreen.h:46
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
\inmodule QtGui
Definition qwindow.h:63
QSet< QString >::iterator it
rect
[4]
else opt state
[0]
T toNativePixels(const T &value, const C *context)
Combined button and popup list for selecting options.
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowMaximized
Definition qnamespace.h:254
ScreenOrientation
Definition qnamespace.h:271
@ InvertedPortraitOrientation
Definition qnamespace.h:275
@ PortraitOrientation
Definition qnamespace.h:273
@ PrimaryOrientation
Definition qnamespace.h:272
@ MaximizeUsingFullscreenGeometryHint
Definition qnamespace.h:237
#define qWarning
Definition qlogging.h:166
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLenum type
GLfloat angle
GLenum target
GLint y
GLuint in
GLuint64EXT * result
[6]
static int log2(uint i)
QPair< qreal, qreal > QDpi
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
QList< int > list
[14]
aWidget window() -> setWindowTitle("New Window Title")
[2]