6#include <qpa/qplatformwindow.h>
7#include <qpa/qplatformintegration.h>
8#ifndef QT_NO_CONTEXTMENU
9#include <qpa/qplatformtheme.h>
13#include <qpa/qplatformopenglcontext.h>
21#if QT_CONFIG(accessibility)
22# include "qaccessible.h"
23# include <private/qaccessiblecache_p.h>
26#if QT_CONFIG(draganddrop)
27#include "qshapedpixmapdndwindow_p.h"
30#include <private/qevent_p.h>
31#include <private/qeventpoint_p.h>
32#include <private/qguiapplication_p.h>
34#include <QtCore/QTimer>
35#include <QtCore/QDebug>
38#include <qpa/qplatformcursor.h>
39#include <qpa/qplatformwindow_p.h>
44
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
123
124
125
126
127
128
129QWindow::QWindow(QScreen *targetScreen)
130 : QObject(*
new QWindowPrivate(),
nullptr)
131 , QSurface(QSurface::Window)
134 d->init(
nullptr, targetScreen);
138
139
140
141
142
143
144
145
146
147QWindow::QWindow(QWindow *parent)
148 : QWindow(*
new QWindowPrivate(), parent)
153
154
155
156
157
158
159
160
161
162
163
164QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
165 : QObject(dd,
nullptr)
166 , QSurface(QSurface::Window)
173
174
179#if QT_CONFIG(accessibility)
180 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
181 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
187 qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly));
192 QGuiApplicationPrivate::window_list.removeAll(
this);
193 QGuiApplicationPrivate::popup_list.removeAll(
this);
194 if (!QGuiApplicationPrivate::is_app_closing)
195 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
200 if (QGuiApplicationPrivate::focus_window ==
this)
201 QGuiApplicationPrivate::focus_window =
nullptr;
202 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
203 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
204 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
205 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
210QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
211 : QObjectPrivate(version)
214QWindowPrivate::~QWindowPrivate()
217void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
221 q->QObject::setParent(parent);
224 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
226 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
229 connectToScreen(connectScreen);
233 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
234 qFatal(
"Cannot create window: no screens available");
236 QGuiApplicationPrivate::window_list.prepend(q);
238 requestedFormat = QSurfaceFormat::defaultFormat();
239 devicePixelRatio = connectScreen->devicePixelRatio();
241 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
246 if (
const auto *handle = q->handle()) {
247 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q,
248 QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q),
249 QHighDpi::fromNativePixels(handle->geometry(), q));
250 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
255 updateDevicePixelRatio();
259 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
260 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
265
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315QWindow::Visibility QWindow::visibility()
const
318 return d->visibility;
321void QWindow::setVisibility(Visibility v)
327 case AutomaticVisibility:
348
349
350
351
352
353void QWindowPrivate::setVisible(
bool visible)
357 if (
this->visible != visible) {
358 this->visible = visible;
359 emit q->visibleChanged(visible);
361 }
else if (platformWindow) {
366 if (!platformWindow) {
369 if (parentWindow && !parentWindow->handle())
385 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
387 if (q->type() == Qt::Window) {
388 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
389 QString &firstWindowTitle = app_priv->firstWindowTitle;
390 if (!firstWindowTitle.isEmpty()) {
391 q->setTitle(firstWindowTitle);
392 firstWindowTitle = QString();
394 if (!app_priv->forcedWindowIcon.isNull())
395 q->setIcon(app_priv->forcedWindowIcon);
398 static bool geometryApplied =
false;
399 if (!geometryApplied) {
400 geometryApplied =
true;
401 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
405 QShowEvent showEvent;
406 QGuiApplication::sendEvent(q, &showEvent);
411 QGuiApplicationPrivate::showModalWindow(q);
413 QGuiApplicationPrivate::hideModalWindow(q);
416 }
else if (visible && QGuiApplication::modalWindow()
417#if QT_CONFIG(draganddrop)
418 && !qobject_cast<QShapedPixmapWindow *>(q)
421 QGuiApplicationPrivate::updateBlockedStatus(q);
424 if (q->type() == Qt::Popup) {
426 QGuiApplicationPrivate::activatePopup(q);
428 QGuiApplicationPrivate::closePopup(q);
432 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
437 platformWindow->setVisible(visible);
440 QHideEvent hideEvent;
441 QGuiApplication::sendEvent(q, &hideEvent);
445void QWindowPrivate::updateVisibility()
449 QWindow::Visibility old = visibility;
452 visibility = QWindow::Hidden;
453 else if (windowState & Qt::WindowMinimized)
454 visibility = QWindow::Minimized;
455 else if (windowState & Qt::WindowFullScreen)
456 visibility = QWindow::FullScreen;
457 else if (windowState & Qt::WindowMaximized)
458 visibility = QWindow::Maximized;
460 visibility = QWindow::Windowed;
462 if (visibility != old)
463 emit q->visibilityChanged(visibility);
466void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
473 QObjectList &siblings = q->parent()->d_ptr->children;
475 const qsizetype siblingCount = siblings.size() - 1;
476 if (siblingCount == 0)
479 const qsizetype currentPosition = siblings.indexOf(q);
480 Q_ASSERT(currentPosition >= 0);
482 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
484 if (currentPosition == targetPosition)
487 siblings.move(currentPosition, targetPosition);
490bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
493 const QScreen *oldScreen = q->screen();
494 return oldScreen != newScreen && (platformWindow || !oldScreen)
495 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
498void QWindowPrivate::disconnectFromScreen()
501 topLevelScreen =
nullptr;
504void QWindowPrivate::connectToScreen(QScreen *screen)
506 disconnectFromScreen();
507 topLevelScreen = screen;
510void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
513 emit q->screenChanged(newScreen);
514 for (QObject *child : q->children()) {
515 if (child->isWindowType())
516 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
520void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
524 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
527 if (newScreen != topLevelScreen) {
528 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
529 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
530 if (shouldRecreate && platformWindow)
532 connectToScreen(newScreen);
535 else if (newScreen && shouldRecreate)
537 emitScreenChangedRecursion(newScreen);
543void QWindowPrivate::create(
bool recursive)
550 const bool needsUpdate = updateRequestPending;
552 updateRequestPending =
false;
555 q->parent()->create();
557 if (platformWindow) {
566 if (q->isTopLevel()) {
567 if (QScreen *screen = screenForGeometry(geometry))
568 setTopLevelScreen(screen,
false);
571 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
573 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
574 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
575 : platformIntegration->createPlatformWindow(q);
576 Q_ASSERT(platformWindow);
578 if (!platformWindow) {
579 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
583 platformWindow->initialize();
585 QObjectList childObjects = q->children();
586 for (
int i = 0; i < childObjects.size(); i ++) {
587 QObject *object = childObjects.at(i);
588 if (!object->isWindowType())
591 QWindow *childWindow =
static_cast<QWindow *>(object);
593 childWindow->d_func()->create(recursive);
598 if (childWindow->isVisible())
599 childWindow->setVisible(
true);
601 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
602 childPlatformWindow->setParent(
this->platformWindow);
605 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
606 QGuiApplication::sendEvent(q, &e);
608 updateDevicePixelRatio();
614void QWindowPrivate::clearFocusObject()
621QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
627void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
628 qxp::function_ref<
void()> funcWidthChanged,
629 qxp::function_ref<
void()> funcHeightChanged)
632 Q_ASSERT(oldSizeMember);
633 const QSize adjustedSize =
634 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
635 if (*oldSizeMember == adjustedSize)
637 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
638 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
639 *oldSizeMember = adjustedSize;
641 if (platformWindow && q->isTopLevel())
642 platformWindow->propagateSizeHints();
650 if (minimumSize.width() <= maximumSize.width()
651 || minimumSize.height() <= maximumSize.height()) {
652 const QSize currentSize = q->size();
653 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
654 q->resize(boundedSize);
659
660
661
662
663
664
665
666
667
668
669
670
671void QWindow::setSurfaceType(SurfaceType surfaceType)
674 d->surfaceType = surfaceType;
678
679
680
681
682QWindow::SurfaceType QWindow::surfaceType()
const
685 return d->surfaceType;
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706void QWindow::setVisible(
bool visible)
710 d->setVisible(visible);
713bool QWindow::isVisible()
const
721
722
723
724
725
726
727
728
729
730
731
732
733
734void QWindow::create()
741
742
743
744
745
746
747
748
749
750
751WId QWindow::winId()
const
755 if (!d->platformWindow)
756 const_cast<QWindow *>(
this)->create();
758 if (!d->platformWindow)
761 return d->platformWindow->winId();
765
766
767
768
769
770
771
772
773
774QWindow *QWindow::parent(AncestorMode mode)
const
777 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
781
782
783
784
785
786
787
788
789
790void QWindow::setParent(QWindow *parent)
793 if (d->parentWindow == parent)
796 QScreen *newScreen = parent ? parent->screen() : screen();
797 if (d->windowRecreationRequired(newScreen)) {
798 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << screen() << newScreen <<
')';
802 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
803 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
805 const auto previousParent = d->parentWindow;
806 QObject::setParent(parent);
807 d->parentWindow = parent;
810 d->disconnectFromScreen();
812 d->connectToScreen(newScreen);
817 if (isVisible() && (!parent || parent->handle()))
820 if (d->platformWindow) {
824 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
827 QGuiApplicationPrivate::updateBlockedStatus(
this);
829 if (previousParent) {
830 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
831 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
835 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
836 QCoreApplication::sendEvent(parent, &childAddedEvent);
839 QEvent parentChangedEvent(QEvent::ParentWindowChange);
840 QCoreApplication::sendEvent(
this, &parentChangedEvent);
841#if QT_CONFIG(accessibility)
842 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
843 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
844 QAccessible::updateAccessibility(&qaEvent);
850
851
852bool QWindow::isTopLevel()
const
855 return d->parentWindow ==
nullptr;
859
860
861
862
863
864
865bool QWindow::isModal()
const
868 return d->modality != Qt::NonModal;
872
873
874
875
876
877
878
879
880
882Qt::WindowModality QWindow::modality()
const
888void QWindow::setModality(Qt::WindowModality modality)
891 if (d->modality == modality)
893 d->modality = modality;
894 emit modalityChanged(modality);
898
899
900
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928void QWindow::setFormat(
const QSurfaceFormat &format)
931 d->requestedFormat = format;
935
936
937
938
939
940
941
942
943
944QSurfaceFormat QWindow::requestedFormat()
const
947 return d->requestedFormat;
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967QSurfaceFormat QWindow::format()
const
970 if (d->platformWindow)
971 return d->platformWindow->format();
972 return d->requestedFormat;
976
977
978
979
980
981
982
983
984
985
986
987
988void QWindow::setFlags(Qt::WindowFlags flags)
991 if (d->windowFlags == flags)
994 if (d->platformWindow)
995 d->platformWindow->setWindowFlags(flags);
996 d->windowFlags = flags;
998 emit flagsChanged(
this->flags());
1001Qt::WindowFlags QWindow::flags()
const
1004 Qt::WindowFlags flags = d->windowFlags;
1006 if (d->platformWindow && d->platformWindow->isForeignWindow())
1007 flags |= Qt::ForeignWindow;
1013
1014
1015
1016
1017
1018
1019
1020void QWindow::setFlag(Qt::WindowType flag,
bool on)
1024 setFlags(d->windowFlags | flag);
1026 setFlags(d->windowFlags & ~flag);
1030
1031
1032
1033
1034
1035
1036
1037Qt::WindowType QWindow::type()
const
1039 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053void QWindow::setTitle(
const QString &title)
1056 bool changed =
false;
1057 if (d->windowTitle != title) {
1058 d->windowTitle = title;
1061 if (d->platformWindow)
1062 d->platformWindow->setWindowTitle(title);
1064 emit windowTitleChanged(title);
1067QString QWindow::title()
const
1070 return d->windowTitle;
1074
1075
1076
1077
1078
1079
1080void QWindow::setFilePath(
const QString &filePath)
1083 d->windowFilePath = filePath;
1084 if (d->platformWindow)
1085 d->platformWindow->setWindowFilePath(filePath);
1089
1090
1091
1092
1093QString QWindow::filePath()
const
1096 return d->windowFilePath;
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110void QWindow::setIcon(
const QIcon &icon)
1113 d->windowIcon = icon;
1114 if (d->platformWindow)
1115 d->platformWindow->setWindowIcon(icon);
1116 QEvent e(QEvent::WindowIconChange);
1117 QCoreApplication::sendEvent(
this, &e);
1121
1122
1123
1124
1125QIcon QWindow::icon()
const
1128 if (d->windowIcon.isNull())
1129 return QGuiApplication::windowIcon();
1130 return d->windowIcon;
1134
1135
1136
1137
1138void QWindow::raise()
1142 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1144 if (d->platformWindow)
1145 d->platformWindow->raise();
1149
1150
1151
1152
1153void QWindow::lower()
1157 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1159 if (d->platformWindow)
1160 d->platformWindow->lower();
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181bool QWindow::startSystemResize(Qt::Edges edges)
1184 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1187 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1188 const bool isCorner =
1189 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1190 edges == (Qt::TopEdge | Qt::RightEdge) ||
1191 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1192 edges == (Qt::BottomEdge | Qt::LeftEdge);
1194 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1195 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1199 return d->platformWindow->startSystemResize(edges);
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219bool QWindow::startSystemMove()
1222 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1225 return d->platformWindow->startSystemMove();
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242void QWindow::setOpacity(qreal level)
1245 if (level == d->opacity)
1248 if (d->platformWindow) {
1249 d->platformWindow->setOpacity(level);
1250 emit opacityChanged(level);
1254qreal QWindow::opacity()
const
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270void QWindow::setMask(
const QRegion ®ion)
1273 if (d->platformWindow)
1274 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1279
1280
1281
1282
1283
1284QRegion QWindow::mask()
const
1291
1292
1293
1294
1295void QWindow::requestActivate()
1298 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1299 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1302 if (d->platformWindow)
1303 d->platformWindow->requestActivateWindow();
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317bool QWindow::isExposed()
const
1324
1325
1326
1327
1328
1329
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343bool QWindow::isActive()
const
1346 if (!d->platformWindow)
1349 QWindow *focus = QGuiApplication::focusWindow();
1358 if (QWindow *p = parent(IncludeTransients))
1359 return p->isActive();
1361 return isAncestorOf(focus);
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1386 if (d->contentOrientation == orientation)
1388 if (d->platformWindow)
1389 d->platformWindow->handleContentOrientationChange(orientation);
1390 d->contentOrientation = orientation;
1391 emit contentOrientationChanged(orientation);
1394Qt::ScreenOrientation QWindow::contentOrientation()
const
1397 return d->contentOrientation;
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415qreal QWindow::devicePixelRatio()
const
1418 return d->devicePixelRatio;
1422
1423
1424
1425
1426bool QWindowPrivate::updateDevicePixelRatio()
1430 const qreal newDevicePixelRatio = [
this, q]{
1432 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1437 if (
auto *screen = q->screen())
1438 return screen->devicePixelRatio();
1441 return qGuiApp->devicePixelRatio();
1444 if (newDevicePixelRatio == devicePixelRatio)
1447 devicePixelRatio = newDevicePixelRatio;
1448 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1449 QGuiApplication::sendEvent(q, &dprChangeEvent);
1453Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1455 if (state & Qt::WindowMinimized)
1456 return Qt::WindowMinimized;
1457 else if (state & Qt::WindowFullScreen)
1458 return Qt::WindowFullScreen;
1459 else if (state & Qt::WindowMaximized)
1460 return Qt::WindowMaximized;
1461 return Qt::WindowNoState;
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474void QWindow::setWindowState(Qt::WindowState state)
1476 setWindowStates(state);
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495void QWindow::setWindowStates(Qt::WindowStates state)
1498 if (state & Qt::WindowActive) {
1499 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1500 state &= ~Qt::WindowActive;
1503 if (d->platformWindow)
1504 d->platformWindow->setWindowState(state);
1506 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1507 d->windowState = state;
1508 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1509 if (newEffectiveState != originalEffectiveState)
1510 emit windowStateChanged(newEffectiveState);
1512 d->updateVisibility();
1516
1517
1518
1519
1520Qt::WindowState QWindow::windowState()
const
1523 return QWindowPrivate::effectiveState(d->windowState);
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537Qt::WindowStates QWindow::windowStates()
const
1540 return d->windowState;
1544
1545
1546
1547
1548
1549
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565void QWindow::setTransientParent(QWindow *parent)
1568 if (parent && !parent->isTopLevel()) {
1569 qWarning() << parent <<
"must be a top level window.";
1572 if (parent ==
this) {
1573 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1577 d->transientParent = parent;
1579 QGuiApplicationPrivate::updateBlockedStatus(
this);
1580 emit transientParentChanged(parent);
1583QWindow *QWindow::transientParent()
const
1586 return d->transientParent.data();
1590
1591
1592
1593
1594
1595void QWindowPrivate::setTransientParent(QWindow *parent)
1598 q->setTransientParent(parent);
1599 transientParentPropertySet =
true;
1603
1604
1605
1606
1607
1608
1609
1610
1613
1614
1615
1616bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1618 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1621 if (QWindow *parent = child->parent(mode)) {
1622 if (isAncestorOf(parent, mode))
1624 }
else if (handle() && child->handle()) {
1625 if (handle()->isAncestorOf(child->handle()))
1633
1634
1635
1636
1637QSize QWindow::minimumSize()
const
1640 return d->minimumSize;
1644
1645
1646
1647
1648QSize QWindow::maximumSize()
const
1651 return d->maximumSize;
1655
1656
1657
1658
1659QSize QWindow::baseSize()
const
1666
1667
1668
1669
1670QSize QWindow::sizeIncrement()
const
1673 return d->sizeIncrement;
1677
1678
1679
1680
1681
1682
1683void QWindow::setMinimumSize(
const QSize &size)
1687 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1688 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1692
1693
1694
1695void QWindow::setX(
int arg)
1699 setGeometry(QRect(arg, y(), width(), height()));
1701 d->positionAutomatic =
false;
1705
1706
1707
1708void QWindow::setY(
int arg)
1712 setGeometry(QRect(x(), arg, width(), height()));
1714 d->positionAutomatic =
false;
1718
1719
1720
1721void QWindow::setWidth(
int w)
1723 resize(w, height());
1727
1728
1729
1730void QWindow::setHeight(
int h)
1736
1737
1738
1739void QWindow::setMinimumWidth(
int w)
1741 setMinimumSize(QSize(w, minimumHeight()));
1745
1746
1747
1748void QWindow::setMinimumHeight(
int h)
1750 setMinimumSize(QSize(minimumWidth(), h));
1754
1755
1756
1757
1758
1759
1760void QWindow::setMaximumSize(
const QSize &size)
1764 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1765 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1769
1770
1771
1772void QWindow::setMaximumWidth(
int w)
1774 setMaximumSize(QSize(w, maximumHeight()));
1778
1779
1780
1781void QWindow::setMaximumHeight(
int h)
1783 setMaximumSize(QSize(maximumWidth(), h));
1787
1788
1789
1790
1791
1792
1793
1794void QWindow::setBaseSize(
const QSize &size)
1797 if (d->baseSize == size)
1800 if (d->platformWindow && isTopLevel())
1801 d->platformWindow->propagateSizeHints();
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818void QWindow::setSizeIncrement(
const QSize &size)
1821 if (d->sizeIncrement == size)
1823 d->sizeIncrement = size;
1824 if (d->platformWindow && isTopLevel())
1825 d->platformWindow->propagateSizeHints();
1829
1830
1831
1832
1833
1834
1835
1836void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1838 setGeometry(QRect(posx, posy, w, h));
1842
1843
1844
1845
1846
1847
1848void QWindow::setGeometry(
const QRect &rect)
1851 d->positionAutomatic =
false;
1852 const QRect oldRect = geometry();
1853 if (rect == oldRect)
1856 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1857 if (d->platformWindow) {
1865 QScreen *newScreen = d->screenForGeometry(rect);
1866 if (newScreen && isTopLevel())
1867 d->setTopLevelScreen(newScreen,
true);
1868 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1872 if (rect.x() != oldRect.x())
1873 emit xChanged(rect.x());
1874 if (rect.y() != oldRect.y())
1875 emit yChanged(rect.y());
1876 if (rect.width() != oldRect.width())
1877 emit widthChanged(rect.width());
1878 if (rect.height() != oldRect.height())
1879 emit heightChanged(rect.height());
1884
1885
1886
1887
1888
1889QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1892 QScreen *currentScreen = q->screen();
1893 QScreen *fallback = currentScreen;
1894 QPoint center = newGeometry.center();
1895 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1896 const auto screens = currentScreen->virtualSiblings();
1897 for (QScreen* screen : screens) {
1898 if (screen->geometry().contains(center))
1900 if (screen->geometry().intersects(newGeometry))
1909
1910
1911
1912
1913
1914
1915QRect QWindow::geometry()
const
1918 if (d->platformWindow) {
1919 const auto nativeGeometry = d->platformWindow->geometry();
1920 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1926
1927
1928
1929
1930QMargins QWindow::frameMargins()
const
1933 if (d->platformWindow)
1934 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1939
1940
1941
1942
1943
1944
1945QRect QWindow::frameGeometry()
const
1948 if (d->platformWindow) {
1949 QMargins m = frameMargins();
1950 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1956
1957
1958
1959
1960
1961
1962QPoint QWindow::framePosition()
const
1965 if (d->platformWindow) {
1966 QMargins margins = frameMargins();
1967 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1969 return d->geometry.topLeft();
1973
1974
1975
1976
1977
1978
1979void QWindow::setFramePosition(
const QPoint &point)
1982 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1983 d->positionAutomatic =
false;
1984 if (d->platformWindow) {
1985 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
1987 d->geometry.moveTopLeft(point);
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014QMargins QWindow::safeAreaMargins()
const
2017 if (d->platformWindow)
2018 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2023
2024
2025
2026
2027
2028
2029
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045void QWindow::setPosition(
const QPoint &pt)
2047 setGeometry(QRect(pt, size()));
2051
2052
2053
2054
2055
2056
2057void QWindow::setPosition(
int posx,
int posy)
2059 setPosition(QPoint(posx, posy));
2063
2064
2065
2066
2067
2068
2069
2070
2071
2074
2075
2076
2077
2078
2081
2082
2083
2084
2085
2086
2087
2088void QWindow::resize(
int w,
int h)
2090 resize(QSize(w, h));
2094
2095
2096
2097
2098void QWindow::resize(
const QSize &newSize)
2102 const QSize oldSize = size();
2103 if (newSize == oldSize)
2106 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2107 if (d->platformWindow) {
2108 d->platformWindow->setGeometry(
2109 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2111 d->geometry.setSize(newSize);
2112 if (newSize.width() != oldSize.width())
2113 emit widthChanged(newSize.width());
2114 if (newSize.height() != oldSize.height())
2115 emit heightChanged(newSize.height());
2120
2121
2122
2123
2124void QWindow::destroy()
2127 if (!d->platformWindow)
2130 if (d->platformWindow->isForeignWindow())
2136void QWindowPrivate::destroy()
2138 if (!platformWindow)
2142 QObjectList childrenWindows = q->children();
2143 for (
int i = 0; i < childrenWindows.size(); i++) {
2144 QObject *object = childrenWindows.at(i);
2145 if (object->isWindowType()) {
2146 QWindow *w =
static_cast<QWindow*>(object);
2147 qt_window_private(w)->destroy();
2151 bool wasVisible = q->isVisible();
2152 visibilityOnDestroy = wasVisible && platformWindow;
2154 q->setVisible(
false);
2165 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2166 QGuiApplication::sendEvent(q, &e);
2171 delete std::exchange(platformWindow,
nullptr);
2173 if (QGuiApplicationPrivate::focus_window == q)
2174 QGuiApplicationPrivate::focus_window = q->parent();
2175 if (QGuiApplicationPrivate::currentMouseWindow == q)
2176 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2177 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2178 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2180 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2181 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2182 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2184 resizeEventPending =
true;
2185 receivedExpose =
false;
2191 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2195
2196
2197
2198
2199QPlatformWindow *QWindow::handle()
const
2202 return d->platformWindow;
2206
2207
2208
2209
2210QPlatformSurface *QWindow::surfaceHandle()
const
2213 return d->platformWindow;
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226bool QWindow::setKeyboardGrabEnabled(
bool grab)
2229 if (d->platformWindow)
2230 return d->platformWindow->setKeyboardGrabEnabled(grab);
2235
2236
2237
2238
2239
2240
2241
2242
2243bool QWindow::setMouseGrabEnabled(
bool grab)
2246 if (d->platformWindow)
2247 return d->platformWindow->setMouseGrabEnabled(grab);
2252
2253
2254
2255
2256
2257
2258QScreen *QWindow::screen()
const
2261 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277void QWindow::setScreen(QScreen *newScreen)
2281 newScreen = QGuiApplication::primaryScreen();
2282 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2286
2287
2288
2289
2290
2291
2294
2295
2296
2297
2298QAccessibleInterface *QWindow::accessibleRoot()
const
2304
2305
2306
2307
2308
2309
2310
2313
2314
2315
2316QObject *QWindow::focusObject()
const
2318 return const_cast<QWindow *>(
this);
2322
2323
2324
2325
2326
2327
2328
2329
2335 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2336 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2337 if (defaultState == Qt::WindowFullScreen)
2339 else if (defaultState == Qt::WindowMaximized)
2347
2348
2349
2350
2351
2352
2359
2360
2361
2362
2363
2364
2365
2366void QWindow::showMinimized()
2368 setWindowStates(Qt::WindowMinimized);
2373
2374
2375
2376
2377
2378
2379
2380void QWindow::showMaximized()
2382 setWindowStates(Qt::WindowMaximized);
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397void QWindow::showFullScreen()
2399 setWindowStates(Qt::WindowFullScreen);
2401#if !defined Q_OS_QNX
2408
2409
2410
2411
2412
2413
2414
2415void QWindow::showNormal()
2417 setWindowStates(Qt::WindowNoState);
2422
2423
2424
2425
2426
2427
2428
2429
2430bool QWindow::close()
2440 if (!d->platformWindow) {
2443 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2444 QGuiApplicationPrivate::closePopup(
this);
2450 QPointer guard(
this);
2452 bool success = d->platformWindow->close();
2459bool QWindowPrivate::participatesInLastWindowClosed()
const
2463 if (!q->isTopLevel())
2469 if (q->type() == Qt::ToolTip)
2474 if (q->transientParent())
2480bool QWindowPrivate::treatAsVisible()
const
2483 return q->isVisible();
2487
2488
2489
2490const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2493 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2494 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2495 QWindow *ret =
nullptr;
2496 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2497 if (q == popupWindow)
2499 if (event->isPointerEvent()) {
2501 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2502 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2503 QEventPoint &eventPoint = pointerEvent->point(i);
2504 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2505 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2506 QMutableEventPoint::setPosition(eventPoint, mapped);
2507 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2511
2512
2513 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2514 event->setAccepted(pointerEvent->isAccepted());
2515 if (pointerEvent->isAccepted())
2518 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2519 <<
"handled?" << (ret !=
nullptr)
2520 <<
"accepted?" << event->isAccepted();
2522 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2523 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2525 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2526 <<
"handled?" << (ret !=
nullptr)
2527 <<
"accepted?" << event->isAccepted();
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552void QWindow::exposeEvent(QExposeEvent *ev)
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571void QWindow::paintEvent(QPaintEvent *ev)
2577
2578
2579void QWindow::moveEvent(QMoveEvent *ev)
2585
2586
2587
2588
2589
2590
2591void QWindow::resizeEvent(QResizeEvent *ev)
2597
2598
2599
2600
2601
2602
2603
2604void QWindow::showEvent(QShowEvent *ev)
2610
2611
2612
2613
2614
2615void QWindow::hideEvent(QHideEvent *ev)
2621
2622
2623
2624
2625
2626
2627
2628void QWindow::closeEvent(QCloseEvent *ev)
2634
2635
2636
2637
2638
2639
2640bool QWindow::event(QEvent *ev)
2643 switch (ev->type()) {
2644 case QEvent::MouseMove:
2645 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2648 case QEvent::MouseButtonPress: {
2649 auto *me =
static_cast<QMouseEvent*>(ev);
2650 mousePressEvent(me);
2651 if (!ev->isAccepted())
2652 d->maybeSynthesizeContextMenuEvent(me);
2656 case QEvent::MouseButtonRelease: {
2657 auto *me =
static_cast<QMouseEvent*>(ev);
2658 mouseReleaseEvent(me);
2659 if (!ev->isAccepted())
2660 d->maybeSynthesizeContextMenuEvent(me);
2664 case QEvent::MouseButtonDblClick:
2665 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2668 case QEvent::TouchBegin:
2669 case QEvent::TouchUpdate:
2670 case QEvent::TouchEnd:
2671 case QEvent::TouchCancel:
2672 touchEvent(
static_cast<QTouchEvent *>(ev));
2676 moveEvent(
static_cast<QMoveEvent*>(ev));
2679 case QEvent::Resize:
2680 resizeEvent(
static_cast<QResizeEvent*>(ev));
2683 case QEvent::KeyPress:
2684 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2687 case QEvent::KeyRelease:
2688 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2691 case QEvent::FocusIn: {
2692 focusInEvent(
static_cast<QFocusEvent *>(ev));
2693#if QT_CONFIG(accessibility)
2694 QAccessible::State state;
2695 state.active =
true;
2696 QAccessibleStateChangeEvent event(
this, state);
2697 QAccessible::updateAccessibility(&event);
2701 case QEvent::FocusOut: {
2702 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2703#if QT_CONFIG(accessibility)
2704 QAccessible::State state;
2705 state.active =
true;
2706 QAccessibleStateChangeEvent event(
this, state);
2707 QAccessible::updateAccessibility(&event);
2711#if QT_CONFIG(wheelevent)
2713 wheelEvent(
static_cast<QWheelEvent*>(ev));
2717 case QEvent::Close: {
2719 const bool wasVisible = d->treatAsVisible();
2720 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2723 QPointer<QWindow> deletionGuard(
this);
2724 closeEvent(
static_cast<QCloseEvent*>(ev));
2726 if (ev->isAccepted()) {
2729 if (wasVisible && participatesInLastWindowClosed)
2730 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2736 case QEvent::Expose:
2737 exposeEvent(
static_cast<QExposeEvent *>(ev));
2741 paintEvent(
static_cast<QPaintEvent *>(ev));
2745 showEvent(
static_cast<QShowEvent *>(ev));
2749 hideEvent(
static_cast<QHideEvent *>(ev));
2752 case QEvent::ApplicationWindowIconChange:
2756#if QT_CONFIG(tabletevent)
2757 case QEvent::TabletPress:
2758 case QEvent::TabletMove:
2759 case QEvent::TabletRelease:
2760 tabletEvent(
static_cast<QTabletEvent *>(ev));
2764 case QEvent::PlatformSurface: {
2765 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2767 QOpenGLContext *context = QOpenGLContext::currentContext();
2768 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2769 context->doneCurrent();
2776 return QObject::event(ev);
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2822#ifndef QT_NO_CONTEXTMENU
2823 if (event->button() == Qt::RightButton
2824 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2825 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2826 event->globalPosition().toPoint(), event->modifiers());
2827 qCDebug(lcPopup) <<
"synthesized after"
2828 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2829 << event->type() <<
":" << &e;
2830 QCoreApplication::forwardEvent(q_func(), &e, event);
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
2864void QWindow::requestUpdate()
2866 Q_ASSERT_X(QThread::isMainThread(),
2867 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2870 if (d->updateRequestPending || !d->platformWindow)
2872 d->updateRequestPending =
true;
2873 d->platformWindow->requestUpdate();
2877
2878
2879
2880
2881void QWindow::keyPressEvent(QKeyEvent *ev)
2887
2888
2889
2890
2891void QWindow::keyReleaseEvent(QKeyEvent *ev)
2897
2898
2899
2900
2901
2902
2903void QWindow::focusInEvent(QFocusEvent *ev)
2909
2910
2911
2912
2913
2914
2915void QWindow::focusOutEvent(QFocusEvent *ev)
2921
2922
2923
2924
2925void QWindow::mousePressEvent(QMouseEvent *ev)
2931
2932
2933
2934
2935void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2941
2942
2943
2944
2945void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2951
2952
2953void QWindow::mouseMoveEvent(QMouseEvent *ev)
2958#if QT_CONFIG(wheelevent)
2960
2961
2962void QWindow::wheelEvent(QWheelEvent *ev)
2969
2970
2971void QWindow::touchEvent(QTouchEvent *ev)
2976#if QT_CONFIG(tabletevent)
2978
2979
2980
2981
2982
2983void QWindow::tabletEvent(QTabletEvent *ev)
2990
2991
2992
2993
2994
2995
2996
2998bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3000 Q_UNUSED(eventType);
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3020 if (d->platformWindow
3021 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3022 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3025 if (!QHighDpiScaling::isActive())
3026 return pos + d->globalPosition();
3034 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3038 QPointF nativeWindowGlobalPos = d->platformWindow
3039 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3040 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3041 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3042 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3043 return deviceIndependentGlobalPos;
3047
3048
3049QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3051 return mapToGlobal(QPointF(pos)).toPoint();
3055
3056
3057
3058
3059
3060
3061
3062
3063QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3067 if (d->platformWindow
3068 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3069 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3072 if (!QHighDpiScaling::isActive())
3073 return pos - d->globalPosition();
3077 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3081 QPointF nativeWindowGlobalPos = d->platformWindow
3082 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3083 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3084 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3085 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3086 return deviceIndependentLocalPos;
3090
3091
3092QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3094 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3097QPoint QWindowPrivate::globalPosition()
const
3100 QPoint offset = q->position();
3101 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3102 QPlatformWindow *pw = p->handle();
3103 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3105 offset += p->mapToGlobal(QPoint(0, 0));
3108 offset += p->position();
3116 return window->d_func();
3119QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3123 QWindow *window =
const_cast<QWindow *>(q);
3126 QWindow *parent = window->parent(mode);
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157QWindow *QWindow::fromWinId(WId id)
3159 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3160 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3164 QWindow *window =
new QWindow;
3168 window->setProperty(kForeignWindowId, id);
3171 if (!window->handle()) {
3180
3181
3182
3183
3184
3185
3186
3187
3188
3190void QWindow::alert(
int msec)
3193 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3195 d->platformWindow->setAlertState(
true);
3196 if (d->platformWindow->isAlertState() && msec)
3197 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3200void QWindowPrivate::_q_clearAlert()
3202 if (platformWindow && platformWindow->isAlertState())
3203 platformWindow->setAlertState(
false);
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227void QWindow::setCursor(
const QCursor &cursor)
3230 d->setCursor(&cursor);
3234
3235
3236void QWindow::unsetCursor()
3239 d->setCursor(
nullptr);
3243
3244
3245
3246
3247QCursor QWindow::cursor()
const
3253void QWindowPrivate::setCursor(
const QCursor *newCursor)
3258 const Qt::CursorShape newShape = newCursor->shape();
3259 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3261 cursor = *newCursor;
3266 cursor = QCursor(Qt::ArrowCursor);
3270 if (applyCursor()) {
3271 QEvent event(QEvent::CursorChange);
3272 QGuiApplication::sendEvent(q, &event);
3277bool QWindowPrivate::applyCursor()
3280 if (QScreen *screen = q->screen()) {
3281 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3282 if (!platformWindow)
3284 QCursor *c = QGuiApplication::overrideCursor();
3285 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3287 if (!c && hasCursor)
3289 platformCursor->changeCursor(c, q);
3297void *QWindow::resolveInterface(
const char *name,
int revision)
const
3299 using namespace QNativeInterface::Private;
3301 auto *platformWindow = handle();
3302 Q_UNUSED(platformWindow);
3306#if defined(Q_OS_WIN)
3307 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3311 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3314#if defined(Q_OS_MACOS)
3315 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3318#if QT_CONFIG(wayland)
3319 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3322#if defined(Q_OS_WASM)
3323 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3329#ifndef QT_NO_DEBUG_STREAM
3330QDebug operator<<(QDebug debug,
const QWindow *window)
3332 QDebugStateSaver saver(debug);
3335 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3336 if (!window->objectName().isEmpty())
3337 debug <<
", name=" << window->objectName();
3338 if (debug.verbosity() > 2) {
3339 const QRect geometry = window->geometry();
3340 if (window->isVisible())
3341 debug <<
", visible";
3342 if (window->isExposed())
3343 debug <<
", exposed";
3344 debug <<
", state=" << window->windowState()
3345 <<
", type=" << window->type() <<
", flags=" << window->flags()
3346 <<
", surface type=" << window->surfaceType();
3347 if (window->isTopLevel())
3348 debug <<
", toplevel";
3349 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3350 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3351 const QMargins margins = window->frameMargins();
3352 if (!margins.isNull())
3353 debug <<
", margins=" << margins;
3354 const QMargins safeAreaMargins = window->safeAreaMargins();
3355 if (!safeAreaMargins.isNull())
3356 debug <<
", safeAreaMargins=" << safeAreaMargins;
3357 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3358 if (
const QPlatformWindow *platformWindow = window->handle())
3359 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3360 if (
const QScreen *screen = window->screen())
3361 debug <<
", on " << screen->name();
3365 debug <<
"QWindow(0x0)";
3371#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3374
3375
3376
3377
3378void QWindow::setVulkanInstance(QVulkanInstance *instance)
3381 d->vulkanInstance = instance;
3385
3386
3387QVulkanInstance *QWindow::vulkanInstance()
const
3390 return d->vulkanInstance;
3397#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId