9#include <qpa/qplatformscreen.h>
10#include <qpa/qplatformscreen_p.h>
12#include <QtCore/QDebug>
13#include <QtCore/private/qobject_p.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
47QScreen::QScreen(QPlatformScreen *platformScreen)
48 : QObject(*
new QScreenPrivate(),
nullptr)
52 d->platformScreen = platformScreen;
53 platformScreen->d_func()->screen =
this;
55 d->orientation = platformScreen->orientation();
56 d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
57 d->refreshRate = platformScreen->refreshRate();
59 if (d->refreshRate < 1.0)
60 d->refreshRate = 60.0;
63 d->updatePrimaryOrientation();
68 geometry = QHighDpi::fromNativeGlobalPosition(platformScreen->geometry(), platformScreen);
69 availableGeometry = QHighDpi::fromNativeGlobalPosition(platformScreen->availableGeometry(), platformScreen);
73
74
75
76
79 Q_ASSERT_X(!QGuiApplicationPrivate::screen_list.contains(
this),
"QScreen",
80 "QScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
84
85
86
87
88QPlatformScreen *QScreen::handle()
const
91 return d->platformScreen;
95
96
97
98
99
100
101
102
103
104
105QString QScreen::name()
const
108 return d->platformScreen->name();
112
113
114
115
116
117QString QScreen::manufacturer()
const
120 return d->platformScreen->manufacturer();
124
125
126
127
128
129QString QScreen::model()
const
132 return d->platformScreen->model();
136
137
138
139
140
141QString QScreen::serialNumber()
const
144 return d->platformScreen->serialNumber();
148
149
150
151int QScreen::depth()
const
154 return d->platformScreen->depth();
158
159
160
161QSize QScreen::size()
const
164 return d->geometry.size();
168
169
170
171
172
173
174
175
176
177
178
179
180qreal QScreen::physicalDotsPerInchX()
const
182 return size().width() / physicalSize().width() * qreal(25.4);
186
187
188
189
190
191
192
193
194
195
196
197
198qreal QScreen::physicalDotsPerInchY()
const
200 return size().height() / physicalSize().height() * qreal(25.4);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220qreal QScreen::physicalDotsPerInch()
const
223 QSizeF psz = physicalSize();
224 return ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
228
229
230
231
232
233
234
235qreal QScreen::logicalDotsPerInchX()
const
238 if (QHighDpiScaling::isActive())
239 return QHighDpiScaling::logicalDpi(
this).first;
240 return d->logicalDpi.first;
244
245
246
247
248
249
250
251qreal QScreen::logicalDotsPerInchY()
const
254 if (QHighDpiScaling::isActive())
255 return QHighDpiScaling::logicalDpi(
this).second;
256 return d->logicalDpi.second;
260
261
262
263
264
265
266
267
268
269
270
271qreal QScreen::logicalDotsPerInch()
const
274 QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(
this) : d->logicalDpi;
275 return (dpi.first + dpi.second) * qreal(0.5);
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295qreal QScreen::devicePixelRatio()
const
298 return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(
this);
302
303
304
305
306
307
308
309
310
311QSizeF QScreen::physicalSize()
const
314 return d->platformScreen->physicalSize();
318
319
320
321
322
323
324QSize QScreen::availableSize()
const
327 return d->availableGeometry.size();
331
332
333
334
335
336
337QRect QScreen::geometry()
const
344
345
346
347
348
349
350
351
352
353
354QRect QScreen::availableGeometry()
const
357 return d->availableGeometry;
361
362
363
364
365
366
367QList<QScreen *> QScreen::virtualSiblings()
const
370 const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
371 QList<QScreen *> screens;
372 screens.reserve(platformScreens.size());
373 for (QPlatformScreen *platformScreen : platformScreens) {
375 if (
auto *knownScreen = platformScreen->screen())
376 screens << knownScreen;
382
383
384
385
386
387
388
389
390
391QSize QScreen::virtualSize()
const
393 return virtualGeometry().size();
397
398
399
400
401
402
403
404
405
406QRect QScreen::virtualGeometry()
const
409 const auto screens = virtualSiblings();
410 for (QScreen *screen : screens)
411 result |= screen->geometry();
416
417
418
419
420
421
422
423
424
425QSize QScreen::availableVirtualSize()
const
427 return availableVirtualGeometry().size();
431
432
433
434
435
436
437
438
439
440QRect QScreen::availableVirtualGeometry()
const
443 const auto screens = virtualSiblings();
444 for (QScreen *screen : screens)
445 result |= screen->availableGeometry();
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464Qt::ScreenOrientation QScreen::orientation()
const
467 return d->orientation;
471
472
473
474
475
476
477
478
479qreal QScreen::refreshRate()
const
482 return d->refreshRate;
486
487
488
489
490
491
492
493
494
495
496
497
498Qt::ScreenOrientation QScreen::primaryOrientation()
const
501 return d->primaryOrientation;
505
506
507
508
509
510
511
512
513
514
515Qt::ScreenOrientation QScreen::nativeOrientation()
const
518 return d->platformScreen->nativeOrientation();
522
523
524
525
526
527
528
529int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
const
531 if (a == Qt::PrimaryOrientation)
532 a = primaryOrientation();
534 if (b == Qt::PrimaryOrientation)
535 b = primaryOrientation();
537 return QPlatformScreen::angleBetween(a, b);
541
542
543
544
545
546
547
548
549
550
551
552QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &target)
const
554 if (a == Qt::PrimaryOrientation)
555 a = primaryOrientation();
557 if (b == Qt::PrimaryOrientation)
558 b = primaryOrientation();
560 return QPlatformScreen::transformBetween(a, b, target);
564
565
566
567
568
569
570
571
572QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &rect)
const
574 if (a == Qt::PrimaryOrientation)
575 a = primaryOrientation();
577 if (b == Qt::PrimaryOrientation)
578 b = primaryOrientation();
580 return QPlatformScreen::mapBetween(a, b, rect);
584
585
586
587
588
589bool QScreen::isPortrait(Qt::ScreenOrientation o)
const
591 return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
592 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
596
597
598
599
600
601bool QScreen::isLandscape(Qt::ScreenOrientation o)
const
603 return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
604 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
608
609
610
611
612
613
614
617
618
619
620
621
622
623
627 primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
631
632
633
634
635
636
637
638
639QScreen *QScreen::virtualSiblingAt(QPoint point)
641 const auto &siblings = virtualSiblings();
642 for (QScreen *sibling : siblings) {
643 if (sibling->geometry().contains(point))
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
709QPixmap QScreen::grabWindow(WId window,
int x,
int y,
int width,
int height)
711 const QPlatformScreen *platformScreen = handle();
712 if (!platformScreen) {
713 qWarning(
"invoked with handle==0");
716 const qreal factor = QHighDpiScaling::factor(
this);
717 if (qFuzzyCompare(factor, 1))
718 return platformScreen->grabWindow(window, x, y, width, height);
720 const QPoint nativePos = QHighDpi::toNative(QPoint(x, y), factor);
721 QSize nativeSize(width, height);
722 if (nativeSize.isValid())
723 nativeSize = QHighDpi::toNative(nativeSize, factor);
725 platformScreen->grabWindow(window, nativePos.x(), nativePos.y(),
726 nativeSize.width(), nativeSize.height());
727 result.setDevicePixelRatio(result.devicePixelRatio() * factor);
732
733
734
735
736
737
738
739
740
741
742
744void *QScreen::resolveInterface(
const char *name,
int revision)
const
746 using namespace QNativeInterface;
747 using namespace QNativeInterface::Private;
749 auto *platformScreen = handle();
750 Q_UNUSED(platformScreen);
755 QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
759 QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
762#if defined(Q_OS_WEBOS)
763 QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
766#if defined(Q_OS_WIN32)
767 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
770#if defined(Q_OS_ANDROID)
771 QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
774#if QT_CONFIG(wayland)
775 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
778#if defined(Q_OS_MACOS)
779 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaScreen, platformScreen);
785#ifndef QT_NO_DEBUG_STREAM
786Q_GUI_EXPORT
QDebug operator<<(QDebug debug,
const QScreen *screen)
788 const QDebugStateSaver saver(debug);
790 debug <<
"QScreen(" << (
const void *)screen;
792 debug <<
", name=" << screen->name();
793 if (debug.verbosity() > 2) {
794 if (screen == QGuiApplication::primaryScreen())
795 debug <<
", primary";
796 debug <<
", geometry=" << screen->geometry();
797 debug <<
", available=" << screen->availableGeometry();
798 debug <<
", logical DPI=" << screen->logicalDotsPerInchX()
799 <<
',' << screen->logicalDotsPerInchY()
800 <<
", physical DPI=" << screen->physicalDotsPerInchX()
801 <<
',' << screen->physicalDotsPerInchY()
802 <<
", devicePixelRatio=" << screen->devicePixelRatio()
803 <<
", orientation=" << screen->orientation()
804 <<
", physical size=" << screen->physicalSize().width()
805 <<
'x' << screen->physicalSize().height() <<
"mm";
815 initialState.platformScreen = screen->handle();
822 initialState.logicalDpi = QDpi{
823 screen->logicalDotsPerInchX(),
824 screen->logicalDotsPerInchY()
826 initialState.geometry = screen->geometry();
827 initialState.availableGeometry = screen->availableGeometry();
828 initialState.primaryOrientation = screen->primaryOrientation();
833 QScreen *screen = initialState.platformScreen->screen();
835 const auto logicalDotsPerInch = QDpi{
836 screen->logicalDotsPerInchX(),
837 screen->logicalDotsPerInchY()
839 if (logicalDotsPerInch != initialState.logicalDpi)
840 emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
842 const auto geometry = screen->geometry();
843 const auto geometryChanged = geometry != initialState.geometry;
845 emit screen->geometryChanged(geometry);
847 const auto availableGeometry = screen->availableGeometry();
848 const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
849 if (availableGeometryChanged)
850 emit screen->availableGeometryChanged(availableGeometry);
852 if (geometryChanged || availableGeometryChanged) {
853 const auto siblings = screen->virtualSiblings();
854 for (QScreen* sibling : siblings)
855 emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
858 if (geometryChanged) {
859 emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
861 const auto primaryOrientation = screen->primaryOrientation();
862 if (primaryOrientation != initialState.primaryOrientation)
863 emit screen->primaryOrientationChanged(primaryOrientation);
869#include "moc_qscreen.cpp"
UpdateEmitter(QScreen *screen)
void updatePrimaryOrientation()
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)