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();
588 positionAutomatic =
false;
589 resizeAutomatic =
false;
591 QObjectList childObjects = q->children();
592 for (
int i = 0; i < childObjects.size(); i ++) {
593 QObject *object = childObjects.at(i);
594 if (!object->isWindowType())
597 QWindow *childWindow =
static_cast<QWindow *>(object);
599 childWindow->d_func()->create(recursive);
604 if (childWindow->isVisible())
605 childWindow->setVisible(
true);
607 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
608 childPlatformWindow->setParent(
this->platformWindow);
611 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
612 QGuiApplication::sendEvent(q, &e);
614 updateDevicePixelRatio();
620void QWindowPrivate::clearFocusObject()
627QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
633void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
634 qxp::function_ref<
void()> funcWidthChanged,
635 qxp::function_ref<
void()> funcHeightChanged)
638 Q_ASSERT(oldSizeMember);
639 const QSize adjustedSize =
640 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
641 if (*oldSizeMember == adjustedSize)
643 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
644 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
645 *oldSizeMember = adjustedSize;
647 if (platformWindow && q->isTopLevel())
648 platformWindow->propagateSizeHints();
656 if (minimumSize.width() <= maximumSize.width()
657 || minimumSize.height() <= maximumSize.height()) {
658 const QSize currentSize = q->size();
659 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
660 q->resize(boundedSize);
665
666
667
668
669
670
671
672
673
674
675
676
677void QWindow::setSurfaceType(SurfaceType surfaceType)
680 d->surfaceType = surfaceType;
684
685
686
687
688QWindow::SurfaceType QWindow::surfaceType()
const
691 return d->surfaceType;
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712void QWindow::setVisible(
bool visible)
716 d->setVisible(visible);
719bool QWindow::isVisible()
const
727
728
729
730
731
732
733
734
735
736
737
738
739
740void QWindow::create()
747
748
749
750
751
752
753
754
755
756
757WId QWindow::winId()
const
761 if (!d->platformWindow)
762 const_cast<QWindow *>(
this)->create();
764 if (!d->platformWindow)
767 return d->platformWindow->winId();
771
772
773
774
775
776
777
778
779
780QWindow *QWindow::parent(AncestorMode mode)
const
783 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
787
788
789
790
791
792
793
794
795
796void QWindow::setParent(QWindow *parent)
799 if (d->parentWindow == parent)
802 QScreen *newScreen = parent ? parent->screen() : screen();
803 if (d->windowRecreationRequired(newScreen)) {
804 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << screen() << newScreen <<
')';
808 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
809 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
811 const auto previousParent = d->parentWindow;
812 QObject::setParent(parent);
813 d->parentWindow = parent;
816 d->disconnectFromScreen();
818 d->connectToScreen(newScreen);
823 if (isVisible() && (!parent || parent->handle()))
826 if (d->platformWindow) {
830 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
833 QGuiApplicationPrivate::updateBlockedStatus(
this);
835 if (previousParent) {
836 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
837 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
841 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
842 QCoreApplication::sendEvent(parent, &childAddedEvent);
845 QEvent parentChangedEvent(QEvent::ParentWindowChange);
846 QCoreApplication::sendEvent(
this, &parentChangedEvent);
847#if QT_CONFIG(accessibility)
848 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
849 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
850 QAccessible::updateAccessibility(&qaEvent);
856
857
858bool QWindow::isTopLevel()
const
861 return d->parentWindow ==
nullptr;
865
866
867
868
869
870
871bool QWindow::isModal()
const
874 return d->modality != Qt::NonModal;
878
879
880
881
882
883
884
885
886
888Qt::WindowModality QWindow::modality()
const
894void QWindow::setModality(Qt::WindowModality modality)
897 if (d->modality == modality)
899 d->modality = modality;
900 emit modalityChanged(modality);
904
905
906
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934void QWindow::setFormat(
const QSurfaceFormat &format)
937 d->requestedFormat = format;
941
942
943
944
945
946
947
948
949
950QSurfaceFormat QWindow::requestedFormat()
const
953 return d->requestedFormat;
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973QSurfaceFormat QWindow::format()
const
976 if (d->platformWindow)
977 return d->platformWindow->format();
978 return d->requestedFormat;
982
983
984
985
986
987
988
989
990
991
992
993
994void QWindow::setFlags(Qt::WindowFlags flags)
997 if (d->windowFlags == flags)
1000 if (d->platformWindow)
1001 d->platformWindow->setWindowFlags(flags);
1002 d->windowFlags = flags;
1004 emit flagsChanged(
this->flags());
1007Qt::WindowFlags QWindow::flags()
const
1010 Qt::WindowFlags flags = d->windowFlags;
1012 if (d->platformWindow && d->platformWindow->isForeignWindow())
1013 flags |= Qt::ForeignWindow;
1019
1020
1021
1022
1023
1024
1025
1026void QWindow::setFlag(Qt::WindowType flag,
bool on)
1030 setFlags(d->windowFlags | flag);
1032 setFlags(d->windowFlags & ~flag);
1036
1037
1038
1039
1040
1041
1042
1043Qt::WindowType QWindow::type()
const
1045 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059void QWindow::setTitle(
const QString &title)
1062 bool changed =
false;
1063 if (d->windowTitle != title) {
1064 d->windowTitle = title;
1067 if (d->platformWindow)
1068 d->platformWindow->setWindowTitle(title);
1070 emit windowTitleChanged(title);
1073QString QWindow::title()
const
1076 return d->windowTitle;
1080
1081
1082
1083
1084
1085
1086void QWindow::setFilePath(
const QString &filePath)
1089 d->windowFilePath = filePath;
1090 if (d->platformWindow)
1091 d->platformWindow->setWindowFilePath(filePath);
1095
1096
1097
1098
1099QString QWindow::filePath()
const
1102 return d->windowFilePath;
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116void QWindow::setIcon(
const QIcon &icon)
1119 d->windowIcon = icon;
1120 if (d->platformWindow)
1121 d->platformWindow->setWindowIcon(icon);
1122 QEvent e(QEvent::WindowIconChange);
1123 QCoreApplication::sendEvent(
this, &e);
1127
1128
1129
1130
1131QIcon QWindow::icon()
const
1134 if (d->windowIcon.isNull())
1135 return QGuiApplication::windowIcon();
1136 return d->windowIcon;
1140
1141
1142
1143
1144void QWindow::raise()
1148 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1150 if (d->platformWindow)
1151 d->platformWindow->raise();
1155
1156
1157
1158
1159void QWindow::lower()
1163 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1165 if (d->platformWindow)
1166 d->platformWindow->lower();
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187bool QWindow::startSystemResize(Qt::Edges edges)
1190 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1193 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1194 const bool isCorner =
1195 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1196 edges == (Qt::TopEdge | Qt::RightEdge) ||
1197 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1198 edges == (Qt::BottomEdge | Qt::LeftEdge);
1200 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1201 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1205 return d->platformWindow->startSystemResize(edges);
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225bool QWindow::startSystemMove()
1228 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1231 return d->platformWindow->startSystemMove();
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248void QWindow::setOpacity(qreal level)
1251 if (level == d->opacity)
1254 if (d->platformWindow) {
1255 d->platformWindow->setOpacity(level);
1256 emit opacityChanged(level);
1260qreal QWindow::opacity()
const
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276void QWindow::setMask(
const QRegion ®ion)
1279 if (d->platformWindow)
1280 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1285
1286
1287
1288
1289
1290QRegion QWindow::mask()
const
1297
1298
1299
1300
1301void QWindow::requestActivate()
1304 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1305 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1308 if (d->platformWindow)
1309 d->platformWindow->requestActivateWindow();
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323bool QWindow::isExposed()
const
1330
1331
1332
1333
1334
1335
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349bool QWindow::isActive()
const
1352 if (!d->platformWindow)
1355 QWindow *focus = QGuiApplication::focusWindow();
1364 if (QWindow *p = parent(IncludeTransients))
1365 return p->isActive();
1367 return isAncestorOf(focus);
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1392 if (d->contentOrientation == orientation)
1394 if (d->platformWindow)
1395 d->platformWindow->handleContentOrientationChange(orientation);
1396 d->contentOrientation = orientation;
1397 emit contentOrientationChanged(orientation);
1400Qt::ScreenOrientation QWindow::contentOrientation()
const
1403 return d->contentOrientation;
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421qreal QWindow::devicePixelRatio()
const
1424 return d->devicePixelRatio;
1428
1429
1430
1431
1432bool QWindowPrivate::updateDevicePixelRatio()
1436 const qreal newDevicePixelRatio = [
this, q]{
1438 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1443 if (
auto *screen = q->screen())
1444 return screen->devicePixelRatio();
1447 return qGuiApp->devicePixelRatio();
1450 if (newDevicePixelRatio == devicePixelRatio)
1453 devicePixelRatio = newDevicePixelRatio;
1454 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1455 QGuiApplication::sendEvent(q, &dprChangeEvent);
1459Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1461 if (state & Qt::WindowMinimized)
1462 return Qt::WindowMinimized;
1463 else if (state & Qt::WindowFullScreen)
1464 return Qt::WindowFullScreen;
1465 else if (state & Qt::WindowMaximized)
1466 return Qt::WindowMaximized;
1467 return Qt::WindowNoState;
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480void QWindow::setWindowState(Qt::WindowState state)
1482 setWindowStates(state);
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501void QWindow::setWindowStates(Qt::WindowStates state)
1504 if (state & Qt::WindowActive) {
1505 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1506 state &= ~Qt::WindowActive;
1509 if (d->platformWindow)
1510 d->platformWindow->setWindowState(state);
1512 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1513 d->windowState = state;
1514 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1515 if (newEffectiveState != originalEffectiveState)
1516 emit windowStateChanged(newEffectiveState);
1518 d->updateVisibility();
1522
1523
1524
1525
1526Qt::WindowState QWindow::windowState()
const
1529 return QWindowPrivate::effectiveState(d->windowState);
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543Qt::WindowStates QWindow::windowStates()
const
1546 return d->windowState;
1550
1551
1552
1553
1554
1555
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571void QWindow::setTransientParent(QWindow *parent)
1574 if (parent && !parent->isTopLevel()) {
1575 qWarning() << parent <<
"must be a top level window.";
1578 if (parent ==
this) {
1579 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1583 d->transientParent = parent;
1585 QGuiApplicationPrivate::updateBlockedStatus(
this);
1586 emit transientParentChanged(parent);
1589QWindow *QWindow::transientParent()
const
1592 return d->transientParent.data();
1596
1597
1598
1599
1600
1601void QWindowPrivate::setTransientParent(QWindow *parent)
1604 q->setTransientParent(parent);
1605 transientParentPropertySet =
true;
1609
1610
1611
1612
1613
1614
1615
1616
1619
1620
1621
1622bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1624 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1627 if (QWindow *parent = child->parent(mode)) {
1628 if (isAncestorOf(parent, mode))
1630 }
else if (handle() && child->handle()) {
1631 if (handle()->isAncestorOf(child->handle()))
1639
1640
1641
1642
1643QSize QWindow::minimumSize()
const
1646 return d->minimumSize;
1650
1651
1652
1653
1654QSize QWindow::maximumSize()
const
1657 return d->maximumSize;
1661
1662
1663
1664
1665QSize QWindow::baseSize()
const
1672
1673
1674
1675
1676QSize QWindow::sizeIncrement()
const
1679 return d->sizeIncrement;
1683
1684
1685
1686
1687
1688
1689void QWindow::setMinimumSize(
const QSize &size)
1693 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1694 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1698
1699
1700
1701void QWindow::setX(
int arg)
1705 setGeometry(QRect(arg, y(), width(), height()));
1707 d->positionAutomatic =
false;
1711
1712
1713
1714void QWindow::setY(
int arg)
1718 setGeometry(QRect(x(), arg, width(), height()));
1720 d->positionAutomatic =
false;
1724
1725
1726
1727void QWindow::setWidth(
int w)
1729 resize(w, height());
1733
1734
1735
1736void QWindow::setHeight(
int h)
1742
1743
1744
1745void QWindow::setMinimumWidth(
int w)
1747 setMinimumSize(QSize(w, minimumHeight()));
1751
1752
1753
1754void QWindow::setMinimumHeight(
int h)
1756 setMinimumSize(QSize(minimumWidth(), h));
1760
1761
1762
1763
1764
1765
1766void QWindow::setMaximumSize(
const QSize &size)
1770 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1771 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1775
1776
1777
1778void QWindow::setMaximumWidth(
int w)
1780 setMaximumSize(QSize(w, maximumHeight()));
1784
1785
1786
1787void QWindow::setMaximumHeight(
int h)
1789 setMaximumSize(QSize(maximumWidth(), h));
1793
1794
1795
1796
1797
1798
1799
1800void QWindow::setBaseSize(
const QSize &size)
1803 if (d->baseSize == size)
1806 if (d->platformWindow && isTopLevel())
1807 d->platformWindow->propagateSizeHints();
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824void QWindow::setSizeIncrement(
const QSize &size)
1827 if (d->sizeIncrement == size)
1829 d->sizeIncrement = size;
1830 if (d->platformWindow && isTopLevel())
1831 d->platformWindow->propagateSizeHints();
1835
1836
1837
1838
1839
1840
1841
1842void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1844 setGeometry(QRect(posx, posy, w, h));
1848
1849
1850
1851
1852
1853
1854void QWindow::setGeometry(
const QRect &rect)
1857 d->positionAutomatic =
false;
1858 const QRect oldRect = geometry();
1859 if (rect == oldRect)
1862 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1863 if (d->platformWindow) {
1871 QScreen *newScreen = d->screenForGeometry(rect);
1872 if (newScreen && isTopLevel())
1873 d->setTopLevelScreen(newScreen,
true);
1874 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1878 if (rect.x() != oldRect.x())
1879 emit xChanged(rect.x());
1880 if (rect.y() != oldRect.y())
1881 emit yChanged(rect.y());
1882 if (rect.width() != oldRect.width())
1883 emit widthChanged(rect.width());
1884 if (rect.height() != oldRect.height())
1885 emit heightChanged(rect.height());
1890
1891
1892
1893
1894
1895QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1898 QScreen *currentScreen = q->screen();
1899 QScreen *fallback = currentScreen;
1900 QPoint center = newGeometry.center();
1901 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1902 const auto screens = currentScreen->virtualSiblings();
1903 for (QScreen* screen : screens) {
1904 if (screen->geometry().contains(center))
1906 if (screen->geometry().intersects(newGeometry))
1915
1916
1917
1918
1919
1920
1921QRect QWindow::geometry()
const
1924 if (d->platformWindow) {
1925 const auto nativeGeometry = d->platformWindow->geometry();
1926 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1932
1933
1934
1935
1936QMargins QWindow::frameMargins()
const
1939 if (d->platformWindow)
1940 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1945
1946
1947
1948
1949
1950
1951QRect QWindow::frameGeometry()
const
1954 if (d->platformWindow) {
1955 QMargins m = frameMargins();
1956 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1962
1963
1964
1965
1966
1967
1968QPoint QWindow::framePosition()
const
1971 if (d->platformWindow) {
1972 QMargins margins = frameMargins();
1973 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1975 return d->geometry.topLeft();
1979
1980
1981
1982
1983
1984
1985void QWindow::setFramePosition(
const QPoint &point)
1988 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1989 d->positionAutomatic =
false;
1990 if (d->platformWindow) {
1991 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
1993 d->geometry.moveTopLeft(point);
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020QMargins QWindow::safeAreaMargins()
const
2023 if (d->platformWindow)
2024 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2029
2030
2031
2032
2033
2034
2035
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051void QWindow::setPosition(
const QPoint &pt)
2053 setGeometry(QRect(pt, size()));
2057
2058
2059
2060
2061
2062
2063void QWindow::setPosition(
int posx,
int posy)
2065 setPosition(QPoint(posx, posy));
2069
2070
2071
2072
2073
2074
2075
2076
2077
2080
2081
2082
2083
2084
2087
2088
2089
2090
2091
2092
2093
2094void QWindow::resize(
int w,
int h)
2096 resize(QSize(w, h));
2100
2101
2102
2103
2104void QWindow::resize(
const QSize &newSize)
2108 const QSize oldSize = size();
2109 if (newSize == oldSize)
2112 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2113 if (d->platformWindow) {
2114 d->platformWindow->setGeometry(
2115 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2117 d->geometry.setSize(newSize);
2118 if (newSize.width() != oldSize.width())
2119 emit widthChanged(newSize.width());
2120 if (newSize.height() != oldSize.height())
2121 emit heightChanged(newSize.height());
2126
2127
2128
2129
2130void QWindow::destroy()
2133 if (!d->platformWindow)
2136 if (d->platformWindow->isForeignWindow())
2142void QWindowPrivate::destroy()
2144 if (!platformWindow)
2148 QObjectList childrenWindows = q->children();
2149 for (
int i = 0; i < childrenWindows.size(); i++) {
2150 QObject *object = childrenWindows.at(i);
2151 if (object->isWindowType()) {
2152 QWindow *w =
static_cast<QWindow*>(object);
2153 qt_window_private(w)->destroy();
2157 bool wasVisible = q->isVisible();
2158 visibilityOnDestroy = wasVisible && platformWindow;
2160 q->setVisible(
false);
2171 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2172 QGuiApplication::sendEvent(q, &e);
2177 delete std::exchange(platformWindow,
nullptr);
2179 if (QGuiApplicationPrivate::focus_window == q)
2180 QGuiApplicationPrivate::focus_window = q->parent();
2181 if (QGuiApplicationPrivate::currentMouseWindow == q)
2182 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2183 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2184 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2186 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2187 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2188 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2190 resizeEventPending =
true;
2191 receivedExpose =
false;
2197 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2201
2202
2203
2204
2205QPlatformWindow *QWindow::handle()
const
2208 return d->platformWindow;
2212
2213
2214
2215
2216QPlatformSurface *QWindow::surfaceHandle()
const
2219 return d->platformWindow;
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232bool QWindow::setKeyboardGrabEnabled(
bool grab)
2235 if (d->platformWindow)
2236 return d->platformWindow->setKeyboardGrabEnabled(grab);
2241
2242
2243
2244
2245
2246
2247
2248
2249bool QWindow::setMouseGrabEnabled(
bool grab)
2252 if (d->platformWindow)
2253 return d->platformWindow->setMouseGrabEnabled(grab);
2258
2259
2260
2261
2262
2263
2264QScreen *QWindow::screen()
const
2267 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283void QWindow::setScreen(QScreen *newScreen)
2287 newScreen = QGuiApplication::primaryScreen();
2288 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2292
2293
2294
2295
2296
2297
2300
2301
2302
2303
2304QAccessibleInterface *QWindow::accessibleRoot()
const
2310
2311
2312
2313
2314
2315
2316
2319
2320
2321
2322QObject *QWindow::focusObject()
const
2324 return const_cast<QWindow *>(
this);
2328
2329
2330
2331
2332
2333
2334
2335
2341 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2342 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2343 if (defaultState == Qt::WindowFullScreen)
2345 else if (defaultState == Qt::WindowMaximized)
2353
2354
2355
2356
2357
2358
2365
2366
2367
2368
2369
2370
2371
2372void QWindow::showMinimized()
2374 setWindowStates(Qt::WindowMinimized);
2379
2380
2381
2382
2383
2384
2385
2386void QWindow::showMaximized()
2388 setWindowStates(Qt::WindowMaximized);
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403void QWindow::showFullScreen()
2405 setWindowStates(Qt::WindowFullScreen);
2407#if !defined Q_OS_QNX
2414
2415
2416
2417
2418
2419
2420
2421void QWindow::showNormal()
2423 setWindowStates(Qt::WindowNoState);
2428
2429
2430
2431
2432
2433
2434
2435
2436bool QWindow::close()
2446 if (!d->platformWindow) {
2449 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2450 QGuiApplicationPrivate::closePopup(
this);
2456 QPointer guard(
this);
2458 bool success = d->platformWindow->close();
2465bool QWindowPrivate::participatesInLastWindowClosed()
const
2469 if (!q->isTopLevel())
2475 if (q->type() == Qt::ToolTip)
2480 if (q->transientParent())
2486bool QWindowPrivate::treatAsVisible()
const
2489 return q->isVisible();
2493
2494
2495
2496const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2499 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2500 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2501 QWindow *ret =
nullptr;
2502 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2503 if (q == popupWindow)
2505 if (event->isPointerEvent()) {
2507 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2508 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2509 QEventPoint &eventPoint = pointerEvent->point(i);
2510 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2511 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2512 QMutableEventPoint::setPosition(eventPoint, mapped);
2513 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2517
2518
2519 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2520 event->setAccepted(pointerEvent->isAccepted());
2521 if (pointerEvent->isAccepted())
2524 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2525 <<
"handled?" << (ret !=
nullptr)
2526 <<
"accepted?" << event->isAccepted();
2528 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2529 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2531 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2532 <<
"handled?" << (ret !=
nullptr)
2533 <<
"accepted?" << event->isAccepted();
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558void QWindow::exposeEvent(QExposeEvent *ev)
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577void QWindow::paintEvent(QPaintEvent *ev)
2583
2584
2585void QWindow::moveEvent(QMoveEvent *ev)
2591
2592
2593
2594
2595
2596
2597void QWindow::resizeEvent(QResizeEvent *ev)
2603
2604
2605
2606
2607
2608
2609
2610void QWindow::showEvent(QShowEvent *ev)
2616
2617
2618
2619
2620
2621void QWindow::hideEvent(QHideEvent *ev)
2627
2628
2629
2630
2631
2632
2633
2634void QWindow::closeEvent(QCloseEvent *ev)
2640
2641
2642
2643
2644
2645
2646bool QWindow::event(QEvent *ev)
2649 switch (ev->type()) {
2650 case QEvent::MouseMove:
2651 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2654 case QEvent::MouseButtonPress: {
2655 auto *me =
static_cast<QMouseEvent*>(ev);
2656 mousePressEvent(me);
2657 if (!ev->isAccepted())
2658 d->maybeSynthesizeContextMenuEvent(me);
2662 case QEvent::MouseButtonRelease: {
2663 auto *me =
static_cast<QMouseEvent*>(ev);
2664 mouseReleaseEvent(me);
2665 if (!ev->isAccepted())
2666 d->maybeSynthesizeContextMenuEvent(me);
2670 case QEvent::MouseButtonDblClick:
2671 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2674 case QEvent::TouchBegin:
2675 case QEvent::TouchUpdate:
2676 case QEvent::TouchEnd:
2677 case QEvent::TouchCancel:
2678 touchEvent(
static_cast<QTouchEvent *>(ev));
2682 moveEvent(
static_cast<QMoveEvent*>(ev));
2685 case QEvent::Resize:
2686 resizeEvent(
static_cast<QResizeEvent*>(ev));
2689 case QEvent::KeyPress:
2690 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2693 case QEvent::KeyRelease:
2694 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2697 case QEvent::FocusIn: {
2698 focusInEvent(
static_cast<QFocusEvent *>(ev));
2699#if QT_CONFIG(accessibility)
2700 QAccessible::State state;
2701 state.active =
true;
2702 QAccessibleStateChangeEvent event(
this, state);
2703 QAccessible::updateAccessibility(&event);
2707 case QEvent::FocusOut: {
2708 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2709#if QT_CONFIG(accessibility)
2710 QAccessible::State state;
2711 state.active =
true;
2712 QAccessibleStateChangeEvent event(
this, state);
2713 QAccessible::updateAccessibility(&event);
2717#if QT_CONFIG(wheelevent)
2719 wheelEvent(
static_cast<QWheelEvent*>(ev));
2723 case QEvent::Close: {
2725 const bool wasVisible = d->treatAsVisible();
2726 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2729 QPointer<QWindow> deletionGuard(
this);
2730 closeEvent(
static_cast<QCloseEvent*>(ev));
2732 if (ev->isAccepted()) {
2735 if (wasVisible && participatesInLastWindowClosed)
2736 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2742 case QEvent::Expose:
2743 exposeEvent(
static_cast<QExposeEvent *>(ev));
2747 paintEvent(
static_cast<QPaintEvent *>(ev));
2751 showEvent(
static_cast<QShowEvent *>(ev));
2755 hideEvent(
static_cast<QHideEvent *>(ev));
2758 case QEvent::ApplicationWindowIconChange:
2762#if QT_CONFIG(tabletevent)
2763 case QEvent::TabletPress:
2764 case QEvent::TabletMove:
2765 case QEvent::TabletRelease:
2766 tabletEvent(
static_cast<QTabletEvent *>(ev));
2770 case QEvent::PlatformSurface: {
2771 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2773 QOpenGLContext *context = QOpenGLContext::currentContext();
2774 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2775 context->doneCurrent();
2782 return QObject::event(ev);
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
2820
2821
2822
2823
2824
2825
2826void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2828#ifndef QT_NO_CONTEXTMENU
2829 if (event->button() == Qt::RightButton
2830 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2831 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2832 event->globalPosition().toPoint(), event->modifiers());
2833 qCDebug(lcPopup) <<
"synthesized after"
2834 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2835 << event->type() <<
":" << &e;
2836 QCoreApplication::forwardEvent(q_func(), &e, event);
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870void QWindow::requestUpdate()
2872 Q_ASSERT_X(QThread::isMainThread(),
2873 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2876 if (d->updateRequestPending || !d->platformWindow)
2878 d->updateRequestPending =
true;
2879 d->platformWindow->requestUpdate();
2883
2884
2885
2886
2887void QWindow::keyPressEvent(QKeyEvent *ev)
2893
2894
2895
2896
2897void QWindow::keyReleaseEvent(QKeyEvent *ev)
2903
2904
2905
2906
2907
2908
2909void QWindow::focusInEvent(QFocusEvent *ev)
2915
2916
2917
2918
2919
2920
2921void QWindow::focusOutEvent(QFocusEvent *ev)
2927
2928
2929
2930
2931void QWindow::mousePressEvent(QMouseEvent *ev)
2937
2938
2939
2940
2941void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2947
2948
2949
2950
2951void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2957
2958
2959void QWindow::mouseMoveEvent(QMouseEvent *ev)
2964#if QT_CONFIG(wheelevent)
2966
2967
2968void QWindow::wheelEvent(QWheelEvent *ev)
2975
2976
2977void QWindow::touchEvent(QTouchEvent *ev)
2982#if QT_CONFIG(tabletevent)
2984
2985
2986
2987
2988
2989void QWindow::tabletEvent(QTabletEvent *ev)
2996
2997
2998
2999
3000
3001
3002
3004bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3006 Q_UNUSED(eventType);
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3026 if (d->platformWindow
3027 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3028 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3031 if (!QHighDpiScaling::isActive())
3032 return pos + d->globalPosition();
3040 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3044 QPointF nativeWindowGlobalPos = d->platformWindow
3045 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3046 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3047 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3048 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3049 return deviceIndependentGlobalPos;
3053
3054
3055QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3057 return mapToGlobal(QPointF(pos)).toPoint();
3061
3062
3063
3064
3065
3066
3067
3068
3069QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3073 if (d->platformWindow
3074 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3075 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3078 if (!QHighDpiScaling::isActive())
3079 return pos - d->globalPosition();
3083 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3087 QPointF nativeWindowGlobalPos = d->platformWindow
3088 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3089 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3090 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3091 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3092 return deviceIndependentLocalPos;
3096
3097
3098QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3100 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3103QPoint QWindowPrivate::globalPosition()
const
3106 QPoint offset = q->position();
3107 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3108 QPlatformWindow *pw = p->handle();
3109 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3111 offset += p->mapToGlobal(QPoint(0, 0));
3114 offset += p->position();
3122 return window->d_func();
3125QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3129 QWindow *window =
const_cast<QWindow *>(q);
3132 QWindow *parent = window->parent(mode);
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163QWindow *QWindow::fromWinId(WId id)
3165 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3166 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3170 QWindow *window =
new QWindow;
3174 window->setProperty(kForeignWindowId, id);
3177 if (!window->handle()) {
3186
3187
3188
3189
3190
3191
3192
3193
3194
3196void QWindow::alert(
int msec)
3199 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3201 d->platformWindow->setAlertState(
true);
3202 if (d->platformWindow->isAlertState() && msec)
3203 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3206void QWindowPrivate::_q_clearAlert()
3208 if (platformWindow && platformWindow->isAlertState())
3209 platformWindow->setAlertState(
false);
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233void QWindow::setCursor(
const QCursor &cursor)
3236 d->setCursor(&cursor);
3240
3241
3242void QWindow::unsetCursor()
3245 d->setCursor(
nullptr);
3249
3250
3251
3252
3253QCursor QWindow::cursor()
const
3259void QWindowPrivate::setCursor(
const QCursor *newCursor)
3264 const Qt::CursorShape newShape = newCursor->shape();
3265 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3267 cursor = *newCursor;
3272 cursor = QCursor(Qt::ArrowCursor);
3276 if (applyCursor()) {
3277 QEvent event(QEvent::CursorChange);
3278 QGuiApplication::sendEvent(q, &event);
3283bool QWindowPrivate::applyCursor()
3286 if (QScreen *screen = q->screen()) {
3287 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3288 if (!platformWindow)
3290 QCursor *c = QGuiApplication::overrideCursor();
3291 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3293 if (!c && hasCursor)
3295 platformCursor->changeCursor(c, q);
3303void *QWindow::resolveInterface(
const char *name,
int revision)
const
3305 using namespace QNativeInterface::Private;
3307 auto *platformWindow = handle();
3308 Q_UNUSED(platformWindow);
3312#if defined(Q_OS_WIN)
3313 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3317 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3320#if defined(Q_OS_MACOS)
3321 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3324#if QT_CONFIG(wayland)
3325 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3328#if defined(Q_OS_WASM)
3329 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3335#ifndef QT_NO_DEBUG_STREAM
3336QDebug operator<<(QDebug debug,
const QWindow *window)
3338 QDebugStateSaver saver(debug);
3341 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3342 if (!window->objectName().isEmpty())
3343 debug <<
", name=" << window->objectName();
3344 if (debug.verbosity() > 2) {
3345 const QRect geometry = window->geometry();
3346 if (window->isVisible())
3347 debug <<
", visible";
3348 if (window->isExposed())
3349 debug <<
", exposed";
3350 debug <<
", state=" << window->windowState()
3351 <<
", type=" << window->type() <<
", flags=" << window->flags()
3352 <<
", surface type=" << window->surfaceType();
3353 if (window->isTopLevel())
3354 debug <<
", toplevel";
3355 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3356 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3357 const QMargins margins = window->frameMargins();
3358 if (!margins.isNull())
3359 debug <<
", margins=" << margins;
3360 const QMargins safeAreaMargins = window->safeAreaMargins();
3361 if (!safeAreaMargins.isNull())
3362 debug <<
", safeAreaMargins=" << safeAreaMargins;
3363 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3364 if (
const QPlatformWindow *platformWindow = window->handle())
3365 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3366 if (
const QScreen *screen = window->screen())
3367 debug <<
", on " << screen->name();
3371 debug <<
"QWindow(0x0)";
3377#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3380
3381
3382
3383
3384void QWindow::setVulkanInstance(QVulkanInstance *instance)
3387 d->vulkanInstance = instance;
3391
3392
3393QVulkanInstance *QWindow::vulkanInstance()
const
3396 return d->vulkanInstance;
3403#include "moc_qwindow.cpp"
static constexpr auto kForeignWindowId