7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformintegration.h>
9#ifndef QT_NO_CONTEXTMENU
10#include <qpa/qplatformtheme.h>
14#include <qpa/qplatformopenglcontext.h>
22#if QT_CONFIG(accessibility)
23# include "qaccessible.h"
24# include <private/qaccessiblecache_p.h>
27#if QT_CONFIG(draganddrop)
28#include "qshapedpixmapdndwindow_p.h"
31#include <private/qevent_p.h>
32#include <private/qeventpoint_p.h>
33#include <private/qguiapplication_p.h>
35#include <QtCore/QTimer>
36#include <QtCore/QDebug>
39#include <qpa/qplatformcursor.h>
40#include <qpa/qplatformwindow_p.h>
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
124
125
126
127
128
129
130QWindow::QWindow(QScreen *targetScreen)
131 : QObject(*
new QWindowPrivate(),
nullptr)
132 , QSurface(QSurface::Window)
135 d->init(
nullptr, targetScreen);
139
140
141
142
143
144
145
146
147
148QWindow::QWindow(QWindow *parent)
149 : QWindow(*
new QWindowPrivate(), parent)
154
155
156
157
158
159
160
161
162
163
164
165QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
166 : QObject(dd,
nullptr)
167 , QSurface(QSurface::Window)
174
175
180#if QT_CONFIG(accessibility)
181 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
182 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
188 qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly));
193 QGuiApplicationPrivate::window_list.removeAll(
this);
194 QGuiApplicationPrivate::popup_list.removeAll(
this);
195 if (!QGuiApplicationPrivate::is_app_closing)
196 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
201 if (QGuiApplicationPrivate::focus_window ==
this)
202 QGuiApplicationPrivate::focus_window =
nullptr;
203 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
204 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
205 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
206 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
211QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
212 : QObjectPrivate(version)
215QWindowPrivate::~QWindowPrivate()
218void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
222 q->QObject::setParent(parent);
225 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
227 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
230 connectToScreen(connectScreen);
234 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
235 qFatal(
"Cannot create window: no screens available");
237 QGuiApplicationPrivate::window_list.prepend(q);
239 requestedFormat = QSurfaceFormat::defaultFormat();
240 devicePixelRatio = connectScreen->devicePixelRatio();
242 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
247 if (
const auto *handle = q->handle()) {
248 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q,
249 QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q),
250 QHighDpi::fromNativePixels(handle->geometry(), q));
251 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
256 updateDevicePixelRatio();
260 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
261 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316QWindow::Visibility QWindow::visibility()
const
319 return d->visibility;
322void QWindow::setVisibility(Visibility v)
328 case AutomaticVisibility:
349
350
351
352
353
354void QWindowPrivate::setVisible(
bool visible)
358 if (
this->visible != visible) {
359 this->visible = visible;
360 emit q->visibleChanged(visible);
362 }
else if (platformWindow) {
367 if (!platformWindow) {
370 if (parentWindow && !parentWindow->handle())
386 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
388 if (q->type() == Qt::Window) {
389 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
390 QString &firstWindowTitle = app_priv->firstWindowTitle;
391 if (!firstWindowTitle.isEmpty()) {
392 q->setTitle(firstWindowTitle);
393 firstWindowTitle = QString();
395 if (!app_priv->forcedWindowIcon.isNull())
396 q->setIcon(app_priv->forcedWindowIcon);
399 static bool geometryApplied =
false;
400 if (!geometryApplied) {
401 geometryApplied =
true;
402 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
406 QShowEvent showEvent;
407 QGuiApplication::sendEvent(q, &showEvent);
412 QGuiApplicationPrivate::showModalWindow(q);
414 QGuiApplicationPrivate::hideModalWindow(q);
417 }
else if (visible && QGuiApplication::modalWindow()
418#if QT_CONFIG(draganddrop)
419 && !qobject_cast<QShapedPixmapWindow *>(q)
422 QGuiApplicationPrivate::updateBlockedStatus(q);
425 if (q->type() == Qt::Popup) {
427 QGuiApplicationPrivate::activatePopup(q);
429 QGuiApplicationPrivate::closePopup(q);
433 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
438 platformWindow->setVisible(visible);
441 QHideEvent hideEvent;
442 QGuiApplication::sendEvent(q, &hideEvent);
446void QWindowPrivate::updateVisibility()
450 QWindow::Visibility old = visibility;
453 visibility = QWindow::Hidden;
454 else if (windowState & Qt::WindowMinimized)
455 visibility = QWindow::Minimized;
456 else if (windowState & Qt::WindowFullScreen)
457 visibility = QWindow::FullScreen;
458 else if (windowState & Qt::WindowMaximized)
459 visibility = QWindow::Maximized;
461 visibility = QWindow::Windowed;
463 if (visibility != old)
464 emit q->visibilityChanged(visibility);
467void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
474 QObjectList &siblings = q->parent()->d_ptr->children;
476 const qsizetype siblingCount = siblings.size() - 1;
477 if (siblingCount == 0)
480 const qsizetype currentPosition = siblings.indexOf(q);
481 Q_ASSERT(currentPosition >= 0);
483 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
485 if (currentPosition == targetPosition)
488 siblings.move(currentPosition, targetPosition);
491bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
494 const QScreen *oldScreen = q->screen();
495 return oldScreen != newScreen && (platformWindow || !oldScreen)
496 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
499void QWindowPrivate::disconnectFromScreen()
502 topLevelScreen =
nullptr;
505void QWindowPrivate::connectToScreen(QScreen *screen)
507 disconnectFromScreen();
508 topLevelScreen = screen;
511void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
514 emit q->screenChanged(newScreen);
515 for (QObject *child : q->children()) {
516 if (child->isWindowType())
517 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
521void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
526 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
529 if (newScreen != topLevelScreen) {
530 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
531 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
532 if (shouldRecreate && platformWindow)
534 connectToScreen(newScreen);
537 else if (newScreen && shouldRecreate)
539 emitScreenChangedRecursion(newScreen);
545void QWindowPrivate::create(
bool recursive)
552 const bool needsUpdate = updateRequestPending;
554 updateRequestPending =
false;
557 q->parent()->create();
559 if (platformWindow) {
568 if (q->isTopLevel()) {
569 if (QScreen *screen = screenForGeometry(geometry))
570 setTopLevelScreen(screen,
false);
573 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
575 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
576 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
577 : platformIntegration->createPlatformWindow(q);
578 Q_ASSERT(platformWindow);
580 if (!platformWindow) {
581 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
585 platformWindow->initialize();
587 QObjectList childObjects = q->children();
588 for (
int i = 0; i < childObjects.size(); i ++) {
589 QObject *object = childObjects.at(i);
590 if (!object->isWindowType())
593 QWindow *childWindow =
static_cast<QWindow *>(object);
595 childWindow->d_func()->create(recursive);
600 if (childWindow->isVisible())
601 childWindow->setVisible(
true);
603 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
604 childPlatformWindow->setParent(
this->platformWindow);
607 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
608 QGuiApplication::sendEvent(q, &e);
610 updateDevicePixelRatio();
616void QWindowPrivate::clearFocusObject()
623QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
629void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
630 qxp::function_ref<
void()> funcWidthChanged,
631 qxp::function_ref<
void()> funcHeightChanged)
634 Q_ASSERT(oldSizeMember);
635 const QSize adjustedSize =
636 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
637 if (*oldSizeMember == adjustedSize)
639 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
640 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
641 *oldSizeMember = adjustedSize;
643 if (platformWindow && q->isTopLevel())
644 platformWindow->propagateSizeHints();
652 if (minimumSize.width() <= maximumSize.width()
653 || minimumSize.height() <= maximumSize.height()) {
654 const QSize currentSize = q->size();
655 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
656 q->resize(boundedSize);
661
662
663
664
665
666
667
668
669
670
671
672
673void QWindow::setSurfaceType(SurfaceType surfaceType)
676 d->surfaceType = surfaceType;
680
681
682
683
684QWindow::SurfaceType QWindow::surfaceType()
const
687 return d->surfaceType;
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708void QWindow::setVisible(
bool visible)
712 d->setVisible(visible);
715bool QWindow::isVisible()
const
723
724
725
726
727
728
729
730
731
732
733
734
735
736void QWindow::create()
743
744
745
746
747
748
749
750
751
752
753WId QWindow::winId()
const
757 if (!d->platformWindow)
758 const_cast<QWindow *>(
this)->create();
760 if (!d->platformWindow)
763 return d->platformWindow->winId();
767
768
769
770
771
772
773
774
775
776QWindow *QWindow::parent(AncestorMode mode)
const
779 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
783
784
785
786
787
788
789
790
791
792void QWindow::setParent(QWindow *parent)
795 if (d->parentWindow == parent
797 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
801 QScreen *oldScreen = screen();
802 QScreen *newScreen = parent ? parent->screen() : oldScreen;
803 if (d->windowRecreationRequired(newScreen)) {
804 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
808 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
809 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
811 const auto previousParent = d->parentWindow;
812 QObject::setParent(parent);
813 d->parentWindow = parent;
816 d->disconnectFromScreen();
818 d->connectToScreen(newScreen);
823 if (isVisible() && (!parent || parent->handle()))
826 if (d->platformWindow) {
830 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
833 QGuiApplicationPrivate::updateBlockedStatus(
this);
835 if (previousParent) {
836 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
837 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
841 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
842 QCoreApplication::sendEvent(parent, &childAddedEvent);
845 QEvent parentChangedEvent(QEvent::ParentWindowChange);
846 QCoreApplication::sendEvent(
this, &parentChangedEvent);
848#if QT_CONFIG(accessibility)
849 if (!d->accessibleParent
850 && QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
851 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
852 QAccessible::updateAccessibility(&qaEvent);
862 if (parent && screen() != oldScreen)
863 d->emitScreenChangedRecursion(screen());
867
868
869bool QWindow::isTopLevel()
const
872 return d->parentWindow ==
nullptr;
876
877
878
879
880
881
882bool QWindow::isModal()
const
885 return d->modality != Qt::NonModal;
889
890
891
892
893
894
895
896
897
899Qt::WindowModality QWindow::modality()
const
905void QWindow::setModality(Qt::WindowModality modality)
908 if (d->modality == modality)
910 d->modality = modality;
911 emit modalityChanged(modality);
915
916
917
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945void QWindow::setFormat(
const QSurfaceFormat &format)
948 d->requestedFormat = format;
952
953
954
955
956
957
958
959
960
961QSurfaceFormat QWindow::requestedFormat()
const
964 return d->requestedFormat;
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984QSurfaceFormat QWindow::format()
const
987 if (d->platformWindow)
988 return d->platformWindow->format();
989 return d->requestedFormat;
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005void QWindow::setFlags(Qt::WindowFlags flags)
1008 if (d->windowFlags == flags)
1011 if (d->platformWindow)
1012 d->platformWindow->setWindowFlags(flags);
1014 d->windowFlags = flags;
1016 emit flagsChanged(
this->flags());
1019Qt::WindowFlags QWindow::flags()
const
1022 Qt::WindowFlags flags = d->windowFlags;
1024 if (d->platformWindow && d->platformWindow->isForeignWindow())
1025 flags |= Qt::ForeignWindow;
1031
1032
1033
1034
1035
1036
1037
1038void QWindow::setFlag(Qt::WindowType flag,
bool on)
1042 setFlags(d->windowFlags | flag);
1044 setFlags(d->windowFlags & ~flag);
1048
1049
1050
1051
1052
1053
1054
1055Qt::WindowType QWindow::type()
const
1057 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071void QWindow::setTitle(
const QString &title)
1074 bool changed =
false;
1075 if (d->windowTitle != title) {
1076 d->windowTitle = title;
1079 if (d->platformWindow)
1080 d->platformWindow->setWindowTitle(title);
1082 emit windowTitleChanged(title);
1085QString QWindow::title()
const
1088 return d->windowTitle;
1092
1093
1094
1095
1096
1097
1098void QWindow::setFilePath(
const QString &filePath)
1101 d->windowFilePath = filePath;
1102 if (d->platformWindow)
1103 d->platformWindow->setWindowFilePath(filePath);
1107
1108
1109
1110
1111QString QWindow::filePath()
const
1114 return d->windowFilePath;
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128void QWindow::setIcon(
const QIcon &icon)
1131 d->windowIcon = icon;
1132 if (d->platformWindow)
1133 d->platformWindow->setWindowIcon(icon);
1134 QEvent e(QEvent::WindowIconChange);
1135 QCoreApplication::sendEvent(
this, &e);
1139
1140
1141
1142
1143QIcon QWindow::icon()
const
1146 if (d->windowIcon.isNull())
1147 return QGuiApplication::windowIcon();
1148 return d->windowIcon;
1152
1153
1154
1155
1156void QWindow::raise()
1160 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1162 if (d->platformWindow)
1163 d->platformWindow->raise();
1167
1168
1169
1170
1171void QWindow::lower()
1175 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1177 if (d->platformWindow)
1178 d->platformWindow->lower();
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199bool QWindow::startSystemResize(Qt::Edges edges)
1202 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1205 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1206 const bool isCorner =
1207 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1208 edges == (Qt::TopEdge | Qt::RightEdge) ||
1209 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1210 edges == (Qt::BottomEdge | Qt::LeftEdge);
1212 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1213 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1217 return d->platformWindow->startSystemResize(edges);
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237bool QWindow::startSystemMove()
1240 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1243 return d->platformWindow->startSystemMove();
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260void QWindow::setOpacity(qreal level)
1263 if (level == d->opacity)
1266 if (d->platformWindow) {
1267 d->platformWindow->setOpacity(level);
1268 emit opacityChanged(level);
1272qreal QWindow::opacity()
const
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288void QWindow::setMask(
const QRegion ®ion)
1291 if (d->platformWindow)
1292 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1297
1298
1299
1300
1301
1302QRegion QWindow::mask()
const
1309
1310
1311
1312
1313void QWindow::requestActivate()
1316 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1317 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1320 if (d->platformWindow)
1321 d->platformWindow->requestActivateWindow();
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335bool QWindow::isExposed()
const
1342
1343
1344
1345
1346
1347
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361bool QWindow::isActive()
const
1364 if (!d->platformWindow)
1367 QWindow *focus = QGuiApplication::focusWindow();
1376 if (QWindow *p = parent(IncludeTransients))
1377 return p->isActive();
1379 return isAncestorOf(focus);
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1404 if (d->contentOrientation == orientation)
1406 if (d->platformWindow)
1407 d->platformWindow->handleContentOrientationChange(orientation);
1408 d->contentOrientation = orientation;
1409 emit contentOrientationChanged(orientation);
1412Qt::ScreenOrientation QWindow::contentOrientation()
const
1415 return d->contentOrientation;
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433qreal QWindow::devicePixelRatio()
const
1436 return d->devicePixelRatio;
1440
1441
1442
1443
1444bool QWindowPrivate::updateDevicePixelRatio()
1448 const qreal newDevicePixelRatio = [
this, q]{
1450 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1455 if (
auto *screen = q->screen())
1456 return screen->devicePixelRatio();
1459 return qGuiApp->devicePixelRatio();
1462 if (newDevicePixelRatio == devicePixelRatio)
1465 devicePixelRatio = newDevicePixelRatio;
1466 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1467 QGuiApplication::sendEvent(q, &dprChangeEvent);
1471Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1473 if (state & Qt::WindowMinimized)
1474 return Qt::WindowMinimized;
1475 else if (state & Qt::WindowFullScreen)
1476 return Qt::WindowFullScreen;
1477 else if (state & Qt::WindowMaximized)
1478 return Qt::WindowMaximized;
1479 return Qt::WindowNoState;
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492void QWindow::setWindowState(Qt::WindowState state)
1494 setWindowStates(state);
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513void QWindow::setWindowStates(Qt::WindowStates state)
1516 if (state & Qt::WindowActive) {
1517 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1518 state &= ~Qt::WindowActive;
1521 if (d->platformWindow)
1522 d->platformWindow->setWindowState(state);
1524 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1525 d->windowState = state;
1526 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1527 if (newEffectiveState != originalEffectiveState)
1528 emit windowStateChanged(newEffectiveState);
1530 d->updateVisibility();
1534
1535
1536
1537
1538Qt::WindowState QWindow::windowState()
const
1541 return QWindowPrivate::effectiveState(d->windowState);
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555Qt::WindowStates QWindow::windowStates()
const
1558 return d->windowState;
1562
1563
1564
1565
1566
1567
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583void QWindow::setTransientParent(QWindow *parent)
1586 if (parent && !parent->isTopLevel()) {
1587 qWarning() << parent <<
"must be a top level window.";
1590 if (parent ==
this) {
1591 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1595 d->transientParent = parent;
1597 QGuiApplicationPrivate::updateBlockedStatus(
this);
1598 emit transientParentChanged(parent);
1601QWindow *QWindow::transientParent()
const
1604 return d->transientParent.data();
1608
1609
1610
1611
1612
1613void QWindowPrivate::setTransientParent(QWindow *parent)
1616 q->setTransientParent(parent);
1617 transientParentPropertySet =
true;
1621
1622
1623
1624
1625
1626
1627
1628
1631
1632
1633
1634bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1636 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1639 if (QWindow *parent = child->parent(mode)) {
1640 if (isAncestorOf(parent, mode))
1642 }
else if (handle() && child->handle()) {
1643 if (handle()->isAncestorOf(child->handle()))
1651
1652
1653
1654
1655QSize QWindow::minimumSize()
const
1658 return d->minimumSize;
1662
1663
1664
1665
1666QSize QWindow::maximumSize()
const
1669 return d->maximumSize;
1673
1674
1675
1676
1677QSize QWindow::baseSize()
const
1684
1685
1686
1687
1688QSize QWindow::sizeIncrement()
const
1691 return d->sizeIncrement;
1695
1696
1697
1698
1699
1700
1701void QWindow::setMinimumSize(
const QSize &size)
1705 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1706 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1710
1711
1712
1713void QWindow::setX(
int arg)
1717 setGeometry(QRect(arg, y(), width(), height()));
1719 d->positionAutomatic =
false;
1723
1724
1725
1726void QWindow::setY(
int arg)
1730 setGeometry(QRect(x(), arg, width(), height()));
1732 d->positionAutomatic =
false;
1736
1737
1738
1739void QWindow::setWidth(
int w)
1741 resize(w, height());
1745
1746
1747
1748void QWindow::setHeight(
int h)
1754
1755
1756
1757void QWindow::setMinimumWidth(
int w)
1759 setMinimumSize(QSize(w, minimumHeight()));
1763
1764
1765
1766void QWindow::setMinimumHeight(
int h)
1768 setMinimumSize(QSize(minimumWidth(), h));
1772
1773
1774
1775
1776
1777
1778void QWindow::setMaximumSize(
const QSize &size)
1782 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1783 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1787
1788
1789
1790void QWindow::setMaximumWidth(
int w)
1792 setMaximumSize(QSize(w, maximumHeight()));
1796
1797
1798
1799void QWindow::setMaximumHeight(
int h)
1801 setMaximumSize(QSize(maximumWidth(), h));
1805
1806
1807
1808
1809
1810
1811
1812void QWindow::setBaseSize(
const QSize &size)
1815 if (d->baseSize == size)
1818 if (d->platformWindow && isTopLevel())
1819 d->platformWindow->propagateSizeHints();
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836void QWindow::setSizeIncrement(
const QSize &size)
1839 if (d->sizeIncrement == size)
1841 d->sizeIncrement = size;
1842 if (d->platformWindow && isTopLevel())
1843 d->platformWindow->propagateSizeHints();
1847
1848
1849
1850
1851
1852
1853
1854void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1856 setGeometry(QRect(posx, posy, w, h));
1860
1861
1862
1863
1864
1865
1866void QWindow::setGeometry(
const QRect &rect)
1869 d->positionAutomatic =
false;
1870 const QRect oldRect = geometry();
1871 if (rect == oldRect)
1874 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1875 if (d->platformWindow) {
1877 QScreen *newScreen = d->screenForGeometry(rect);
1878 d->platformWindow->setGeometry(QHighDpi::toNativeGlobalPosition(rect, newScreen));
1880 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1885 if (rect.x() != oldRect.x())
1886 emit xChanged(rect.x());
1887 if (rect.y() != oldRect.y())
1888 emit yChanged(rect.y());
1889 if (rect.width() != oldRect.width())
1890 emit widthChanged(rect.width());
1891 if (rect.height() != oldRect.height())
1892 emit heightChanged(rect.height());
1897
1898
1899
1900
1901
1902QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1905 QScreen *currentScreen = q->screen();
1906 QScreen *fallback = currentScreen;
1907 QPoint center = newGeometry.center();
1908 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1909 const auto screens = currentScreen->virtualSiblings();
1910 for (QScreen* screen : screens) {
1911 if (screen->geometry().contains(center))
1913 if (screen->geometry().intersects(newGeometry))
1922
1923
1924
1925
1926
1927
1928QRect QWindow::geometry()
const
1931 if (d->platformWindow) {
1932 const auto nativeGeometry = d->platformWindow->geometry();
1933 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1939
1940
1941
1942
1943QMargins QWindow::frameMargins()
const
1946 if (d->platformWindow)
1947 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1952
1953
1954
1955
1956
1957
1958QRect QWindow::frameGeometry()
const
1961 if (d->platformWindow) {
1962 QMargins m = frameMargins();
1963 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1969
1970
1971
1972
1973
1974
1975QPoint QWindow::framePosition()
const
1978 if (d->platformWindow) {
1979 QMargins margins = frameMargins();
1980 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1982 return d->geometry.topLeft();
1986
1987
1988
1989
1990
1991
1992void QWindow::setFramePosition(
const QPoint &point)
1995 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1996 d->positionAutomatic =
false;
1997 if (d->platformWindow) {
1998 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
2000 d->geometry.moveTopLeft(point);
2005
2006
2007
2008
2009
2010
2011
2012
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037QMargins QWindow::safeAreaMargins()
const
2040 if (d->platformWindow)
2041 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2046
2047
2048
2049
2050
2051
2052
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068void QWindow::setPosition(
const QPoint &pt)
2070 setGeometry(QRect(pt, size()));
2074
2075
2076
2077
2078
2079
2080void QWindow::setPosition(
int posx,
int posy)
2082 setPosition(QPoint(posx, posy));
2086
2087
2088
2089
2090
2091
2092
2093
2094
2097
2098
2099
2100
2101
2104
2105
2106
2107
2108
2109
2110
2111void QWindow::resize(
int w,
int h)
2113 resize(QSize(w, h));
2117
2118
2119
2120
2121void QWindow::resize(
const QSize &newSize)
2125 const QSize oldSize = size();
2126 if (newSize == oldSize)
2129 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2130 if (d->platformWindow) {
2131 d->platformWindow->setGeometry(
2132 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2134 d->geometry.setSize(newSize);
2135 if (newSize.width() != oldSize.width())
2136 emit widthChanged(newSize.width());
2137 if (newSize.height() != oldSize.height())
2138 emit heightChanged(newSize.height());
2143
2144
2145
2146
2147void QWindow::destroy()
2150 if (!d->platformWindow)
2153 if (d->platformWindow->isForeignWindow())
2159void QWindowPrivate::destroy()
2161 if (!platformWindow)
2165 QObjectList childrenWindows = q->children();
2166 for (
int i = 0; i < childrenWindows.size(); i++) {
2167 QObject *object = childrenWindows.at(i);
2168 if (object->isWindowType()) {
2169 QWindow *w =
static_cast<QWindow*>(object);
2170 qt_window_private(w)->destroy();
2174 bool wasVisible = q->isVisible();
2175 visibilityOnDestroy = wasVisible && platformWindow;
2177 q->setVisible(
false);
2188 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2189 QGuiApplication::sendEvent(q, &e);
2194 delete std::exchange(platformWindow,
nullptr);
2196 if (QGuiApplicationPrivate::focus_window == q)
2197 QGuiApplicationPrivate::focus_window = q->parent();
2198 if (QGuiApplicationPrivate::currentMouseWindow == q)
2199 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2200 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2201 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2203 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2204 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2205 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2207 resizeEventPending =
true;
2208 receivedExpose =
false;
2214 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2218
2219
2220
2221
2222QPlatformWindow *QWindow::handle()
const
2225 return d->platformWindow;
2229
2230
2231
2232
2233QPlatformSurface *QWindow::surfaceHandle()
const
2236 return d->platformWindow;
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249bool QWindow::setKeyboardGrabEnabled(
bool grab)
2252 if (d->platformWindow)
2253 return d->platformWindow->setKeyboardGrabEnabled(grab);
2258
2259
2260
2261
2262
2263
2264
2265
2266bool QWindow::setMouseGrabEnabled(
bool grab)
2269 if (d->platformWindow)
2270 return d->platformWindow->setMouseGrabEnabled(grab);
2275
2276
2277
2278
2279
2280
2281QScreen *QWindow::screen()
const
2284 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300void QWindow::setScreen(QScreen *newScreen)
2304 newScreen = QGuiApplication::primaryScreen();
2305 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2309
2310
2311
2312
2313
2314
2317
2318
2319
2320
2321QAccessibleInterface *QWindow::accessibleRoot()
const
2326#if QT_CONFIG(accessibility)
2328
2329
2330
2331
2332
2333
2334
2335
2336void QWindowPrivate::setAccessibleParent(QObject *parent)
2340 if (accessibleParent == parent)
2343 accessibleParent = parent;
2345 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
2346 QAccessibleEvent event(q, QAccessible::ParentChanged);
2347 QAccessible::updateAccessibility(&event);
2353
2354
2355
2356
2357
2358
2359
2362
2363
2364
2365QObject *QWindow::focusObject()
const
2367 return const_cast<QWindow *>(
this);
2371
2372
2373
2374
2375
2376
2377
2378
2384 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2385 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2386 if (defaultState == Qt::WindowFullScreen)
2388 else if (defaultState == Qt::WindowMaximized)
2396
2397
2398
2399
2400
2401
2408
2409
2410
2411
2412
2413
2414
2415void QWindow::showMinimized()
2417 setWindowStates(Qt::WindowMinimized);
2422
2423
2424
2425
2426
2427
2428
2429void QWindow::showMaximized()
2431 setWindowStates(Qt::WindowMaximized);
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446void QWindow::showFullScreen()
2448 setWindowStates(Qt::WindowFullScreen);
2450#if !defined Q_OS_QNX
2457
2458
2459
2460
2461
2462
2463
2464void QWindow::showNormal()
2466 setWindowStates(Qt::WindowNoState);
2471
2472
2473
2474
2475
2476
2477
2478
2479bool QWindow::close()
2489 if (!d->platformWindow) {
2492 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2493 QGuiApplicationPrivate::closePopup(
this);
2499 QPointer guard(
this);
2501 bool success = d->platformWindow->close();
2508bool QWindowPrivate::participatesInLastWindowClosed()
const
2512 if (!q->isTopLevel())
2518 if (q->type() == Qt::ToolTip)
2523 if (q->transientParent())
2529bool QWindowPrivate::treatAsVisible()
const
2532 return q->isVisible();
2536
2537
2538
2539const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2542 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2543 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2544 QWindow *ret =
nullptr;
2545 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2546 if (q == popupWindow)
2548 if (event->isPointerEvent()) {
2550 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2551 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2552 QEventPoint &eventPoint = pointerEvent->point(i);
2553 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2554 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2555 QMutableEventPoint::setPosition(eventPoint, mapped);
2556 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2560
2561
2562 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2563 event->setAccepted(pointerEvent->isAccepted());
2564 if (pointerEvent->isAccepted())
2567 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2568 <<
"handled?" << (ret !=
nullptr)
2569 <<
"accepted?" << event->isAccepted();
2571 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2572 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2574 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2575 <<
"handled?" << (ret !=
nullptr)
2576 <<
"accepted?" << event->isAccepted();
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601void QWindow::exposeEvent(QExposeEvent *ev)
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620void QWindow::paintEvent(QPaintEvent *ev)
2626
2627
2628void QWindow::moveEvent(QMoveEvent *ev)
2634
2635
2636
2637
2638
2639
2640void QWindow::resizeEvent(QResizeEvent *ev)
2646
2647
2648
2649
2650
2651
2652
2653void QWindow::showEvent(QShowEvent *ev)
2659
2660
2661
2662
2663
2664void QWindow::hideEvent(QHideEvent *ev)
2670
2671
2672
2673
2674
2675
2676
2677void QWindow::closeEvent(QCloseEvent *ev)
2683
2684
2685
2686
2687
2688
2689bool QWindow::event(QEvent *ev)
2692 switch (ev->type()) {
2693 case QEvent::MouseMove:
2694 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2697 case QEvent::MouseButtonPress: {
2698 auto *me =
static_cast<QMouseEvent*>(ev);
2699 mousePressEvent(me);
2700 if (!ev->isAccepted())
2701 d->maybeSynthesizeContextMenuEvent(me);
2705 case QEvent::MouseButtonRelease: {
2706 auto *me =
static_cast<QMouseEvent*>(ev);
2707 mouseReleaseEvent(me);
2708 if (!ev->isAccepted())
2709 d->maybeSynthesizeContextMenuEvent(me);
2713 case QEvent::MouseButtonDblClick:
2714 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2717 case QEvent::TouchBegin:
2718 case QEvent::TouchUpdate:
2719 case QEvent::TouchEnd:
2720 case QEvent::TouchCancel:
2721 touchEvent(
static_cast<QTouchEvent *>(ev));
2725 moveEvent(
static_cast<QMoveEvent*>(ev));
2728 case QEvent::Resize:
2729 resizeEvent(
static_cast<QResizeEvent*>(ev));
2732 case QEvent::KeyPress:
2733 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2736 case QEvent::KeyRelease:
2737 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2740 case QEvent::FocusIn: {
2741 focusInEvent(
static_cast<QFocusEvent *>(ev));
2742#if QT_CONFIG(accessibility)
2743 QAccessible::State state;
2744 state.active =
true;
2745 QAccessibleStateChangeEvent event(
this, state);
2746 QAccessible::updateAccessibility(&event);
2750 case QEvent::FocusOut: {
2751 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2752#if QT_CONFIG(accessibility)
2753 QAccessible::State state;
2754 state.active =
true;
2755 QAccessibleStateChangeEvent event(
this, state);
2756 QAccessible::updateAccessibility(&event);
2760#if QT_CONFIG(wheelevent)
2762 wheelEvent(
static_cast<QWheelEvent*>(ev));
2766 case QEvent::Close: {
2768 const bool wasVisible = d->treatAsVisible();
2769 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2772 QPointer<QWindow> deletionGuard(
this);
2773 closeEvent(
static_cast<QCloseEvent*>(ev));
2775 if (ev->isAccepted()) {
2778 if (wasVisible && participatesInLastWindowClosed)
2779 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2785 case QEvent::Expose:
2786 exposeEvent(
static_cast<QExposeEvent *>(ev));
2790 paintEvent(
static_cast<QPaintEvent *>(ev));
2794 showEvent(
static_cast<QShowEvent *>(ev));
2798 hideEvent(
static_cast<QHideEvent *>(ev));
2801 case QEvent::ApplicationWindowIconChange:
2805#if QT_CONFIG(tabletevent)
2806 case QEvent::TabletPress:
2807 case QEvent::TabletMove:
2808 case QEvent::TabletRelease:
2809 tabletEvent(
static_cast<QTabletEvent *>(ev));
2813 case QEvent::PlatformSurface: {
2814 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2816 QOpenGLContext *context = QOpenGLContext::currentContext();
2817 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2818 context->doneCurrent();
2825 return QObject::event(ev);
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2871#ifndef QT_NO_CONTEXTMENU
2872 if (event->button() == Qt::RightButton
2873 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2874 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2875 event->globalPosition().toPoint(), event->modifiers());
2876 qCDebug(lcPopup) <<
"synthesized after"
2877 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2878 << event->type() <<
":" << &e;
2879 QCoreApplication::forwardEvent(q_func(), &e, event);
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913void QWindow::requestUpdate()
2915 Q_ASSERT_X(QThread::isMainThread(),
2916 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2919 if (d->updateRequestPending || !d->platformWindow)
2921 d->updateRequestPending =
true;
2922 d->platformWindow->requestUpdate();
2926
2927
2928
2929
2930void QWindow::keyPressEvent(QKeyEvent *ev)
2936
2937
2938
2939
2940void QWindow::keyReleaseEvent(QKeyEvent *ev)
2946
2947
2948
2949
2950
2951
2952void QWindow::focusInEvent(QFocusEvent *ev)
2958
2959
2960
2961
2962
2963
2964void QWindow::focusOutEvent(QFocusEvent *ev)
2970
2971
2972
2973
2974void QWindow::mousePressEvent(QMouseEvent *ev)
2980
2981
2982
2983
2984void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2990
2991
2992
2993
2994void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
3000
3001
3002void QWindow::mouseMoveEvent(QMouseEvent *ev)
3007#if QT_CONFIG(wheelevent)
3009
3010
3011void QWindow::wheelEvent(QWheelEvent *ev)
3018
3019
3020void QWindow::touchEvent(QTouchEvent *ev)
3025#if QT_CONFIG(tabletevent)
3027
3028
3029
3030
3031
3032void QWindow::tabletEvent(QTabletEvent *ev)
3039
3040
3041
3042
3043
3044
3045
3047bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3049 Q_UNUSED(eventType);
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3069 if (d->platformWindow
3070 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3071 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3074 if (!QHighDpiScaling::isActive())
3075 return pos + d->globalPosition();
3083 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3087 QPointF nativeWindowGlobalPos = d->platformWindow
3088 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3089 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3090 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3091 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3092 return deviceIndependentGlobalPos;
3096
3097
3098QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3100 return mapToGlobal(QPointF(pos)).toPoint();
3104
3105
3106
3107
3108
3109
3110
3111
3112QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3116 if (d->platformWindow
3117 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3118 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3121 if (!QHighDpiScaling::isActive())
3122 return pos - d->globalPosition();
3126 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3130 QPointF nativeWindowGlobalPos = d->platformWindow
3131 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3132 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3133 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3134 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3135 return deviceIndependentLocalPos;
3139
3140
3141QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3143 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3146QPoint QWindowPrivate::globalPosition()
const
3149 QPoint offset = q->position();
3150 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3151 QPlatformWindow *pw = p->handle();
3152 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3154 offset += p->mapToGlobal(QPoint(0, 0));
3157 offset += p->position();
3165 return window->d_func();
3168QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3172 QWindow *window =
const_cast<QWindow *>(q);
3175 QWindow *parent = window->parent(mode);
3186
3187
3188
3189
3190
3191
3196#if QT_CONFIG(accessibility)
3198
3199
3200
3201
3202
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231QWindow *QWindow::fromWinId(WId id)
3233 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3234 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3238 QWindow *window =
new QForeignWindow;
3242 window->setProperty(kForeignWindowId, id);
3245 if (!window->handle()) {
3254
3255
3256
3257
3258
3259
3260
3261
3262
3264void QWindow::alert(
int msec)
3267 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3269 d->platformWindow->setAlertState(
true);
3270 if (d->platformWindow->isAlertState() && msec)
3271 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3274void QWindowPrivate::_q_clearAlert()
3276 if (platformWindow && platformWindow->isAlertState())
3277 platformWindow->setAlertState(
false);
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301void QWindow::setCursor(
const QCursor &cursor)
3304 d->setCursor(&cursor);
3308
3309
3310void QWindow::unsetCursor()
3313 d->setCursor(
nullptr);
3317
3318
3319
3320
3321QCursor QWindow::cursor()
const
3327void QWindowPrivate::setCursor(
const QCursor *newCursor)
3332 const Qt::CursorShape newShape = newCursor->shape();
3333 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3335 cursor = *newCursor;
3340 cursor = QCursor(Qt::ArrowCursor);
3344 if (applyCursor()) {
3345 QEvent event(QEvent::CursorChange);
3346 QGuiApplication::sendEvent(q, &event);
3351bool QWindowPrivate::applyCursor()
3354 if (QScreen *screen = q->screen()) {
3355 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3356 if (!platformWindow)
3358 QCursor *c = QGuiApplication::overrideCursor();
3359 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3361 if (!c && hasCursor)
3363 platformCursor->changeCursor(c, q);
3371void *QWindow::resolveInterface(
const char *name,
int revision)
const
3373 using namespace QNativeInterface::Private;
3375 auto *platformWindow = handle();
3376 Q_UNUSED(platformWindow);
3380#if defined(Q_OS_WIN)
3381 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3385 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3388#if defined(Q_OS_MACOS)
3389 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3392#if QT_CONFIG(wayland)
3393 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3396#if defined(Q_OS_WASM)
3397 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3403#ifndef QT_NO_DEBUG_STREAM
3404QDebug operator<<(QDebug debug,
const QWindow *window)
3406 QDebugStateSaver saver(debug);
3409 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3410 if (!window->objectName().isEmpty())
3411 debug <<
", name=" << window->objectName();
3412 if (debug.verbosity() > 2) {
3413 const QRect geometry = window->geometry();
3414 if (window->isVisible())
3415 debug <<
", visible";
3416 if (window->isExposed())
3417 debug <<
", exposed";
3418 debug <<
", state=" << window->windowState()
3419 <<
", type=" << window->type() <<
", flags=" << window->flags()
3420 <<
", surface type=" << window->surfaceType();
3421 if (window->isTopLevel())
3422 debug <<
", toplevel";
3423 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3424 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3425 const QMargins margins = window->frameMargins();
3426 if (!margins.isNull())
3427 debug <<
", margins=" << margins;
3428 const QMargins safeAreaMargins = window->safeAreaMargins();
3429 if (!safeAreaMargins.isNull())
3430 debug <<
", safeAreaMargins=" << safeAreaMargins;
3431 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3432 if (
const QPlatformWindow *platformWindow = window->handle())
3433 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3434 if (
const QScreen *screen = window->screen())
3435 debug <<
", on " << screen->name();
3439 debug <<
"QWindow(0x0)";
3445#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3448
3449
3450
3451
3452void QWindow::setVulkanInstance(QVulkanInstance *instance)
3455 d->vulkanInstance = instance;
3459
3460
3461QVulkanInstance *QWindow::vulkanInstance()
const
3464 return d->vulkanInstance;
3471#include "moc_qwindow.cpp"
3472#include "qwindow.moc"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId