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"
25#if QT_CONFIG(draganddrop)
26#include "qshapedpixmapdndwindow_p.h"
29#include <private/qevent_p.h>
30#include <private/qeventpoint_p.h>
31#include <private/qguiapplication_p.h>
33#include <QtCore/QTimer>
34#include <QtCore/QDebug>
37#include <qpa/qplatformcursor.h>
38#include <qpa/qplatformwindow_p.h>
43
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
122
123
124
125
126
127
128QWindow::QWindow(QScreen *targetScreen)
129 : QObject(*
new QWindowPrivate(),
nullptr)
130 , QSurface(QSurface::Window)
133 d->init(
nullptr, targetScreen);
138 if (parent && parent->type() == Qt::Desktop) {
139 qWarning(
"QWindows cannot be reparented into desktop windows");
147
148
149
150
151
152
153
154
155
156QWindow::QWindow(QWindow *parent)
157 : QWindow(*
new QWindowPrivate(), parent)
162
163
164
165
166
167
168
169
170
171
172
173QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
174 : QObject(dd,
nullptr)
175 , QSurface(QSurface::Window)
178 d->init(nonDesktopParent(parent));
182
183
190 QGuiApplicationPrivate::window_list.removeAll(
this);
191 QGuiApplicationPrivate::popup_list.removeAll(
this);
192 if (!QGuiApplicationPrivate::is_app_closing)
193 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
198 if (QGuiApplicationPrivate::focus_window ==
this)
199 QGuiApplicationPrivate::focus_window =
nullptr;
200 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
201 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
202 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
203 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
208QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
209 : QObjectPrivate(version)
212QWindowPrivate::~QWindowPrivate()
215void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
219 q->QObject::setParent(parent);
222 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
224 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
227 connectToScreen(connectScreen);
231 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
232 qFatal(
"Cannot create window: no screens available");
234 QGuiApplicationPrivate::window_list.prepend(q);
236 requestedFormat = QSurfaceFormat::defaultFormat();
237 devicePixelRatio = connectScreen->devicePixelRatio();
239 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
245 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q, QHighDpi::fromNativePixels(q->handle()->geometry(), q));
246 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
251 updateDevicePixelRatio();
255 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
256 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
261
262
263
264
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311QWindow::Visibility QWindow::visibility()
const
314 return d->visibility;
317void QWindow::setVisibility(Visibility v)
323 case AutomaticVisibility:
344
345
346
347
348
349void QWindowPrivate::setVisible(
bool visible)
353 if (
this->visible != visible) {
354 this->visible = visible;
355 emit q->visibleChanged(visible);
357 }
else if (platformWindow) {
362 if (!platformWindow) {
365 if (parentWindow && !parentWindow->handle())
381 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
383 if (q->type() == Qt::Window) {
384 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
385 QString &firstWindowTitle = app_priv->firstWindowTitle;
386 if (!firstWindowTitle.isEmpty()) {
387 q->setTitle(firstWindowTitle);
388 firstWindowTitle = QString();
390 if (!app_priv->forcedWindowIcon.isNull())
391 q->setIcon(app_priv->forcedWindowIcon);
394 static bool geometryApplied =
false;
395 if (!geometryApplied) {
396 geometryApplied =
true;
397 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
401 QShowEvent showEvent;
402 QGuiApplication::sendEvent(q, &showEvent);
407 QGuiApplicationPrivate::showModalWindow(q);
409 QGuiApplicationPrivate::hideModalWindow(q);
412 }
else if (visible && QGuiApplication::modalWindow()
413#if QT_CONFIG(draganddrop)
414 && !qobject_cast<QShapedPixmapWindow *>(q)
417 QGuiApplicationPrivate::updateBlockedStatus(q);
420 if (q->type() == Qt::Popup) {
422 QGuiApplicationPrivate::activatePopup(q);
424 QGuiApplicationPrivate::closePopup(q);
428 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
433 platformWindow->setVisible(visible);
436 QHideEvent hideEvent;
437 QGuiApplication::sendEvent(q, &hideEvent);
441void QWindowPrivate::updateVisibility()
445 QWindow::Visibility old = visibility;
448 visibility = QWindow::Hidden;
449 else if (windowState & Qt::WindowMinimized)
450 visibility = QWindow::Minimized;
451 else if (windowState & Qt::WindowFullScreen)
452 visibility = QWindow::FullScreen;
453 else if (windowState & Qt::WindowMaximized)
454 visibility = QWindow::Maximized;
456 visibility = QWindow::Windowed;
458 if (visibility != old)
459 emit q->visibilityChanged(visibility);
462void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
469 QObjectList &siblings = q->parent()->d_ptr->children;
471 const qsizetype siblingCount = siblings.size() - 1;
472 if (siblingCount == 0)
475 const qsizetype currentPosition = siblings.indexOf(q);
476 Q_ASSERT(currentPosition >= 0);
478 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
480 if (currentPosition == targetPosition)
483 siblings.move(currentPosition, targetPosition);
486bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
489 const QScreen *oldScreen = q->screen();
490 return oldScreen != newScreen && (platformWindow || !oldScreen)
491 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
494void QWindowPrivate::disconnectFromScreen()
497 topLevelScreen =
nullptr;
500void QWindowPrivate::connectToScreen(QScreen *screen)
502 disconnectFromScreen();
503 topLevelScreen = screen;
506void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
509 emit q->screenChanged(newScreen);
510 for (QObject *child : q->children()) {
511 if (child->isWindowType())
512 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
516void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
520 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
523 if (newScreen != topLevelScreen) {
524 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
525 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
526 if (shouldRecreate && platformWindow)
528 connectToScreen(newScreen);
531 else if (newScreen && shouldRecreate)
533 emitScreenChangedRecursion(newScreen);
539void QWindowPrivate::create(
bool recursive)
546 const bool needsUpdate = updateRequestPending;
548 updateRequestPending =
false;
551 q->parent()->create();
553 if (platformWindow) {
562 if (q->isTopLevel()) {
563 if (QScreen *screen = screenForGeometry(geometry))
564 setTopLevelScreen(screen,
false);
567 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
569 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
570 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
571 : platformIntegration->createPlatformWindow(q);
572 Q_ASSERT(platformWindow);
574 if (!platformWindow) {
575 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
579 platformWindow->initialize();
581 QObjectList childObjects = q->children();
582 for (
int i = 0; i < childObjects.size(); i ++) {
583 QObject *object = childObjects.at(i);
584 if (!object->isWindowType())
587 QWindow *childWindow =
static_cast<QWindow *>(object);
589 childWindow->d_func()->create(recursive);
594 if (childWindow->isVisible())
595 childWindow->setVisible(
true);
597 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
598 childPlatformWindow->setParent(
this->platformWindow);
601 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
602 QGuiApplication::sendEvent(q, &e);
604 updateDevicePixelRatio();
610void QWindowPrivate::clearFocusObject()
617QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
623void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
624 qxp::function_ref<
void()> funcWidthChanged,
625 qxp::function_ref<
void()> funcHeightChanged)
628 Q_ASSERT(oldSizeMember);
629 const QSize adjustedSize =
630 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
631 if (*oldSizeMember == adjustedSize)
633 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
634 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
635 *oldSizeMember = adjustedSize;
637 if (platformWindow && q->isTopLevel())
638 platformWindow->propagateSizeHints();
646 if (minimumSize.width() <= maximumSize.width()
647 || minimumSize.height() <= maximumSize.height()) {
648 const QSize currentSize = q->size();
649 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
650 q->resize(boundedSize);
655
656
657
658
659
660
661
662
663
664
665
666
667void QWindow::setSurfaceType(SurfaceType surfaceType)
670 d->surfaceType = surfaceType;
674
675
676
677
678QWindow::SurfaceType QWindow::surfaceType()
const
681 return d->surfaceType;
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702void QWindow::setVisible(
bool visible)
706 d->setVisible(visible);
709bool QWindow::isVisible()
const
717
718
719
720
721
722
723
724
725
726
727
728
729
730void QWindow::create()
737
738
739
740
741
742
743
744
745
746
747WId QWindow::winId()
const
751 if (!d->platformWindow)
752 const_cast<QWindow *>(
this)->create();
754 if (!d->platformWindow)
757 return d->platformWindow->winId();
761
762
763
764
765
766
767
768
769
770QWindow *QWindow::parent(AncestorMode mode)
const
773 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
777
778
779
780
781
782
783
784
785
786void QWindow::setParent(QWindow *parent)
788 parent = nonDesktopParent(parent);
791 if (d->parentWindow == parent)
794 QScreen *newScreen = parent ? parent->screen() : screen();
795 if (d->windowRecreationRequired(newScreen)) {
796 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << screen() << newScreen <<
')';
800 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
801 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
803 const auto previousParent = d->parentWindow;
804 QObject::setParent(parent);
805 d->parentWindow = parent;
808 d->disconnectFromScreen();
810 d->connectToScreen(newScreen);
815 if (isVisible() && (!parent || parent->handle()))
818 if (d->platformWindow) {
822 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
825 QGuiApplicationPrivate::updateBlockedStatus(
this);
827 if (previousParent) {
828 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
829 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
833 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
834 QCoreApplication::sendEvent(parent, &childAddedEvent);
837 QEvent parentChangedEvent(QEvent::ParentWindowChange);
838 QCoreApplication::sendEvent(
this, &parentChangedEvent);
842
843
844bool QWindow::isTopLevel()
const
847 return d->parentWindow ==
nullptr;
851
852
853
854
855
856
857bool QWindow::isModal()
const
860 return d->modality != Qt::NonModal;
864
865
866
867
868
869
870
871
872
874Qt::WindowModality QWindow::modality()
const
880void QWindow::setModality(Qt::WindowModality modality)
883 if (d->modality == modality)
885 d->modality = modality;
886 emit modalityChanged(modality);
890
891
892
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920void QWindow::setFormat(
const QSurfaceFormat &format)
923 d->requestedFormat = format;
927
928
929
930
931
932
933
934
935
936QSurfaceFormat QWindow::requestedFormat()
const
939 return d->requestedFormat;
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959QSurfaceFormat QWindow::format()
const
962 if (d->platformWindow)
963 return d->platformWindow->format();
964 return d->requestedFormat;
968
969
970
971
972
973
974
975
976
977
978
979
980void QWindow::setFlags(Qt::WindowFlags flags)
983 if (d->windowFlags == flags)
986 if (d->platformWindow)
987 d->platformWindow->setWindowFlags(flags);
988 d->windowFlags = flags;
991Qt::WindowFlags QWindow::flags()
const
994 Qt::WindowFlags flags = d->windowFlags;
996 if (d->platformWindow && d->platformWindow->isForeignWindow())
997 flags |= Qt::ForeignWindow;
1003
1004
1005
1006
1007
1008
1009
1010void QWindow::setFlag(Qt::WindowType flag,
bool on)
1014 setFlags(d->windowFlags | flag);
1016 setFlags(d->windowFlags & ~flag);
1020
1021
1022
1023
1024
1025
1026
1027Qt::WindowType QWindow::type()
const
1029 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043void QWindow::setTitle(
const QString &title)
1046 bool changed =
false;
1047 if (d->windowTitle != title) {
1048 d->windowTitle = title;
1051 if (d->platformWindow && type() != Qt::Desktop)
1052 d->platformWindow->setWindowTitle(title);
1054 emit windowTitleChanged(title);
1057QString QWindow::title()
const
1060 return d->windowTitle;
1064
1065
1066
1067
1068
1069
1070void QWindow::setFilePath(
const QString &filePath)
1073 d->windowFilePath = filePath;
1074 if (d->platformWindow)
1075 d->platformWindow->setWindowFilePath(filePath);
1079
1080
1081
1082
1083QString QWindow::filePath()
const
1086 return d->windowFilePath;
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100void QWindow::setIcon(
const QIcon &icon)
1103 d->windowIcon = icon;
1104 if (d->platformWindow)
1105 d->platformWindow->setWindowIcon(icon);
1106 QEvent e(QEvent::WindowIconChange);
1107 QCoreApplication::sendEvent(
this, &e);
1111
1112
1113
1114
1115QIcon QWindow::icon()
const
1118 if (d->windowIcon.isNull())
1119 return QGuiApplication::windowIcon();
1120 return d->windowIcon;
1124
1125
1126
1127
1128void QWindow::raise()
1132 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1134 if (d->platformWindow)
1135 d->platformWindow->raise();
1139
1140
1141
1142
1143void QWindow::lower()
1147 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1149 if (d->platformWindow)
1150 d->platformWindow->lower();
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171bool QWindow::startSystemResize(Qt::Edges edges)
1174 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1177 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1178 const bool isCorner =
1179 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1180 edges == (Qt::TopEdge | Qt::RightEdge) ||
1181 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1182 edges == (Qt::BottomEdge | Qt::LeftEdge);
1184 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1185 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1189 return d->platformWindow->startSystemResize(edges);
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209bool QWindow::startSystemMove()
1212 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1215 return d->platformWindow->startSystemMove();
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232void QWindow::setOpacity(qreal level)
1235 if (level == d->opacity)
1238 if (d->platformWindow) {
1239 d->platformWindow->setOpacity(level);
1240 emit opacityChanged(level);
1244qreal QWindow::opacity()
const
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260void QWindow::setMask(
const QRegion ®ion)
1263 if (d->platformWindow)
1264 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1269
1270
1271
1272
1273
1274QRegion QWindow::mask()
const
1281
1282
1283
1284
1285void QWindow::requestActivate()
1288 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1289 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1292 if (d->platformWindow)
1293 d->platformWindow->requestActivateWindow();
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307bool QWindow::isExposed()
const
1314
1315
1316
1317
1318
1319
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333bool QWindow::isActive()
const
1336 if (!d->platformWindow)
1339 QWindow *focus = QGuiApplication::focusWindow();
1348 if (QWindow *p = parent(IncludeTransients))
1349 return p->isActive();
1351 return isAncestorOf(focus);
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1376 if (d->contentOrientation == orientation)
1378 if (d->platformWindow)
1379 d->platformWindow->handleContentOrientationChange(orientation);
1380 d->contentOrientation = orientation;
1381 emit contentOrientationChanged(orientation);
1384Qt::ScreenOrientation QWindow::contentOrientation()
const
1387 return d->contentOrientation;
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402qreal QWindow::devicePixelRatio()
const
1405 return d->devicePixelRatio;
1409
1410
1411
1412
1413bool QWindowPrivate::updateDevicePixelRatio()
1417 const qreal newDevicePixelRatio = [
this, q]{
1419 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1424 if (
auto *screen = q->screen())
1425 return screen->devicePixelRatio();
1428 return qGuiApp->devicePixelRatio();
1431 if (newDevicePixelRatio == devicePixelRatio)
1434 devicePixelRatio = newDevicePixelRatio;
1435 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1436 QGuiApplication::sendEvent(q, &dprChangeEvent);
1440Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1442 if (state & Qt::WindowMinimized)
1443 return Qt::WindowMinimized;
1444 else if (state & Qt::WindowFullScreen)
1445 return Qt::WindowFullScreen;
1446 else if (state & Qt::WindowMaximized)
1447 return Qt::WindowMaximized;
1448 return Qt::WindowNoState;
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461void QWindow::setWindowState(Qt::WindowState state)
1463 setWindowStates(state);
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482void QWindow::setWindowStates(Qt::WindowStates state)
1485 if (state & Qt::WindowActive) {
1486 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1487 state &= ~Qt::WindowActive;
1490 if (d->platformWindow)
1491 d->platformWindow->setWindowState(state);
1493 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1494 d->windowState = state;
1495 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1496 if (newEffectiveState != originalEffectiveState)
1497 emit windowStateChanged(newEffectiveState);
1499 d->updateVisibility();
1503
1504
1505
1506
1507Qt::WindowState QWindow::windowState()
const
1510 return QWindowPrivate::effectiveState(d->windowState);
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524Qt::WindowStates QWindow::windowStates()
const
1527 return d->windowState;
1531
1532
1533
1534
1535
1536
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552void QWindow::setTransientParent(QWindow *parent)
1555 if (parent && !parent->isTopLevel()) {
1556 qWarning() << parent <<
"must be a top level window.";
1559 if (parent ==
this) {
1560 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1564 d->transientParent = parent;
1566 QGuiApplicationPrivate::updateBlockedStatus(
this);
1567 emit transientParentChanged(parent);
1570QWindow *QWindow::transientParent()
const
1573 return d->transientParent.data();
1577
1578
1579
1580
1581
1582void QWindowPrivate::setTransientParent(QWindow *parent)
1585 q->setTransientParent(parent);
1586 transientParentPropertySet =
true;
1590
1591
1592
1593
1594
1595
1596
1597
1600
1601
1602
1603bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1605 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1608 if (QWindow *parent = child->parent(mode)) {
1609 if (isAncestorOf(parent, mode))
1611 }
else if (handle() && child->handle()) {
1612 if (handle()->isAncestorOf(child->handle()))
1620
1621
1622
1623
1624QSize QWindow::minimumSize()
const
1627 return d->minimumSize;
1631
1632
1633
1634
1635QSize QWindow::maximumSize()
const
1638 return d->maximumSize;
1642
1643
1644
1645
1646QSize QWindow::baseSize()
const
1653
1654
1655
1656
1657QSize QWindow::sizeIncrement()
const
1660 return d->sizeIncrement;
1664
1665
1666
1667
1668
1669
1670void QWindow::setMinimumSize(
const QSize &size)
1674 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1675 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1679
1680
1681
1682void QWindow::setX(
int arg)
1686 setGeometry(QRect(arg, y(), width(), height()));
1688 d->positionAutomatic =
false;
1692
1693
1694
1695void QWindow::setY(
int arg)
1699 setGeometry(QRect(x(), arg, width(), height()));
1701 d->positionAutomatic =
false;
1705
1706
1707
1708void QWindow::setWidth(
int w)
1710 resize(w, height());
1714
1715
1716
1717void QWindow::setHeight(
int h)
1723
1724
1725
1726void QWindow::setMinimumWidth(
int w)
1728 setMinimumSize(QSize(w, minimumHeight()));
1732
1733
1734
1735void QWindow::setMinimumHeight(
int h)
1737 setMinimumSize(QSize(minimumWidth(), h));
1741
1742
1743
1744
1745
1746
1747void QWindow::setMaximumSize(
const QSize &size)
1751 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1752 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1756
1757
1758
1759void QWindow::setMaximumWidth(
int w)
1761 setMaximumSize(QSize(w, maximumHeight()));
1765
1766
1767
1768void QWindow::setMaximumHeight(
int h)
1770 setMaximumSize(QSize(maximumWidth(), h));
1774
1775
1776
1777
1778
1779
1780
1781void QWindow::setBaseSize(
const QSize &size)
1784 if (d->baseSize == size)
1787 if (d->platformWindow && isTopLevel())
1788 d->platformWindow->propagateSizeHints();
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805void QWindow::setSizeIncrement(
const QSize &size)
1808 if (d->sizeIncrement == size)
1810 d->sizeIncrement = size;
1811 if (d->platformWindow && isTopLevel())
1812 d->platformWindow->propagateSizeHints();
1816
1817
1818
1819
1820
1821
1822
1823void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1825 setGeometry(QRect(posx, posy, w, h));
1829
1830
1831
1832
1833
1834
1835void QWindow::setGeometry(
const QRect &rect)
1838 d->positionAutomatic =
false;
1839 const QRect oldRect = geometry();
1840 if (rect == oldRect)
1843 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1844 if (d->platformWindow) {
1845 QScreen *newScreen = d->screenForGeometry(rect);
1846 if (newScreen && isTopLevel())
1847 d->setTopLevelScreen(newScreen,
true);
1848 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1852 if (rect.x() != oldRect.x())
1853 emit xChanged(rect.x());
1854 if (rect.y() != oldRect.y())
1855 emit yChanged(rect.y());
1856 if (rect.width() != oldRect.width())
1857 emit widthChanged(rect.width());
1858 if (rect.height() != oldRect.height())
1859 emit heightChanged(rect.height());
1864
1865
1866
1867
1868
1869QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1872 QScreen *currentScreen = q->screen();
1873 QScreen *fallback = currentScreen;
1874 QPoint center = newGeometry.center();
1875 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1876 const auto screens = currentScreen->virtualSiblings();
1877 for (QScreen* screen : screens) {
1878 if (screen->geometry().contains(center))
1880 if (screen->geometry().intersects(newGeometry))
1889
1890
1891
1892
1893
1894
1895QRect QWindow::geometry()
const
1898 if (d->platformWindow) {
1899 const auto nativeGeometry = d->platformWindow->geometry();
1900 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1906
1907
1908
1909
1910QMargins QWindow::frameMargins()
const
1913 if (d->platformWindow)
1914 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1919
1920
1921
1922
1923
1924
1925QRect QWindow::frameGeometry()
const
1928 if (d->platformWindow) {
1929 QMargins m = frameMargins();
1930 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1936
1937
1938
1939
1940
1941
1942QPoint QWindow::framePosition()
const
1945 if (d->platformWindow) {
1946 QMargins margins = frameMargins();
1947 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1949 return d->geometry.topLeft();
1953
1954
1955
1956
1957
1958
1959void QWindow::setFramePosition(
const QPoint &point)
1962 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1963 d->positionAutomatic =
false;
1964 if (d->platformWindow) {
1965 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
1967 d->geometry.moveTopLeft(point);
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994QMargins QWindow::safeAreaMargins()
const
1997 if (d->platformWindow)
1998 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2003
2004
2005
2006
2007
2008
2009
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025void QWindow::setPosition(
const QPoint &pt)
2027 setGeometry(QRect(pt, size()));
2031
2032
2033
2034
2035
2036
2037void QWindow::setPosition(
int posx,
int posy)
2039 setPosition(QPoint(posx, posy));
2043
2044
2045
2046
2047
2048
2049
2050
2051
2054
2055
2056
2057
2058
2061
2062
2063
2064
2065
2066
2067
2068void QWindow::resize(
int w,
int h)
2070 resize(QSize(w, h));
2074
2075
2076
2077
2078void QWindow::resize(
const QSize &newSize)
2082 const QSize oldSize = size();
2083 if (newSize == oldSize)
2086 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2087 if (d->platformWindow) {
2088 d->platformWindow->setGeometry(
2089 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2091 d->geometry.setSize(newSize);
2092 if (newSize.width() != oldSize.width())
2093 emit widthChanged(newSize.width());
2094 if (newSize.height() != oldSize.height())
2095 emit heightChanged(newSize.height());
2100
2101
2102
2103
2104void QWindow::destroy()
2107 if (!d->platformWindow)
2110 if (d->platformWindow->isForeignWindow())
2116void QWindowPrivate::destroy()
2118 if (!platformWindow)
2122 QObjectList childrenWindows = q->children();
2123 for (
int i = 0; i < childrenWindows.size(); i++) {
2124 QObject *object = childrenWindows.at(i);
2125 if (object->isWindowType()) {
2126 QWindow *w =
static_cast<QWindow*>(object);
2127 qt_window_private(w)->destroy();
2131 bool wasVisible = q->isVisible();
2132 visibilityOnDestroy = wasVisible && platformWindow;
2134 q->setVisible(
false);
2145 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2146 QGuiApplication::sendEvent(q, &e);
2151 delete std::exchange(platformWindow,
nullptr);
2153 if (QGuiApplicationPrivate::focus_window == q)
2154 QGuiApplicationPrivate::focus_window = q->parent();
2155 if (QGuiApplicationPrivate::currentMouseWindow == q)
2156 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2157 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2158 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2160 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2161 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2162 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2164 resizeEventPending =
true;
2165 receivedExpose =
false;
2171 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2175
2176
2177
2178
2179QPlatformWindow *QWindow::handle()
const
2182 return d->platformWindow;
2186
2187
2188
2189
2190QPlatformSurface *QWindow::surfaceHandle()
const
2193 return d->platformWindow;
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206bool QWindow::setKeyboardGrabEnabled(
bool grab)
2209 if (d->platformWindow)
2210 return d->platformWindow->setKeyboardGrabEnabled(grab);
2215
2216
2217
2218
2219
2220
2221
2222
2223bool QWindow::setMouseGrabEnabled(
bool grab)
2226 if (d->platformWindow)
2227 return d->platformWindow->setMouseGrabEnabled(grab);
2232
2233
2234
2235
2236
2237
2238QScreen *QWindow::screen()
const
2241 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257void QWindow::setScreen(QScreen *newScreen)
2261 newScreen = QGuiApplication::primaryScreen();
2262 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2266
2267
2268
2269
2270
2271
2274
2275
2276
2277
2278QAccessibleInterface *QWindow::accessibleRoot()
const
2284
2285
2286
2287
2288
2289
2290
2293
2294
2295
2296QObject *QWindow::focusObject()
const
2298 return const_cast<QWindow *>(
this);
2302
2303
2304
2305
2306
2307
2308
2309
2315 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2316 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2317 if (defaultState == Qt::WindowFullScreen)
2319 else if (defaultState == Qt::WindowMaximized)
2327
2328
2329
2330
2331
2332
2339
2340
2341
2342
2343
2344
2345
2346void QWindow::showMinimized()
2348 setWindowStates(Qt::WindowMinimized);
2353
2354
2355
2356
2357
2358
2359
2360void QWindow::showMaximized()
2362 setWindowStates(Qt::WindowMaximized);
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377void QWindow::showFullScreen()
2379 setWindowStates(Qt::WindowFullScreen);
2381#if !defined Q_OS_QNX
2388
2389
2390
2391
2392
2393
2394
2395void QWindow::showNormal()
2397 setWindowStates(Qt::WindowNoState);
2402
2403
2404
2405
2406
2407
2408
2409
2410bool QWindow::close()
2420 if (!d->platformWindow) {
2423 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2424 QGuiApplicationPrivate::closePopup(
this);
2430 QPointer guard(
this);
2432 bool success = d->platformWindow->close();
2439bool QWindowPrivate::participatesInLastWindowClosed()
const
2443 if (!q->isTopLevel())
2449 if (q->type() == Qt::ToolTip)
2454 if (q->transientParent())
2460bool QWindowPrivate::treatAsVisible()
const
2463 return q->isVisible();
2467
2468
2469
2470const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2473 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2474 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2475 QWindow *ret =
nullptr;
2476 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2477 if (q == popupWindow)
2479 if (event->isPointerEvent()) {
2481 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2482 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2483 QEventPoint &eventPoint = pointerEvent->point(i);
2484 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2485 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2486 QMutableEventPoint::setPosition(eventPoint, mapped);
2487 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2491
2492
2493 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2494 event->setAccepted(pointerEvent->isAccepted());
2495 if (pointerEvent->isAccepted())
2498 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2499 <<
"handled?" << (ret !=
nullptr)
2500 <<
"accepted?" << event->isAccepted();
2502 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2503 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2505 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2506 <<
"handled?" << (ret !=
nullptr)
2507 <<
"accepted?" << event->isAccepted();
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532void QWindow::exposeEvent(QExposeEvent *ev)
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551void QWindow::paintEvent(QPaintEvent *ev)
2557
2558
2559void QWindow::moveEvent(QMoveEvent *ev)
2565
2566
2567
2568
2569
2570
2571void QWindow::resizeEvent(QResizeEvent *ev)
2577
2578
2579
2580
2581
2582
2583
2584void QWindow::showEvent(QShowEvent *ev)
2590
2591
2592
2593
2594
2595void QWindow::hideEvent(QHideEvent *ev)
2601
2602
2603
2604
2605
2606
2607
2608void QWindow::closeEvent(QCloseEvent *ev)
2614
2615
2616
2617
2618
2619
2620bool QWindow::event(QEvent *ev)
2623 switch (ev->type()) {
2624 case QEvent::MouseMove:
2625 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2628 case QEvent::MouseButtonPress: {
2629 auto *me =
static_cast<QMouseEvent*>(ev);
2630 mousePressEvent(me);
2631 if (!ev->isAccepted())
2632 d->maybeSynthesizeContextMenuEvent(me);
2636 case QEvent::MouseButtonRelease: {
2637 auto *me =
static_cast<QMouseEvent*>(ev);
2638 mouseReleaseEvent(me);
2639 if (!ev->isAccepted())
2640 d->maybeSynthesizeContextMenuEvent(me);
2644 case QEvent::MouseButtonDblClick:
2645 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2648 case QEvent::TouchBegin:
2649 case QEvent::TouchUpdate:
2650 case QEvent::TouchEnd:
2651 case QEvent::TouchCancel:
2652 touchEvent(
static_cast<QTouchEvent *>(ev));
2656 moveEvent(
static_cast<QMoveEvent*>(ev));
2659 case QEvent::Resize:
2660 resizeEvent(
static_cast<QResizeEvent*>(ev));
2663 case QEvent::KeyPress:
2664 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2667 case QEvent::KeyRelease:
2668 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2671 case QEvent::FocusIn: {
2672 focusInEvent(
static_cast<QFocusEvent *>(ev));
2673#if QT_CONFIG(accessibility)
2674 QAccessible::State state;
2675 state.active =
true;
2676 QAccessibleStateChangeEvent event(
this, state);
2677 QAccessible::updateAccessibility(&event);
2681 case QEvent::FocusOut: {
2682 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2683#if QT_CONFIG(accessibility)
2684 QAccessible::State state;
2685 state.active =
true;
2686 QAccessibleStateChangeEvent event(
this, state);
2687 QAccessible::updateAccessibility(&event);
2691#if QT_CONFIG(wheelevent)
2693 wheelEvent(
static_cast<QWheelEvent*>(ev));
2697 case QEvent::Close: {
2699 const bool wasVisible = d->treatAsVisible();
2700 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2703 QPointer<QWindow> deletionGuard(
this);
2704 closeEvent(
static_cast<QCloseEvent*>(ev));
2706 if (ev->isAccepted()) {
2709 if (wasVisible && participatesInLastWindowClosed)
2710 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2716 case QEvent::Expose:
2717 exposeEvent(
static_cast<QExposeEvent *>(ev));
2721 paintEvent(
static_cast<QPaintEvent *>(ev));
2725 showEvent(
static_cast<QShowEvent *>(ev));
2729 hideEvent(
static_cast<QHideEvent *>(ev));
2732 case QEvent::ApplicationWindowIconChange:
2736#if QT_CONFIG(tabletevent)
2737 case QEvent::TabletPress:
2738 case QEvent::TabletMove:
2739 case QEvent::TabletRelease:
2740 tabletEvent(
static_cast<QTabletEvent *>(ev));
2744 case QEvent::PlatformSurface: {
2745 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2747 QOpenGLContext *context = QOpenGLContext::currentContext();
2748 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2749 context->doneCurrent();
2756 return QObject::event(ev);
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2802#ifndef QT_NO_CONTEXTMENU
2803 if (event->button() == Qt::RightButton
2804 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2805 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2806 event->globalPosition().toPoint(), event->modifiers());
2807 qCDebug(lcPopup) <<
"synthesized after"
2808 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2809 << event->type() <<
":" << &e;
2810 QCoreApplication::forwardEvent(q_func(), &e, event);
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842void QWindow::requestUpdate()
2844 Q_ASSERT_X(QThread::isMainThread(),
2845 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2848 if (d->updateRequestPending || !d->platformWindow)
2850 d->updateRequestPending =
true;
2851 d->platformWindow->requestUpdate();
2855
2856
2857
2858
2859void QWindow::keyPressEvent(QKeyEvent *ev)
2865
2866
2867
2868
2869void QWindow::keyReleaseEvent(QKeyEvent *ev)
2875
2876
2877
2878
2879
2880
2881void QWindow::focusInEvent(QFocusEvent *ev)
2887
2888
2889
2890
2891
2892
2893void QWindow::focusOutEvent(QFocusEvent *ev)
2899
2900
2901
2902
2903void QWindow::mousePressEvent(QMouseEvent *ev)
2909
2910
2911
2912
2913void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2919
2920
2921
2922
2923void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2929
2930
2931void QWindow::mouseMoveEvent(QMouseEvent *ev)
2936#if QT_CONFIG(wheelevent)
2938
2939
2940void QWindow::wheelEvent(QWheelEvent *ev)
2947
2948
2949void QWindow::touchEvent(QTouchEvent *ev)
2954#if QT_CONFIG(tabletevent)
2956
2957
2958
2959
2960
2961void QWindow::tabletEvent(QTabletEvent *ev)
2968
2969
2970
2971
2972
2973
2974
2976bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
2978 Q_UNUSED(eventType);
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
2998 if (d->platformWindow
2999 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3000 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3003 if (!QHighDpiScaling::isActive())
3004 return pos + d->globalPosition();
3012 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3016 QPointF nativeWindowGlobalPos = d->platformWindow
3017 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3018 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3019 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3020 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3021 return deviceIndependentGlobalPos;
3025
3026
3027QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3029 return mapToGlobal(QPointF(pos)).toPoint();
3033
3034
3035
3036
3037
3038
3039
3040
3041QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3045 if (d->platformWindow
3046 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3047 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3050 if (!QHighDpiScaling::isActive())
3051 return pos - d->globalPosition();
3055 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3059 QPointF nativeWindowGlobalPos = d->platformWindow
3060 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3061 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3062 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3063 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3064 return deviceIndependentLocalPos;
3068
3069
3070QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3072 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3075QPoint QWindowPrivate::globalPosition()
const
3078 QPoint offset = q->position();
3079 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3080 QPlatformWindow *pw = p->handle();
3081 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3083 offset += p->mapToGlobal(QPoint(0, 0));
3086 offset += p->position();
3094 return window->d_func();
3097QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3101 QWindow *window =
const_cast<QWindow *>(q);
3104 QWindow *parent = window->parent(mode);
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135QWindow *QWindow::fromWinId(WId id)
3137 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3138 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3142 QWindow *window =
new QWindow;
3146 window->setProperty(kForeignWindowId, id);
3149 if (!window->handle()) {
3158
3159
3160
3161
3162
3163
3164
3165
3166
3168void QWindow::alert(
int msec)
3171 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3173 d->platformWindow->setAlertState(
true);
3174 if (d->platformWindow->isAlertState() && msec)
3175 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3178void QWindowPrivate::_q_clearAlert()
3180 if (platformWindow && platformWindow->isAlertState())
3181 platformWindow->setAlertState(
false);
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205void QWindow::setCursor(
const QCursor &cursor)
3208 d->setCursor(&cursor);
3212
3213
3214void QWindow::unsetCursor()
3217 d->setCursor(
nullptr);
3221
3222
3223
3224
3225QCursor QWindow::cursor()
const
3231void QWindowPrivate::setCursor(
const QCursor *newCursor)
3236 const Qt::CursorShape newShape = newCursor->shape();
3237 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3239 cursor = *newCursor;
3244 cursor = QCursor(Qt::ArrowCursor);
3248 if (applyCursor()) {
3249 QEvent event(QEvent::CursorChange);
3250 QGuiApplication::sendEvent(q, &event);
3255bool QWindowPrivate::applyCursor()
3258 if (QScreen *screen = q->screen()) {
3259 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3260 if (!platformWindow)
3262 QCursor *c = QGuiApplication::overrideCursor();
3263 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3265 if (!c && hasCursor)
3267 platformCursor->changeCursor(c, q);
3275void *QWindow::resolveInterface(
const char *name,
int revision)
const
3277 using namespace QNativeInterface::Private;
3279 auto *platformWindow = handle();
3280 Q_UNUSED(platformWindow);
3284#if defined(Q_OS_WIN)
3285 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3289 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3292#if defined(Q_OS_MACOS)
3293 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3296#if QT_CONFIG(wayland)
3297 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3300#if defined(Q_OS_WASM)
3301 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3307#ifndef QT_NO_DEBUG_STREAM
3308QDebug operator<<(QDebug debug,
const QWindow *window)
3310 QDebugStateSaver saver(debug);
3313 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3314 if (!window->objectName().isEmpty())
3315 debug <<
", name=" << window->objectName();
3316 if (debug.verbosity() > 2) {
3317 const QRect geometry = window->geometry();
3318 if (window->isVisible())
3319 debug <<
", visible";
3320 if (window->isExposed())
3321 debug <<
", exposed";
3322 debug <<
", state=" << window->windowState()
3323 <<
", type=" << window->type() <<
", flags=" << window->flags()
3324 <<
", surface type=" << window->surfaceType();
3325 if (window->isTopLevel())
3326 debug <<
", toplevel";
3327 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3328 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3329 const QMargins margins = window->frameMargins();
3330 if (!margins.isNull())
3331 debug <<
", margins=" << margins;
3332 const QMargins safeAreaMargins = window->safeAreaMargins();
3333 if (!safeAreaMargins.isNull())
3334 debug <<
", safeAreaMargins=" << safeAreaMargins;
3335 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3336 if (
const QPlatformWindow *platformWindow = window->handle())
3337 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3338 if (
const QScreen *screen = window->screen())
3339 debug <<
", on " << screen->name();
3343 debug <<
"QWindow(0x0)";
3349#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3352
3353
3354
3355
3356void QWindow::setVulkanInstance(QVulkanInstance *instance)
3359 d->vulkanInstance = instance;
3363
3364
3365QVulkanInstance *QWindow::vulkanInstance()
const
3368 return d->vulkanInstance;
3375#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId
static QWindow * nonDesktopParent(QWindow *parent)