8#include <qpa/qplatformscreen.h>
9#include <qpa/qplatformscreen_p.h>
11#include <QtCore/QDebug>
12#include <QtCore/private/qobject_p.h>
18
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
46QScreen::QScreen(QPlatformScreen *platformScreen)
47 : QObject(*
new QScreenPrivate(),
nullptr)
51 d->platformScreen = platformScreen;
52 platformScreen->d_func()->screen =
this;
54 d->orientation = platformScreen->orientation();
55 d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
56 d->refreshRate = platformScreen->refreshRate();
58 if (d->refreshRate < 1.0)
59 d->refreshRate = 60.0;
62 d->updatePrimaryOrientation();
67 qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
68 QRect nativeGeometry = platformScreen->geometry();
69 geometry = QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
70 QRect nativeAvailableGeometry = platformScreen->availableGeometry();
71 availableGeometry = QRect(nativeAvailableGeometry.topLeft(), QHighDpi::fromNative(nativeAvailableGeometry.size(), scaleFactor));
75
76
77
78
81 Q_ASSERT_X(!QGuiApplicationPrivate::screen_list.contains(
this),
"QScreen",
82 "QScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
86
87
88
89
90QPlatformScreen *QScreen::handle()
const
93 return d->platformScreen;
97
98
99
100
101
102
103
104
105
106
107QString QScreen::name()
const
110 return d->platformScreen->name();
114
115
116
117
118
119QString QScreen::manufacturer()
const
122 return d->platformScreen->manufacturer();
126
127
128
129
130
131QString QScreen::model()
const
134 return d->platformScreen->model();
138
139
140
141
142
143QString QScreen::serialNumber()
const
146 return d->platformScreen->serialNumber();
150
151
152
153int QScreen::depth()
const
156 return d->platformScreen->depth();
160
161
162
163QSize QScreen::size()
const
166 return d->geometry.size();
170
171
172
173
174
175
176
177
178
179
180
181
182qreal QScreen::physicalDotsPerInchX()
const
184 return size().width() / physicalSize().width() * qreal(25.4);
188
189
190
191
192
193
194
195
196
197
198
199
200qreal QScreen::physicalDotsPerInchY()
const
202 return size().height() / physicalSize().height() * qreal(25.4);
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222qreal QScreen::physicalDotsPerInch()
const
225 QSizeF psz = physicalSize();
226 return ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
230
231
232
233
234
235
236
237qreal QScreen::logicalDotsPerInchX()
const
240 if (QHighDpiScaling::isActive())
241 return QHighDpiScaling::logicalDpi(
this).first;
242 return d->logicalDpi.first;
246
247
248
249
250
251
252
253qreal QScreen::logicalDotsPerInchY()
const
256 if (QHighDpiScaling::isActive())
257 return QHighDpiScaling::logicalDpi(
this).second;
258 return d->logicalDpi.second;
262
263
264
265
266
267
268
269
270
271
272
273qreal QScreen::logicalDotsPerInch()
const
276 QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(
this) : d->logicalDpi;
277 return (dpi.first + dpi.second) * qreal(0.5);
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297qreal QScreen::devicePixelRatio()
const
300 return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(
this);
304
305
306
307
308
309
310
311
312
313QSizeF QScreen::physicalSize()
const
316 return d->platformScreen->physicalSize();
320
321
322
323
324
325
326QSize QScreen::availableSize()
const
329 return d->availableGeometry.size();
333
334
335
336
337
338
339QRect QScreen::geometry()
const
346
347
348
349
350
351
352
353
354
355
356QRect QScreen::availableGeometry()
const
359 return d->availableGeometry;
363
364
365
366
367
368
369QList<QScreen *> QScreen::virtualSiblings()
const
372 const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
373 QList<QScreen *> screens;
374 screens.reserve(platformScreens.size());
375 for (QPlatformScreen *platformScreen : platformScreens) {
377 if (
auto *knownScreen = platformScreen->screen())
378 screens << knownScreen;
384
385
386
387
388
389
390
391
392
393QSize QScreen::virtualSize()
const
395 return virtualGeometry().size();
399
400
401
402
403
404
405
406
407
408QRect QScreen::virtualGeometry()
const
411 const auto screens = virtualSiblings();
412 for (QScreen *screen : screens)
413 result |= screen->geometry();
418
419
420
421
422
423
424
425
426
427QSize QScreen::availableVirtualSize()
const
429 return availableVirtualGeometry().size();
433
434
435
436
437
438
439
440
441
442QRect QScreen::availableVirtualGeometry()
const
445 const auto screens = virtualSiblings();
446 for (QScreen *screen : screens)
447 result |= screen->availableGeometry();
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466Qt::ScreenOrientation QScreen::orientation()
const
469 return d->orientation;
473
474
475
476
477
478
479
480
481qreal QScreen::refreshRate()
const
484 return d->refreshRate;
488
489
490
491
492
493
494
495
496
497
498
499
500Qt::ScreenOrientation QScreen::primaryOrientation()
const
503 return d->primaryOrientation;
507
508
509
510
511
512
513
514
515
516
517Qt::ScreenOrientation QScreen::nativeOrientation()
const
520 return d->platformScreen->nativeOrientation();
524
525
526
527
528
529
530
531int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
const
533 if (a == Qt::PrimaryOrientation)
534 a = primaryOrientation();
536 if (b == Qt::PrimaryOrientation)
537 b = primaryOrientation();
539 return QPlatformScreen::angleBetween(a, b);
543
544
545
546
547
548
549
550
551
552
553
554QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &target)
const
556 if (a == Qt::PrimaryOrientation)
557 a = primaryOrientation();
559 if (b == Qt::PrimaryOrientation)
560 b = primaryOrientation();
562 return QPlatformScreen::transformBetween(a, b, target);
566
567
568
569
570
571
572
573
574QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &rect)
const
576 if (a == Qt::PrimaryOrientation)
577 a = primaryOrientation();
579 if (b == Qt::PrimaryOrientation)
580 b = primaryOrientation();
582 return QPlatformScreen::mapBetween(a, b, rect);
586
587
588
589
590
591bool QScreen::isPortrait(Qt::ScreenOrientation o)
const
593 return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
594 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
598
599
600
601
602
603bool QScreen::isLandscape(Qt::ScreenOrientation o)
const
605 return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
606 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
610
611
612
613
614
615
616
619
620
621
622
623
624
625
629 primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
633
634
635
636
637
638
639
640
641QScreen *QScreen::virtualSiblingAt(QPoint point)
643 const auto &siblings = virtualSiblings();
644 for (QScreen *sibling : siblings) {
645 if (sibling->geometry().contains(point))
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
697QPixmap QScreen::grabWindow(WId window,
int x,
int y,
int width,
int height)
699 const QPlatformScreen *platformScreen = handle();
700 if (!platformScreen) {
701 qWarning(
"invoked with handle==0");
704 const qreal factor = QHighDpiScaling::factor(
this);
705 if (qFuzzyCompare(factor, 1))
706 return platformScreen->grabWindow(window, x, y, width, height);
708 const QPoint nativePos = QHighDpi::toNative(QPoint(x, y), factor);
709 QSize nativeSize(width, height);
710 if (nativeSize.isValid())
711 nativeSize = QHighDpi::toNative(nativeSize, factor);
713 platformScreen->grabWindow(window, nativePos.x(), nativePos.y(),
714 nativeSize.width(), nativeSize.height());
715 result.setDevicePixelRatio(result.devicePixelRatio() * factor);
720
721
722
723
724
725
726
727
728
729
730
732void *QScreen::resolveInterface(
const char *name,
int revision)
const
734 using namespace QNativeInterface;
735 using namespace QNativeInterface::Private;
737 auto *platformScreen = handle();
738 Q_UNUSED(platformScreen);
743 QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
747 QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
750#if defined(Q_OS_WEBOS)
751 QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
754#if defined(Q_OS_WIN32)
755 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
758#if defined(Q_OS_ANDROID)
759 QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
762#if QT_CONFIG(wayland)
763 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
766#if defined(Q_OS_MACOS)
767 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaScreen, platformScreen);
773#ifndef QT_NO_DEBUG_STREAM
774Q_GUI_EXPORT
QDebug operator<<(QDebug debug,
const QScreen *screen)
776 const QDebugStateSaver saver(debug);
778 debug <<
"QScreen(" << (
const void *)screen;
780 debug <<
", name=" << screen->name();
781 if (debug.verbosity() > 2) {
782 if (screen == QGuiApplication::primaryScreen())
783 debug <<
", primary";
784 debug <<
", geometry=" << screen->geometry();
785 debug <<
", available=" << screen->availableGeometry();
786 debug <<
", logical DPI=" << screen->logicalDotsPerInchX()
787 <<
',' << screen->logicalDotsPerInchY()
788 <<
", physical DPI=" << screen->physicalDotsPerInchX()
789 <<
',' << screen->physicalDotsPerInchY()
790 <<
", devicePixelRatio=" << screen->devicePixelRatio()
791 <<
", orientation=" << screen->orientation()
792 <<
", physical size=" << screen->physicalSize().width()
793 <<
'x' << screen->physicalSize().height() <<
"mm";
803 initialState.platformScreen = screen->handle();
810 initialState.logicalDpi = QDpi{
811 screen->logicalDotsPerInchX(),
812 screen->logicalDotsPerInchY()
814 initialState.geometry = screen->geometry();
815 initialState.availableGeometry = screen->availableGeometry();
816 initialState.primaryOrientation = screen->primaryOrientation();
821 QScreen *screen = initialState.platformScreen->screen();
823 const auto logicalDotsPerInch = QDpi{
824 screen->logicalDotsPerInchX(),
825 screen->logicalDotsPerInchY()
827 if (logicalDotsPerInch != initialState.logicalDpi)
828 emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
830 const auto geometry = screen->geometry();
831 const auto geometryChanged = geometry != initialState.geometry;
833 emit screen->geometryChanged(geometry);
835 const auto availableGeometry = screen->availableGeometry();
836 const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
837 if (availableGeometryChanged)
838 emit screen->availableGeometryChanged(availableGeometry);
840 if (geometryChanged || availableGeometryChanged) {
841 const auto siblings = screen->virtualSiblings();
842 for (QScreen* sibling : siblings)
843 emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
846 if (geometryChanged) {
847 emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
849 const auto primaryOrientation = screen->primaryOrientation();
850 if (primaryOrientation != initialState.primaryOrientation)
851 emit screen->primaryOrientationChanged(primaryOrientation);
857#include "moc_qscreen.cpp"
UpdateEmitter(QScreen *screen)
void updatePrimaryOrientation()
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)