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)
525 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
528 if (newScreen != topLevelScreen) {
529 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
530 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
531 if (shouldRecreate && platformWindow)
533 connectToScreen(newScreen);
536 else if (newScreen && shouldRecreate)
538 emitScreenChangedRecursion(newScreen);
544void QWindowPrivate::create(
bool recursive)
551 const bool needsUpdate = updateRequestPending;
553 updateRequestPending =
false;
556 q->parent()->create();
558 if (platformWindow) {
567 if (q->isTopLevel()) {
568 if (QScreen *screen = screenForGeometry(geometry))
569 setTopLevelScreen(screen,
false);
572 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
574 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
575 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
576 : platformIntegration->createPlatformWindow(q);
577 Q_ASSERT(platformWindow);
579 if (!platformWindow) {
580 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
584 platformWindow->initialize();
586 QObjectList childObjects = q->children();
587 for (
int i = 0; i < childObjects.size(); i ++) {
588 QObject *object = childObjects.at(i);
589 if (!object->isWindowType())
592 QWindow *childWindow =
static_cast<QWindow *>(object);
594 childWindow->d_func()->create(recursive);
599 if (childWindow->isVisible())
600 childWindow->setVisible(
true);
602 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
603 childPlatformWindow->setParent(
this->platformWindow);
606 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
607 QGuiApplication::sendEvent(q, &e);
609 updateDevicePixelRatio();
615void QWindowPrivate::clearFocusObject()
622QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
628void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
629 qxp::function_ref<
void()> funcWidthChanged,
630 qxp::function_ref<
void()> funcHeightChanged)
633 Q_ASSERT(oldSizeMember);
634 const QSize adjustedSize =
635 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
636 if (*oldSizeMember == adjustedSize)
638 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
639 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
640 *oldSizeMember = adjustedSize;
642 if (platformWindow && q->isTopLevel())
643 platformWindow->propagateSizeHints();
651 if (minimumSize.width() <= maximumSize.width()
652 || minimumSize.height() <= maximumSize.height()) {
653 const QSize currentSize = q->size();
654 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
655 q->resize(boundedSize);
660
661
662
663
664
665
666
667
668
669
670
671
672void QWindow::setSurfaceType(SurfaceType surfaceType)
675 d->surfaceType = surfaceType;
679
680
681
682
683QWindow::SurfaceType QWindow::surfaceType()
const
686 return d->surfaceType;
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707void QWindow::setVisible(
bool visible)
711 d->setVisible(visible);
714bool QWindow::isVisible()
const
722
723
724
725
726
727
728
729
730
731
732
733
734
735void QWindow::create()
742
743
744
745
746
747
748
749
750
751
752WId QWindow::winId()
const
756 if (!d->platformWindow)
757 const_cast<QWindow *>(
this)->create();
759 if (!d->platformWindow)
762 return d->platformWindow->winId();
766
767
768
769
770
771
772
773
774
775QWindow *QWindow::parent(AncestorMode mode)
const
778 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
782
783
784
785
786
787
788
789
790
791void QWindow::setParent(QWindow *parent)
794 if (d->parentWindow == parent
796 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
800 QScreen *oldScreen = screen();
801 QScreen *newScreen = parent ? parent->screen() : oldScreen;
802 if (d->windowRecreationRequired(newScreen)) {
803 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
807 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
808 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
810 const auto previousParent = d->parentWindow;
811 QObject::setParent(parent);
812 d->parentWindow = parent;
815 d->disconnectFromScreen();
817 d->connectToScreen(newScreen);
822 if (isVisible() && (!parent || parent->handle()))
825 if (d->platformWindow) {
829 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
832 QGuiApplicationPrivate::updateBlockedStatus(
this);
834 if (previousParent) {
835 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
836 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
840 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
841 QCoreApplication::sendEvent(parent, &childAddedEvent);
844 QEvent parentChangedEvent(QEvent::ParentWindowChange);
845 QCoreApplication::sendEvent(
this, &parentChangedEvent);
846#if QT_CONFIG(accessibility)
847 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
848 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
849 QAccessible::updateAccessibility(&qaEvent);
859 if (parent && screen() != oldScreen)
860 d->emitScreenChangedRecursion(screen());
864
865
866bool QWindow::isTopLevel()
const
869 return d->parentWindow ==
nullptr;
873
874
875
876
877
878
879bool QWindow::isModal()
const
882 return d->modality != Qt::NonModal;
886
887
888
889
890
891
892
893
894
896Qt::WindowModality QWindow::modality()
const
902void QWindow::setModality(Qt::WindowModality modality)
905 if (d->modality == modality)
907 d->modality = modality;
908 emit modalityChanged(modality);
912
913
914
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942void QWindow::setFormat(
const QSurfaceFormat &format)
945 d->requestedFormat = format;
949
950
951
952
953
954
955
956
957
958QSurfaceFormat QWindow::requestedFormat()
const
961 return d->requestedFormat;
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981QSurfaceFormat QWindow::format()
const
984 if (d->platformWindow)
985 return d->platformWindow->format();
986 return d->requestedFormat;
990
991
992
993
994
995
996
997
998
999
1000
1001
1002void QWindow::setFlags(Qt::WindowFlags flags)
1005 if (d->windowFlags == flags)
1008 if (d->platformWindow)
1009 d->platformWindow->setWindowFlags(flags);
1011 d->windowFlags = flags;
1013 emit flagsChanged(
this->flags());
1016Qt::WindowFlags QWindow::flags()
const
1019 Qt::WindowFlags flags = d->windowFlags;
1021 if (d->platformWindow && d->platformWindow->isForeignWindow())
1022 flags |= Qt::ForeignWindow;
1028
1029
1030
1031
1032
1033
1034
1035void QWindow::setFlag(Qt::WindowType flag,
bool on)
1039 setFlags(d->windowFlags | flag);
1041 setFlags(d->windowFlags & ~flag);
1045
1046
1047
1048
1049
1050
1051
1052Qt::WindowType QWindow::type()
const
1054 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068void QWindow::setTitle(
const QString &title)
1071 bool changed =
false;
1072 if (d->windowTitle != title) {
1073 d->windowTitle = title;
1076 if (d->platformWindow)
1077 d->platformWindow->setWindowTitle(title);
1079 emit windowTitleChanged(title);
1082QString QWindow::title()
const
1085 return d->windowTitle;
1089
1090
1091
1092
1093
1094
1095void QWindow::setFilePath(
const QString &filePath)
1098 d->windowFilePath = filePath;
1099 if (d->platformWindow)
1100 d->platformWindow->setWindowFilePath(filePath);
1104
1105
1106
1107
1108QString QWindow::filePath()
const
1111 return d->windowFilePath;
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125void QWindow::setIcon(
const QIcon &icon)
1128 d->windowIcon = icon;
1129 if (d->platformWindow)
1130 d->platformWindow->setWindowIcon(icon);
1131 QEvent e(QEvent::WindowIconChange);
1132 QCoreApplication::sendEvent(
this, &e);
1136
1137
1138
1139
1140QIcon QWindow::icon()
const
1143 if (d->windowIcon.isNull())
1144 return QGuiApplication::windowIcon();
1145 return d->windowIcon;
1149
1150
1151
1152
1153void QWindow::raise()
1157 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1159 if (d->platformWindow)
1160 d->platformWindow->raise();
1164
1165
1166
1167
1168void QWindow::lower()
1172 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1174 if (d->platformWindow)
1175 d->platformWindow->lower();
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196bool QWindow::startSystemResize(Qt::Edges edges)
1199 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1202 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1203 const bool isCorner =
1204 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1205 edges == (Qt::TopEdge | Qt::RightEdge) ||
1206 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1207 edges == (Qt::BottomEdge | Qt::LeftEdge);
1209 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1210 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1214 return d->platformWindow->startSystemResize(edges);
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234bool QWindow::startSystemMove()
1237 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1240 return d->platformWindow->startSystemMove();
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257void QWindow::setOpacity(qreal level)
1260 if (level == d->opacity)
1263 if (d->platformWindow) {
1264 d->platformWindow->setOpacity(level);
1265 emit opacityChanged(level);
1269qreal QWindow::opacity()
const
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285void QWindow::setMask(
const QRegion ®ion)
1288 if (d->platformWindow)
1289 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1294
1295
1296
1297
1298
1299QRegion QWindow::mask()
const
1306
1307
1308
1309
1310void QWindow::requestActivate()
1313 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1314 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1317 if (d->platformWindow)
1318 d->platformWindow->requestActivateWindow();
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332bool QWindow::isExposed()
const
1339
1340
1341
1342
1343
1344
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358bool QWindow::isActive()
const
1361 if (!d->platformWindow)
1364 QWindow *focus = QGuiApplication::focusWindow();
1373 if (QWindow *p = parent(IncludeTransients))
1374 return p->isActive();
1376 return isAncestorOf(focus);
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1401 if (d->contentOrientation == orientation)
1403 if (d->platformWindow)
1404 d->platformWindow->handleContentOrientationChange(orientation);
1405 d->contentOrientation = orientation;
1406 emit contentOrientationChanged(orientation);
1409Qt::ScreenOrientation QWindow::contentOrientation()
const
1412 return d->contentOrientation;
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430qreal QWindow::devicePixelRatio()
const
1433 return d->devicePixelRatio;
1437
1438
1439
1440
1441bool QWindowPrivate::updateDevicePixelRatio()
1445 const qreal newDevicePixelRatio = [
this, q]{
1447 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1452 if (
auto *screen = q->screen())
1453 return screen->devicePixelRatio();
1456 return qGuiApp->devicePixelRatio();
1459 if (newDevicePixelRatio == devicePixelRatio)
1462 devicePixelRatio = newDevicePixelRatio;
1463 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1464 QGuiApplication::sendEvent(q, &dprChangeEvent);
1468Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1470 if (state & Qt::WindowMinimized)
1471 return Qt::WindowMinimized;
1472 else if (state & Qt::WindowFullScreen)
1473 return Qt::WindowFullScreen;
1474 else if (state & Qt::WindowMaximized)
1475 return Qt::WindowMaximized;
1476 return Qt::WindowNoState;
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489void QWindow::setWindowState(Qt::WindowState state)
1491 setWindowStates(state);
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510void QWindow::setWindowStates(Qt::WindowStates state)
1513 if (state & Qt::WindowActive) {
1514 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1515 state &= ~Qt::WindowActive;
1518 if (d->platformWindow)
1519 d->platformWindow->setWindowState(state);
1521 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1522 d->windowState = state;
1523 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1524 if (newEffectiveState != originalEffectiveState)
1525 emit windowStateChanged(newEffectiveState);
1527 d->updateVisibility();
1531
1532
1533
1534
1535Qt::WindowState QWindow::windowState()
const
1538 return QWindowPrivate::effectiveState(d->windowState);
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552Qt::WindowStates QWindow::windowStates()
const
1555 return d->windowState;
1559
1560
1561
1562
1563
1564
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580void QWindow::setTransientParent(QWindow *parent)
1583 if (parent && !parent->isTopLevel()) {
1584 qWarning() << parent <<
"must be a top level window.";
1587 if (parent ==
this) {
1588 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1592 d->transientParent = parent;
1594 QGuiApplicationPrivate::updateBlockedStatus(
this);
1595 emit transientParentChanged(parent);
1598QWindow *QWindow::transientParent()
const
1601 return d->transientParent.data();
1605
1606
1607
1608
1609
1610void QWindowPrivate::setTransientParent(QWindow *parent)
1613 q->setTransientParent(parent);
1614 transientParentPropertySet =
true;
1618
1619
1620
1621
1622
1623
1624
1625
1628
1629
1630
1631bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1633 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1636 if (QWindow *parent = child->parent(mode)) {
1637 if (isAncestorOf(parent, mode))
1639 }
else if (handle() && child->handle()) {
1640 if (handle()->isAncestorOf(child->handle()))
1648
1649
1650
1651
1652QSize QWindow::minimumSize()
const
1655 return d->minimumSize;
1659
1660
1661
1662
1663QSize QWindow::maximumSize()
const
1666 return d->maximumSize;
1670
1671
1672
1673
1674QSize QWindow::baseSize()
const
1681
1682
1683
1684
1685QSize QWindow::sizeIncrement()
const
1688 return d->sizeIncrement;
1692
1693
1694
1695
1696
1697
1698void QWindow::setMinimumSize(
const QSize &size)
1702 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1703 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1707
1708
1709
1710void QWindow::setX(
int arg)
1714 setGeometry(QRect(arg, y(), width(), height()));
1716 d->positionAutomatic =
false;
1720
1721
1722
1723void QWindow::setY(
int arg)
1727 setGeometry(QRect(x(), arg, width(), height()));
1729 d->positionAutomatic =
false;
1733
1734
1735
1736void QWindow::setWidth(
int w)
1738 resize(w, height());
1742
1743
1744
1745void QWindow::setHeight(
int h)
1751
1752
1753
1754void QWindow::setMinimumWidth(
int w)
1756 setMinimumSize(QSize(w, minimumHeight()));
1760
1761
1762
1763void QWindow::setMinimumHeight(
int h)
1765 setMinimumSize(QSize(minimumWidth(), h));
1769
1770
1771
1772
1773
1774
1775void QWindow::setMaximumSize(
const QSize &size)
1779 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1780 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1784
1785
1786
1787void QWindow::setMaximumWidth(
int w)
1789 setMaximumSize(QSize(w, maximumHeight()));
1793
1794
1795
1796void QWindow::setMaximumHeight(
int h)
1798 setMaximumSize(QSize(maximumWidth(), h));
1802
1803
1804
1805
1806
1807
1808
1809void QWindow::setBaseSize(
const QSize &size)
1812 if (d->baseSize == size)
1815 if (d->platformWindow && isTopLevel())
1816 d->platformWindow->propagateSizeHints();
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833void QWindow::setSizeIncrement(
const QSize &size)
1836 if (d->sizeIncrement == size)
1838 d->sizeIncrement = size;
1839 if (d->platformWindow && isTopLevel())
1840 d->platformWindow->propagateSizeHints();
1844
1845
1846
1847
1848
1849
1850
1851void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1853 setGeometry(QRect(posx, posy, w, h));
1857
1858
1859
1860
1861
1862
1863void QWindow::setGeometry(
const QRect &rect)
1866 d->positionAutomatic =
false;
1867 const QRect oldRect = geometry();
1868 if (rect == oldRect)
1871 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1872 if (d->platformWindow) {
1880 QScreen *newScreen = d->screenForGeometry(rect);
1881 if (newScreen && isTopLevel())
1882 d->setTopLevelScreen(newScreen,
true);
1883 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1887 if (rect.x() != oldRect.x())
1888 emit xChanged(rect.x());
1889 if (rect.y() != oldRect.y())
1890 emit yChanged(rect.y());
1891 if (rect.width() != oldRect.width())
1892 emit widthChanged(rect.width());
1893 if (rect.height() != oldRect.height())
1894 emit heightChanged(rect.height());
1899
1900
1901
1902
1903
1904QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1907 QScreen *currentScreen = q->screen();
1908 QScreen *fallback = currentScreen;
1909 QPoint center = newGeometry.center();
1910 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1911 const auto screens = currentScreen->virtualSiblings();
1912 for (QScreen* screen : screens) {
1913 if (screen->geometry().contains(center))
1915 if (screen->geometry().intersects(newGeometry))
1924
1925
1926
1927
1928
1929
1930QRect QWindow::geometry()
const
1933 if (d->platformWindow) {
1934 const auto nativeGeometry = d->platformWindow->geometry();
1935 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1941
1942
1943
1944
1945QMargins QWindow::frameMargins()
const
1948 if (d->platformWindow)
1949 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1954
1955
1956
1957
1958
1959
1960QRect QWindow::frameGeometry()
const
1963 if (d->platformWindow) {
1964 QMargins m = frameMargins();
1965 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1971
1972
1973
1974
1975
1976
1977QPoint QWindow::framePosition()
const
1980 if (d->platformWindow) {
1981 QMargins margins = frameMargins();
1982 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1984 return d->geometry.topLeft();
1988
1989
1990
1991
1992
1993
1994void QWindow::setFramePosition(
const QPoint &point)
1997 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1998 d->positionAutomatic =
false;
1999 if (d->platformWindow) {
2000 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
2002 d->geometry.moveTopLeft(point);
2007
2008
2009
2010
2011
2012
2013
2014
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039QMargins QWindow::safeAreaMargins()
const
2042 if (d->platformWindow)
2043 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2048
2049
2050
2051
2052
2053
2054
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070void QWindow::setPosition(
const QPoint &pt)
2072 setGeometry(QRect(pt, size()));
2076
2077
2078
2079
2080
2081
2082void QWindow::setPosition(
int posx,
int posy)
2084 setPosition(QPoint(posx, posy));
2088
2089
2090
2091
2092
2093
2094
2095
2096
2099
2100
2101
2102
2103
2106
2107
2108
2109
2110
2111
2112
2113void QWindow::resize(
int w,
int h)
2115 resize(QSize(w, h));
2119
2120
2121
2122
2123void QWindow::resize(
const QSize &newSize)
2127 const QSize oldSize = size();
2128 if (newSize == oldSize)
2131 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2132 if (d->platformWindow) {
2133 d->platformWindow->setGeometry(
2134 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2136 d->geometry.setSize(newSize);
2137 if (newSize.width() != oldSize.width())
2138 emit widthChanged(newSize.width());
2139 if (newSize.height() != oldSize.height())
2140 emit heightChanged(newSize.height());
2145
2146
2147
2148
2149void QWindow::destroy()
2152 if (!d->platformWindow)
2155 if (d->platformWindow->isForeignWindow())
2161void QWindowPrivate::destroy()
2163 if (!platformWindow)
2167 QObjectList childrenWindows = q->children();
2168 for (
int i = 0; i < childrenWindows.size(); i++) {
2169 QObject *object = childrenWindows.at(i);
2170 if (object->isWindowType()) {
2171 QWindow *w =
static_cast<QWindow*>(object);
2172 qt_window_private(w)->destroy();
2176 bool wasVisible = q->isVisible();
2177 visibilityOnDestroy = wasVisible && platformWindow;
2179 q->setVisible(
false);
2190 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2191 QGuiApplication::sendEvent(q, &e);
2196 delete std::exchange(platformWindow,
nullptr);
2198 if (QGuiApplicationPrivate::focus_window == q)
2199 QGuiApplicationPrivate::focus_window = q->parent();
2200 if (QGuiApplicationPrivate::currentMouseWindow == q)
2201 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2202 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2203 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2205 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2206 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2207 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2209 resizeEventPending =
true;
2210 receivedExpose =
false;
2216 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2220
2221
2222
2223
2224QPlatformWindow *QWindow::handle()
const
2227 return d->platformWindow;
2231
2232
2233
2234
2235QPlatformSurface *QWindow::surfaceHandle()
const
2238 return d->platformWindow;
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251bool QWindow::setKeyboardGrabEnabled(
bool grab)
2254 if (d->platformWindow)
2255 return d->platformWindow->setKeyboardGrabEnabled(grab);
2260
2261
2262
2263
2264
2265
2266
2267
2268bool QWindow::setMouseGrabEnabled(
bool grab)
2271 if (d->platformWindow)
2272 return d->platformWindow->setMouseGrabEnabled(grab);
2277
2278
2279
2280
2281
2282
2283QScreen *QWindow::screen()
const
2286 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302void QWindow::setScreen(QScreen *newScreen)
2306 newScreen = QGuiApplication::primaryScreen();
2307 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2311
2312
2313
2314
2315
2316
2319
2320
2321
2322
2323QAccessibleInterface *QWindow::accessibleRoot()
const
2329
2330
2331
2332
2333
2334
2335
2338
2339
2340
2341QObject *QWindow::focusObject()
const
2343 return const_cast<QWindow *>(
this);
2347
2348
2349
2350
2351
2352
2353
2354
2360 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2361 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2362 if (defaultState == Qt::WindowFullScreen)
2364 else if (defaultState == Qt::WindowMaximized)
2372
2373
2374
2375
2376
2377
2384
2385
2386
2387
2388
2389
2390
2391void QWindow::showMinimized()
2393 setWindowStates(Qt::WindowMinimized);
2398
2399
2400
2401
2402
2403
2404
2405void QWindow::showMaximized()
2407 setWindowStates(Qt::WindowMaximized);
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422void QWindow::showFullScreen()
2424 setWindowStates(Qt::WindowFullScreen);
2426#if !defined Q_OS_QNX
2433
2434
2435
2436
2437
2438
2439
2440void QWindow::showNormal()
2442 setWindowStates(Qt::WindowNoState);
2447
2448
2449
2450
2451
2452
2453
2454
2455bool QWindow::close()
2465 if (!d->platformWindow) {
2468 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2469 QGuiApplicationPrivate::closePopup(
this);
2475 QPointer guard(
this);
2477 bool success = d->platformWindow->close();
2484bool QWindowPrivate::participatesInLastWindowClosed()
const
2488 if (!q->isTopLevel())
2494 if (q->type() == Qt::ToolTip)
2499 if (q->transientParent())
2505bool QWindowPrivate::treatAsVisible()
const
2508 return q->isVisible();
2512
2513
2514
2515const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2518 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2519 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2520 QWindow *ret =
nullptr;
2521 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2522 if (q == popupWindow)
2524 if (event->isPointerEvent()) {
2526 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2527 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2528 QEventPoint &eventPoint = pointerEvent->point(i);
2529 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2530 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2531 QMutableEventPoint::setPosition(eventPoint, mapped);
2532 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2536
2537
2538 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2539 event->setAccepted(pointerEvent->isAccepted());
2540 if (pointerEvent->isAccepted())
2543 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2544 <<
"handled?" << (ret !=
nullptr)
2545 <<
"accepted?" << event->isAccepted();
2547 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2548 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2550 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2551 <<
"handled?" << (ret !=
nullptr)
2552 <<
"accepted?" << event->isAccepted();
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577void QWindow::exposeEvent(QExposeEvent *ev)
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596void QWindow::paintEvent(QPaintEvent *ev)
2602
2603
2604void QWindow::moveEvent(QMoveEvent *ev)
2610
2611
2612
2613
2614
2615
2616void QWindow::resizeEvent(QResizeEvent *ev)
2622
2623
2624
2625
2626
2627
2628
2629void QWindow::showEvent(QShowEvent *ev)
2635
2636
2637
2638
2639
2640void QWindow::hideEvent(QHideEvent *ev)
2646
2647
2648
2649
2650
2651
2652
2653void QWindow::closeEvent(QCloseEvent *ev)
2659
2660
2661
2662
2663
2664
2665bool QWindow::event(QEvent *ev)
2668 switch (ev->type()) {
2669 case QEvent::MouseMove:
2670 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2673 case QEvent::MouseButtonPress: {
2674 auto *me =
static_cast<QMouseEvent*>(ev);
2675 mousePressEvent(me);
2676 if (!ev->isAccepted())
2677 d->maybeSynthesizeContextMenuEvent(me);
2681 case QEvent::MouseButtonRelease: {
2682 auto *me =
static_cast<QMouseEvent*>(ev);
2683 mouseReleaseEvent(me);
2684 if (!ev->isAccepted())
2685 d->maybeSynthesizeContextMenuEvent(me);
2689 case QEvent::MouseButtonDblClick:
2690 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2693 case QEvent::TouchBegin:
2694 case QEvent::TouchUpdate:
2695 case QEvent::TouchEnd:
2696 case QEvent::TouchCancel:
2697 touchEvent(
static_cast<QTouchEvent *>(ev));
2701 moveEvent(
static_cast<QMoveEvent*>(ev));
2704 case QEvent::Resize:
2705 resizeEvent(
static_cast<QResizeEvent*>(ev));
2708 case QEvent::KeyPress:
2709 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2712 case QEvent::KeyRelease:
2713 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2716 case QEvent::FocusIn: {
2717 focusInEvent(
static_cast<QFocusEvent *>(ev));
2718#if QT_CONFIG(accessibility)
2719 QAccessible::State state;
2720 state.active =
true;
2721 QAccessibleStateChangeEvent event(
this, state);
2722 QAccessible::updateAccessibility(&event);
2726 case QEvent::FocusOut: {
2727 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2728#if QT_CONFIG(accessibility)
2729 QAccessible::State state;
2730 state.active =
true;
2731 QAccessibleStateChangeEvent event(
this, state);
2732 QAccessible::updateAccessibility(&event);
2736#if QT_CONFIG(wheelevent)
2738 wheelEvent(
static_cast<QWheelEvent*>(ev));
2742 case QEvent::Close: {
2744 const bool wasVisible = d->treatAsVisible();
2745 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2748 QPointer<QWindow> deletionGuard(
this);
2749 closeEvent(
static_cast<QCloseEvent*>(ev));
2751 if (ev->isAccepted()) {
2754 if (wasVisible && participatesInLastWindowClosed)
2755 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2761 case QEvent::Expose:
2762 exposeEvent(
static_cast<QExposeEvent *>(ev));
2766 paintEvent(
static_cast<QPaintEvent *>(ev));
2770 showEvent(
static_cast<QShowEvent *>(ev));
2774 hideEvent(
static_cast<QHideEvent *>(ev));
2777 case QEvent::ApplicationWindowIconChange:
2781#if QT_CONFIG(tabletevent)
2782 case QEvent::TabletPress:
2783 case QEvent::TabletMove:
2784 case QEvent::TabletRelease:
2785 tabletEvent(
static_cast<QTabletEvent *>(ev));
2789 case QEvent::PlatformSurface: {
2790 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2792 QOpenGLContext *context = QOpenGLContext::currentContext();
2793 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2794 context->doneCurrent();
2801 return QObject::event(ev);
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2847#ifndef QT_NO_CONTEXTMENU
2848 if (event->button() == Qt::RightButton
2849 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2850 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2851 event->globalPosition().toPoint(), event->modifiers());
2852 qCDebug(lcPopup) <<
"synthesized after"
2853 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2854 << event->type() <<
":" << &e;
2855 QCoreApplication::forwardEvent(q_func(), &e, event);
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889void QWindow::requestUpdate()
2891 Q_ASSERT_X(QThread::isMainThread(),
2892 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2895 if (d->updateRequestPending || !d->platformWindow)
2897 d->updateRequestPending =
true;
2898 d->platformWindow->requestUpdate();
2902
2903
2904
2905
2906void QWindow::keyPressEvent(QKeyEvent *ev)
2912
2913
2914
2915
2916void QWindow::keyReleaseEvent(QKeyEvent *ev)
2922
2923
2924
2925
2926
2927
2928void QWindow::focusInEvent(QFocusEvent *ev)
2934
2935
2936
2937
2938
2939
2940void QWindow::focusOutEvent(QFocusEvent *ev)
2946
2947
2948
2949
2950void QWindow::mousePressEvent(QMouseEvent *ev)
2956
2957
2958
2959
2960void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2966
2967
2968
2969
2970void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2976
2977
2978void QWindow::mouseMoveEvent(QMouseEvent *ev)
2983#if QT_CONFIG(wheelevent)
2985
2986
2987void QWindow::wheelEvent(QWheelEvent *ev)
2994
2995
2996void QWindow::touchEvent(QTouchEvent *ev)
3001#if QT_CONFIG(tabletevent)
3003
3004
3005
3006
3007
3008void QWindow::tabletEvent(QTabletEvent *ev)
3015
3016
3017
3018
3019
3020
3021
3023bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3025 Q_UNUSED(eventType);
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3045 if (d->platformWindow
3046 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3047 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3050 if (!QHighDpiScaling::isActive())
3051 return pos + d->globalPosition();
3059 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3063 QPointF nativeWindowGlobalPos = d->platformWindow
3064 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3065 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3066 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3067 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3068 return deviceIndependentGlobalPos;
3072
3073
3074QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3076 return mapToGlobal(QPointF(pos)).toPoint();
3080
3081
3082
3083
3084
3085
3086
3087
3088QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3092 if (d->platformWindow
3093 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3094 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3097 if (!QHighDpiScaling::isActive())
3098 return pos - d->globalPosition();
3102 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3106 QPointF nativeWindowGlobalPos = d->platformWindow
3107 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3108 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3109 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3110 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3111 return deviceIndependentLocalPos;
3115
3116
3117QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3119 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3122QPoint QWindowPrivate::globalPosition()
const
3125 QPoint offset = q->position();
3126 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3127 QPlatformWindow *pw = p->handle();
3128 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3130 offset += p->mapToGlobal(QPoint(0, 0));
3133 offset += p->position();
3141 return window->d_func();
3144QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3148 QWindow *window =
const_cast<QWindow *>(q);
3151 QWindow *parent = window->parent(mode);
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182QWindow *QWindow::fromWinId(WId id)
3184 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3185 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3189 QWindow *window =
new QWindow;
3193 window->setProperty(kForeignWindowId, id);
3196 if (!window->handle()) {
3205
3206
3207
3208
3209
3210
3211
3212
3213
3215void QWindow::alert(
int msec)
3218 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3220 d->platformWindow->setAlertState(
true);
3221 if (d->platformWindow->isAlertState() && msec)
3222 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3225void QWindowPrivate::_q_clearAlert()
3227 if (platformWindow && platformWindow->isAlertState())
3228 platformWindow->setAlertState(
false);
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252void QWindow::setCursor(
const QCursor &cursor)
3255 d->setCursor(&cursor);
3259
3260
3261void QWindow::unsetCursor()
3264 d->setCursor(
nullptr);
3268
3269
3270
3271
3272QCursor QWindow::cursor()
const
3278void QWindowPrivate::setCursor(
const QCursor *newCursor)
3283 const Qt::CursorShape newShape = newCursor->shape();
3284 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3286 cursor = *newCursor;
3291 cursor = QCursor(Qt::ArrowCursor);
3295 if (applyCursor()) {
3296 QEvent event(QEvent::CursorChange);
3297 QGuiApplication::sendEvent(q, &event);
3302bool QWindowPrivate::applyCursor()
3305 if (QScreen *screen = q->screen()) {
3306 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3307 if (!platformWindow)
3309 QCursor *c = QGuiApplication::overrideCursor();
3310 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3312 if (!c && hasCursor)
3314 platformCursor->changeCursor(c, q);
3322void *QWindow::resolveInterface(
const char *name,
int revision)
const
3324 using namespace QNativeInterface::Private;
3326 auto *platformWindow = handle();
3327 Q_UNUSED(platformWindow);
3331#if defined(Q_OS_WIN)
3332 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3336 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3339#if defined(Q_OS_MACOS)
3340 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3343#if QT_CONFIG(wayland)
3344 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3347#if defined(Q_OS_WASM)
3348 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3354#ifndef QT_NO_DEBUG_STREAM
3355QDebug operator<<(QDebug debug,
const QWindow *window)
3357 QDebugStateSaver saver(debug);
3360 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3361 if (!window->objectName().isEmpty())
3362 debug <<
", name=" << window->objectName();
3363 if (debug.verbosity() > 2) {
3364 const QRect geometry = window->geometry();
3365 if (window->isVisible())
3366 debug <<
", visible";
3367 if (window->isExposed())
3368 debug <<
", exposed";
3369 debug <<
", state=" << window->windowState()
3370 <<
", type=" << window->type() <<
", flags=" << window->flags()
3371 <<
", surface type=" << window->surfaceType();
3372 if (window->isTopLevel())
3373 debug <<
", toplevel";
3374 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3375 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3376 const QMargins margins = window->frameMargins();
3377 if (!margins.isNull())
3378 debug <<
", margins=" << margins;
3379 const QMargins safeAreaMargins = window->safeAreaMargins();
3380 if (!safeAreaMargins.isNull())
3381 debug <<
", safeAreaMargins=" << safeAreaMargins;
3382 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3383 if (
const QPlatformWindow *platformWindow = window->handle())
3384 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3385 if (
const QScreen *screen = window->screen())
3386 debug <<
", on " << screen->name();
3390 debug <<
"QWindow(0x0)";
3396#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3399
3400
3401
3402
3403void QWindow::setVulkanInstance(QVulkanInstance *instance)
3406 d->vulkanInstance = instance;
3410
3411
3412QVulkanInstance *QWindow::vulkanInstance()
const
3415 return d->vulkanInstance;
3422#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId