Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qscreen.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// Qt-Security score:significant reason:default
4
5#include "qscreen.h"
6#include "qscreen_p.h"
7#include "qpixmap.h"
9#include <qpa/qplatformscreen.h>
10#include <qpa/qplatformscreen_p.h>
11
12#include <QtCore/QDebug>
13#include <QtCore/private/qobject_p.h>
15
17
18/*!
19 \class QScreen
20 \since 5.0
21 \brief The QScreen class is used to query screen properties.
22 \inmodule QtGui
23
24 A note on logical vs physical dots per inch: physical DPI is based on the
25 actual physical pixel sizes when available, and is useful for print preview
26 and other cases where it's desirable to know the exact physical dimensions
27 of screen displayed contents.
28
29 Logical dots per inch are used to convert font and user interface elements
30 from point sizes to pixel sizes, and might be different from the physical
31 dots per inch. The logical dots per inch are sometimes user-settable in the
32 desktop environment's settings panel, to let the user globally control UI
33 and font sizes in different applications.
34
35 \note Both physical and logical DPI are expressed in device-independent dots.
36 Multiply by QScreen::devicePixelRatio() to get device-dependent density.
37
38 To obtain a QScreen object, use QGuiApplication::primaryScreen() for the
39 primary screen, or QGuiApplication::screens() to get a list of all screens.
40
41 \sa QGuiApplication::primaryScreen()
42 \sa QGuiApplication::screens()
43
44 \inmodule QtGui
45*/
46
47QScreen::QScreen(QPlatformScreen *platformScreen)
48 : QObject(*new QScreenPrivate(), nullptr)
49{
50 Q_D(QScreen);
51
52 d->platformScreen = platformScreen;
53 platformScreen->d_func()->screen = this;
54
55 d->orientation = platformScreen->orientation();
56 d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
57 d->refreshRate = platformScreen->refreshRate();
58 // safeguard ourselves against buggy platform behavior...
59 if (d->refreshRate < 1.0)
60 d->refreshRate = 60.0;
61
62 d->updateGeometry();
63 d->updatePrimaryOrientation(); // derived from the geometry
64}
65
66void QScreenPrivate::updateGeometry()
67{
68 qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
69 QRect nativeGeometry = platformScreen->geometry();
70 geometry = QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
71 QRect nativeAvailableGeometry = platformScreen->availableGeometry();
72 availableGeometry = QRect(nativeAvailableGeometry.topLeft(), QHighDpi::fromNative(nativeAvailableGeometry.size(), scaleFactor));
73}
74
75/*!
76 Destroys the screen.
77
78 \internal
79 */
80QScreen::~QScreen()
81{
82 Q_ASSERT_X(!QGuiApplicationPrivate::screen_list.contains(this), "QScreen",
83 "QScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
84}
85
86/*!
87 Get the platform screen handle.
88
89 \sa {Qt Platform Abstraction}{Qt Platform Abstraction (QPA)}
90*/
91QPlatformScreen *QScreen::handle() const
92{
93 Q_D(const QScreen);
94 return d->platformScreen;
95}
96
97/*!
98 \property QScreen::name
99 \brief a user presentable string representing the screen
100
101 For example, on X11 these correspond to the XRandr screen names,
102 typically "VGA1", "HDMI1", etc.
103
104 \note The user presentable string is not guaranteed to match the
105 result of any native APIs, and should not be used to uniquely identify
106 a screen.
107*/
108QString QScreen::name() const
109{
110 Q_D(const QScreen);
111 return d->platformScreen->name();
112}
113
114/*!
115 \property QScreen::manufacturer
116 \brief the manufacturer of the screen
117
118 \since 5.9
119*/
120QString QScreen::manufacturer() const
121{
122 Q_D(const QScreen);
123 return d->platformScreen->manufacturer();
124}
125
126/*!
127 \property QScreen::model
128 \brief the model of the screen
129
130 \since 5.9
131*/
132QString QScreen::model() const
133{
134 Q_D(const QScreen);
135 return d->platformScreen->model();
136}
137
138/*!
139 \property QScreen::serialNumber
140 \brief the serial number of the screen
141
142 \since 5.9
143*/
144QString QScreen::serialNumber() const
145{
146 Q_D(const QScreen);
147 return d->platformScreen->serialNumber();
148}
149
150/*!
151 \property QScreen::depth
152 \brief the color depth of the screen
153*/
154int QScreen::depth() const
155{
156 Q_D(const QScreen);
157 return d->platformScreen->depth();
158}
159
160/*!
161 \property QScreen::size
162 \brief the pixel resolution of the screen
163*/
164QSize QScreen::size() const
165{
166 Q_D(const QScreen);
167 return d->geometry.size();
168}
169
170/*!
171 \property QScreen::physicalDotsPerInchX
172 \brief the number of physical dots or pixels per inch in the horizontal direction
173
174 This value represents the actual horizontal pixel density on the screen's display.
175 Depending on what information the underlying system provides the value might not be
176 entirely accurate.
177
178 \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
179 to get device-dependent density.
180
181 \sa physicalDotsPerInchY()
182*/
183qreal QScreen::physicalDotsPerInchX() const
184{
185 return size().width() / physicalSize().width() * qreal(25.4);
186}
187
188/*!
189 \property QScreen::physicalDotsPerInchY
190 \brief the number of physical dots or pixels per inch in the vertical direction
191
192 This value represents the actual vertical pixel density on the screen's display.
193 Depending on what information the underlying system provides the value might not be
194 entirely accurate.
195
196 \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
197 to get device-dependent density.
198
199 \sa physicalDotsPerInchX()
200*/
201qreal QScreen::physicalDotsPerInchY() const
202{
203 return size().height() / physicalSize().height() * qreal(25.4);
204}
205
206/*!
207 \property QScreen::physicalDotsPerInch
208 \brief the number of physical dots or pixels per inch
209
210 This value represents the pixel density on the screen's display.
211 Depending on what information the underlying system provides the value might not be
212 entirely accurate.
213
214 This is a convenience property that's simply the average of the physicalDotsPerInchX
215 and physicalDotsPerInchY properties.
216
217 \note Physical DPI is expressed in device-independent dots. Multiply by QScreen::devicePixelRatio()
218 to get device-dependent density.
219
220 \sa physicalDotsPerInchX()
221 \sa physicalDotsPerInchY()
222*/
223qreal QScreen::physicalDotsPerInch() const
224{
225 QSize sz = size();
226 QSizeF psz = physicalSize();
227 return ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
228}
229
230/*!
231 \property QScreen::logicalDotsPerInchX
232 \brief the number of logical dots or pixels per inch in the horizontal direction
233
234 This value is used to convert font point sizes to pixel sizes.
235
236 \sa logicalDotsPerInchY()
237*/
238qreal QScreen::logicalDotsPerInchX() const
239{
240 Q_D(const QScreen);
241 if (QHighDpiScaling::isActive())
242 return QHighDpiScaling::logicalDpi(this).first;
243 return d->logicalDpi.first;
244}
245
246/*!
247 \property QScreen::logicalDotsPerInchY
248 \brief the number of logical dots or pixels per inch in the vertical direction
249
250 This value is used to convert font point sizes to pixel sizes.
251
252 \sa logicalDotsPerInchX()
253*/
254qreal QScreen::logicalDotsPerInchY() const
255{
256 Q_D(const QScreen);
257 if (QHighDpiScaling::isActive())
258 return QHighDpiScaling::logicalDpi(this).second;
259 return d->logicalDpi.second;
260}
261
262/*!
263 \property QScreen::logicalDotsPerInch
264 \brief the number of logical dots or pixels per inch
265
266 This value can be used to convert font point sizes to pixel sizes.
267
268 This is a convenience property that's simply the average of the logicalDotsPerInchX
269 and logicalDotsPerInchY properties.
270
271 \sa logicalDotsPerInchX()
272 \sa logicalDotsPerInchY()
273*/
274qreal QScreen::logicalDotsPerInch() const
275{
276 Q_D(const QScreen);
277 QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(this) : d->logicalDpi;
278 return (dpi.first + dpi.second) * qreal(0.5);
279}
280
281/*!
282 \property QScreen::devicePixelRatio
283 \brief the screen's ratio between physical pixels and device-independent pixels
284 \since 5.5
285
286 Returns the ratio between physical pixels and device-independent pixels for the screen.
287
288 This function may return a value that differs from QWindow::devicePixelRatio(),
289 for instance on Wayland when using fractional scaling, or if window properties
290 that affect surface resolution are set. Prefer using QWindow::devicePixelRatio().
291
292 \note On some platforms the devicePixelRatio of a window and the screen it is on can
293 be different. Use this function only when you don't know which window you are targeting.
294 If you do know the target window, use QWindow::devicePixelRatio() instead.
295
296 \sa QWindow::devicePixelRatio(), QGuiApplication::devicePixelRatio()
297*/
298qreal QScreen::devicePixelRatio() const
299{
300 Q_D(const QScreen);
301 return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(this);
302}
303
304/*!
305 \property QScreen::physicalSize
306 \brief the screen's physical size (in millimeters)
307
308 The physical size represents the actual physical dimensions of the
309 screen's display.
310
311 Depending on what information the underlying system provides the value
312 might not be entirely accurate.
313*/
314QSizeF QScreen::physicalSize() const
315{
316 Q_D(const QScreen);
317 return d->platformScreen->physicalSize();
318}
319
320/*!
321 \property QScreen::availableSize
322 \brief the screen's available size in pixels
323
324 The available size is the size excluding window manager reserved areas
325 such as task bars and system menus.
326*/
327QSize QScreen::availableSize() const
328{
329 Q_D(const QScreen);
330 return d->availableGeometry.size();
331}
332
333/*!
334 \property QScreen::geometry
335 \brief the screen's geometry in pixels
336
337 As an example this might return QRect(0, 0, 1280, 1024), or in a
338 virtual desktop setting QRect(1280, 0, 1280, 1024).
339*/
340QRect QScreen::geometry() const
341{
342 Q_D(const QScreen);
343 return d->geometry;
344}
345
346/*!
347 \property QScreen::availableGeometry
348 \brief the screen's available geometry in pixels
349
350 The available geometry is the geometry excluding window manager reserved areas
351 such as task bars and system menus.
352
353 Note, on X11 this will return the true available geometry only on systems with one monitor and
354 if window manager has set _NET_WORKAREA atom. In all other cases this is equal to geometry().
355 This is a limitation in X11 window manager specification.
356*/
357QRect QScreen::availableGeometry() const
358{
359 Q_D(const QScreen);
360 return d->availableGeometry;
361}
362
363/*!
364 Get the screen's virtual siblings.
365
366 The virtual siblings are the screen instances sharing the same virtual desktop.
367 They share a common coordinate system, and windows can freely be moved or
368 positioned across them without having to be re-created.
369*/
370QList<QScreen *> QScreen::virtualSiblings() const
371{
372 Q_D(const QScreen);
373 const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
374 QList<QScreen *> screens;
375 screens.reserve(platformScreens.size());
376 for (QPlatformScreen *platformScreen : platformScreens) {
377 // Only consider platform screens that have been added
378 if (auto *knownScreen = platformScreen->screen())
379 screens << knownScreen;
380 }
381 return screens;
382}
383
384/*!
385 \property QScreen::virtualSize
386 \brief the pixel size of the virtual desktop to which this screen belongs
387
388 Returns the pixel size of the virtual desktop corresponding to this screen.
389
390 This is the combined size of the virtual siblings' individual geometries.
391
392 \sa virtualSiblings()
393*/
394QSize QScreen::virtualSize() const
395{
396 return virtualGeometry().size();
397}
398
399/*!
400 \property QScreen::virtualGeometry
401 \brief the pixel geometry of the virtual desktop to which this screen belongs
402
403 Returns the pixel geometry of the virtual desktop corresponding to this screen.
404
405 This is the union of the virtual siblings' individual geometries.
406
407 \sa virtualSiblings()
408*/
409QRect QScreen::virtualGeometry() const
410{
411 QRect result;
412 const auto screens = virtualSiblings();
413 for (QScreen *screen : screens)
414 result |= screen->geometry();
415 return result;
416}
417
418/*!
419 \property QScreen::availableVirtualSize
420 \brief the available size of the virtual desktop to which this screen belongs
421
422 Returns the available pixel size of the virtual desktop corresponding to this screen.
423
424 This is the combined size of the virtual siblings' individual available geometries.
425
426 \sa availableSize(), virtualSiblings()
427*/
428QSize QScreen::availableVirtualSize() const
429{
430 return availableVirtualGeometry().size();
431}
432
433/*!
434 \property QScreen::availableVirtualGeometry
435 \brief the available geometry of the virtual desktop to which this screen belongs
436
437 Returns the available geometry of the virtual desktop corresponding to this screen.
438
439 This is the union of the virtual siblings' individual available geometries.
440
441 \sa availableGeometry(), virtualSiblings()
442*/
443QRect QScreen::availableVirtualGeometry() const
444{
445 QRect result;
446 const auto screens = virtualSiblings();
447 for (QScreen *screen : screens)
448 result |= screen->availableGeometry();
449 return result;
450}
451
452/*!
453 \property QScreen::orientation
454 \brief the screen orientation
455
456 The \c orientation property tells the orientation of the screen from the
457 window system perspective.
458
459 Most mobile devices and tablet computers contain accelerometer sensors.
460 The Qt Sensors module provides the ability to read this sensor directly.
461 However, the windowing system may rotate the entire screen automatically
462 based on how it is being held; in that case, this \c orientation property
463 will change.
464
465 \sa primaryOrientation(), QWindow::contentOrientation()
466*/
467Qt::ScreenOrientation QScreen::orientation() const
468{
469 Q_D(const QScreen);
470 return d->orientation;
471}
472
473/*!
474 \property QScreen::refreshRate
475 \brief the approximate vertical refresh rate of the screen in Hz
476
477 \warning Avoid using the screen's refresh rate to drive animations via a
478 timer such as QChronoTimer. Instead use QWindow::requestUpdate().
479
480 \sa QWindow::requestUpdate()
481*/
482qreal QScreen::refreshRate() const
483{
484 Q_D(const QScreen);
485 return d->refreshRate;
486}
487
488/*!
489 \property QScreen::primaryOrientation
490 \brief the primary screen orientation
491
492 The primary screen orientation is Qt::LandscapeOrientation
493 if the screen geometry's width is greater than or equal to its
494 height, or Qt::PortraitOrientation otherwise. This property might
495 change when the screen orientation was changed (i.e. when the
496 display is rotated).
497 The behavior is however platform dependent and can often be specified in
498 an application manifest file.
499
500*/
501Qt::ScreenOrientation QScreen::primaryOrientation() const
502{
503 Q_D(const QScreen);
504 return d->primaryOrientation;
505}
506
507/*!
508 \property QScreen::nativeOrientation
509 \brief the native screen orientation
510 \since 5.2
511
512 The native orientation of the screen is the orientation where the logo
513 sticker of the device appears the right way up, or Qt::PrimaryOrientation
514 if the platform does not support this functionality.
515
516 The native orientation is a property of the hardware, and does not change.
517*/
518Qt::ScreenOrientation QScreen::nativeOrientation() const
519{
520 Q_D(const QScreen);
521 return d->platformScreen->nativeOrientation();
522}
523
524/*!
525 Convenience function to compute the angle of rotation to get from
526 rotation \a a to rotation \a b.
527
528 The result will be 0, 90, 180, or 270.
529
530 Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
531*/
532int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const
533{
534 if (a == Qt::PrimaryOrientation)
535 a = primaryOrientation();
536
537 if (b == Qt::PrimaryOrientation)
538 b = primaryOrientation();
539
540 return QPlatformScreen::angleBetween(a, b);
541}
542
543/*!
544 Convenience function to compute a transform that maps from the coordinate system
545 defined by orientation \a a into the coordinate system defined by orientation
546 \a b and target dimensions \a target.
547
548 Example, \a a is Qt::Landscape, \a b is Qt::Portrait, and \a target is QRect(0, 0, w, h)
549 the resulting transform will be such that the point QPoint(0, 0) is mapped to QPoint(0, w),
550 and QPoint(h, w) is mapped to QPoint(0, h). Thus, the landscape coordinate system QRect(0, 0, h, w)
551 is mapped (with a 90 degree rotation) into the portrait coordinate system QRect(0, 0, w, h).
552
553 Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
554*/
555QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target) const
556{
557 if (a == Qt::PrimaryOrientation)
558 a = primaryOrientation();
559
560 if (b == Qt::PrimaryOrientation)
561 b = primaryOrientation();
562
563 return QPlatformScreen::transformBetween(a, b, target);
564}
565
566/*!
567 Maps the rect between two screen orientations.
568
569 This will flip the x and y dimensions of the rectangle \a{rect} if the orientation \a{a} is
570 Qt::PortraitOrientation or Qt::InvertedPortraitOrientation and orientation \a{b} is
571 Qt::LandscapeOrientation or Qt::InvertedLandscapeOrientation, or vice versa.
572
573 Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
574*/
575QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect) const
576{
577 if (a == Qt::PrimaryOrientation)
578 a = primaryOrientation();
579
580 if (b == Qt::PrimaryOrientation)
581 b = primaryOrientation();
582
583 return QPlatformScreen::mapBetween(a, b, rect);
584}
585
586/*!
587 Convenience function that returns \c true if \a o is either portrait or inverted portrait;
588 otherwise returns \c false.
589
590 Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
591*/
592bool QScreen::isPortrait(Qt::ScreenOrientation o) const
593{
594 return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
595 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
596}
597
598/*!
599 Convenience function that returns \c true if \a o is either landscape or inverted landscape;
600 otherwise returns \c false.
601
602 Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
603*/
604bool QScreen::isLandscape(Qt::ScreenOrientation o) const
605{
606 return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
607 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
608}
609
610/*!
611 \fn void QScreen::orientationChanged(Qt::ScreenOrientation orientation)
612
613 This signal is emitted when the orientation of the screen
614 changes with \a orientation as an argument.
615
616 \sa orientation()
617*/
618
619/*!
620 \fn void QScreen::primaryOrientationChanged(Qt::ScreenOrientation orientation)
621
622 This signal is emitted when the primary orientation of the screen
623 changes with \a orientation as an argument.
624
625 \sa primaryOrientation()
626*/
627
629{
630 primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
631}
632
633/*!
634 Returns the screen at \a point within the set of \l QScreen::virtualSiblings(),
635 or \c nullptr if outside of any screen.
636
637 The \a point is in relation to the virtualGeometry() of each set of virtual
638 siblings.
639
640 \since 5.15
641*/
642QScreen *QScreen::virtualSiblingAt(QPoint point)
643{
644 const auto &siblings = virtualSiblings();
645 for (QScreen *sibling : siblings) {
646 if (sibling->geometry().contains(point))
647 return sibling;
648 }
649 return nullptr;
650}
651
652/*!
653 Creates and returns a pixmap constructed by grabbing the contents
654 of the given \a window restricted by QRect(\a x, \a y, \a width,
655 \a height). If \a window is 0, then the entire screen will be
656 grabbed.
657
658 The arguments (\a{x}, \a{y}) specify the offset in the window,
659 whereas (\a{width}, \a{height}) specify the area to be copied. If
660 \a width is negative, the function copies everything to the right
661 border of the window. If \a height is negative, the function
662 copies everything to the bottom of the window.
663
664 The offset and size arguments are specified in device independent
665 pixels. The returned pixmap may be larger than the requested size
666 when grabbing from a high-DPI screen. Call QPixmap::devicePixelRatio()
667 to determine if this is the case.
668
669 The window system identifier (\c WId) can be retrieved using the
670 QWidget::winId() function. The rationale for using a window
671 identifier and not a QWidget, is to enable grabbing of windows
672 that are not part of the application, window system frames, and so
673 on.
674
675 \warning Grabbing windows that are not part of the application is
676 not supported on systems such as iOS, where sandboxing/security
677 prevents reading pixels of windows not owned by the application.
678
679 The grabWindow() function grabs pixels from the screen, not from
680 the window, i.e. if there is another window partially or entirely
681 over the one you grab, you get pixels from the overlying window,
682 too. The mouse cursor is generally not grabbed.
683
684 Note on X11 that if the given \a window doesn't have the same depth
685 as the root window, and another window partially or entirely
686 obscures the one you grab, you will \e not get pixels from the
687 overlying window. The contents of the obscured areas in the
688 pixmap will be undefined and uninitialized.
689
690 On Windows Vista and above grabbing a layered window, which is
691 created by setting the Qt::WA_TranslucentBackground attribute, will
692 not work. Instead grabbing the desktop widget should work.
693
694 \warning In general, grabbing an area outside the screen is not
695 safe. This depends on the underlying window system.
696*/
697
698QPixmap QScreen::grabWindow(WId window, int x, int y, int width, int height)
699{
700 const QPlatformScreen *platformScreen = handle();
701 if (!platformScreen) {
702 qWarning("invoked with handle==0");
703 return QPixmap();
704 }
705 const qreal factor = QHighDpiScaling::factor(this);
706 if (qFuzzyCompare(factor, 1))
707 return platformScreen->grabWindow(window, x, y, width, height);
708
709 const QPoint nativePos = QHighDpi::toNative(QPoint(x, y), factor);
710 QSize nativeSize(width, height);
711 if (nativeSize.isValid())
712 nativeSize = QHighDpi::toNative(nativeSize, factor);
713 QPixmap result =
714 platformScreen->grabWindow(window, nativePos.x(), nativePos.y(),
715 nativeSize.width(), nativeSize.height());
716 result.setDevicePixelRatio(result.devicePixelRatio() * factor);
717 return result;
718}
719
720/*!
721 \fn template <typename QNativeInterface> QNativeInterface *QScreen::nativeInterface() const
722
723 Returns a native interface of the given type for the screen.
724
725 This function provides access to platform specific functionality
726 of QScreen, as defined in the QNativeInterface namespace:
727
728 \annotatedlist native-interfaces-qscreen
729
730 If the requested interface is not available a \nullptr is returned.
731 */
732
733void *QScreen::resolveInterface(const char *name, int revision) const
734{
735 using namespace QNativeInterface;
736 using namespace QNativeInterface::Private;
737
738 auto *platformScreen = handle();
739 Q_UNUSED(platformScreen);
740 Q_UNUSED(name);
741 Q_UNUSED(revision);
742
743#if QT_CONFIG(xcb)
744 QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
745#endif
746
747#if QT_CONFIG(vsp2)
748 QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
749#endif
750
751#if defined(Q_OS_WEBOS)
752 QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
753#endif
754
755#if defined(Q_OS_WIN32)
756 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
757#endif
758
759#if defined(Q_OS_ANDROID)
760 QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
761#endif
762
763#if QT_CONFIG(wayland)
764 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
765#endif
766
767#if defined(Q_OS_MACOS)
768 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaScreen, platformScreen);
769#endif
770
771 return nullptr;
772}
773
774#ifndef QT_NO_DEBUG_STREAM
775Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QScreen *screen)
776{
777 const QDebugStateSaver saver(debug);
778 debug.nospace();
779 debug << "QScreen(" << (const void *)screen;
780 if (screen) {
781 debug << ", name=" << screen->name();
782 if (debug.verbosity() > 2) {
783 if (screen == QGuiApplication::primaryScreen())
784 debug << ", primary";
785 debug << ", geometry=" << screen->geometry();
786 debug << ", available=" << screen->availableGeometry();
787 debug << ", logical DPI=" << screen->logicalDotsPerInchX()
788 << ',' << screen->logicalDotsPerInchY()
789 << ", physical DPI=" << screen->physicalDotsPerInchX()
790 << ',' << screen->physicalDotsPerInchY()
791 << ", devicePixelRatio=" << screen->devicePixelRatio()
792 << ", orientation=" << screen->orientation()
793 << ", physical size=" << screen->physicalSize().width()
794 << 'x' << screen->physicalSize().height() << "mm";
795 }
796 }
797 debug << ')';
798 return debug;
799}
800#endif // !QT_NO_DEBUG_STREAM
801
803{
804 initialState.platformScreen = screen->handle();
805
806 // Use public APIs to read out current state, rather
807 // than accessing the QScreenPrivate members, so that
808 // we detect any changes to the high-DPI scale factors
809 // that may be applied in the getters.
810
811 initialState.logicalDpi = QDpi{
812 screen->logicalDotsPerInchX(),
813 screen->logicalDotsPerInchY()
814 };
815 initialState.geometry = screen->geometry();
816 initialState.availableGeometry = screen->availableGeometry();
817 initialState.primaryOrientation = screen->primaryOrientation();
818}
819
821{
822 QScreen *screen = initialState.platformScreen->screen();
823
824 const auto logicalDotsPerInch = QDpi{
825 screen->logicalDotsPerInchX(),
826 screen->logicalDotsPerInchY()
827 };
828 if (logicalDotsPerInch != initialState.logicalDpi)
829 emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
830
831 const auto geometry = screen->geometry();
832 const auto geometryChanged = geometry != initialState.geometry;
833 if (geometryChanged)
834 emit screen->geometryChanged(geometry);
835
836 const auto availableGeometry = screen->availableGeometry();
837 const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
838 if (availableGeometryChanged)
839 emit screen->availableGeometryChanged(availableGeometry);
840
841 if (geometryChanged || availableGeometryChanged) {
842 const auto siblings = screen->virtualSiblings();
843 for (QScreen* sibling : siblings)
844 emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
845 }
846
847 if (geometryChanged) {
848 emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
849
850 const auto primaryOrientation = screen->primaryOrientation();
851 if (primaryOrientation != initialState.primaryOrientation)
852 emit screen->primaryOrientationChanged(primaryOrientation);
853 }
854}
855
856QT_END_NAMESPACE
857
858#include "moc_qscreen.cpp"
UpdateEmitter(QScreen *screen)
Definition qscreen.cpp:802
void updatePrimaryOrientation()
Definition qscreen.cpp:628
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582