7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformintegration.h>
9#ifndef QT_NO_CONTEXTMENU
10#include <qpa/qplatformtheme.h>
14#include <qpa/qplatformopenglcontext.h>
22#if QT_CONFIG(accessibility)
23# include "qaccessible.h"
24# include <private/qaccessiblecache_p.h>
27#if QT_CONFIG(draganddrop)
28#include "qshapedpixmapdndwindow_p.h"
31#include <private/qevent_p.h>
32#include <private/qeventpoint_p.h>
33#include <private/qguiapplication_p.h>
35#include <QtCore/QTimer>
36#include <QtCore/QDebug>
39#include <qpa/qplatformcursor.h>
40#include <qpa/qplatformwindow_p.h>
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
124
125
126
127
128
129
130QWindow::QWindow(QScreen *targetScreen)
131 : QObject(*
new QWindowPrivate(),
nullptr)
132 , QSurface(QSurface::Window)
135 d->init(
nullptr, targetScreen);
139
140
141
142
143
144
145
146
147
148QWindow::QWindow(QWindow *parent)
149 : QWindow(*
new QWindowPrivate(), parent)
154
155
156
157
158
159
160
161
162
163
164
165QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
166 : QObject(dd,
nullptr)
167 , QSurface(QSurface::Window)
174
175
180#if QT_CONFIG(accessibility)
181 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
182 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
188 qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly));
193 QGuiApplicationPrivate::window_list.removeAll(
this);
194 QGuiApplicationPrivate::popup_list.removeAll(
this);
195 if (!QGuiApplicationPrivate::is_app_closing)
196 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
201 if (QGuiApplicationPrivate::focus_window ==
this)
202 QGuiApplicationPrivate::focus_window =
nullptr;
203 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
204 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
205 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
206 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
211QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
212 : QObjectPrivate(version)
215QWindowPrivate::~QWindowPrivate()
218void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
222 q->QObject::setParent(parent);
225 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
227 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
230 connectToScreen(connectScreen);
234 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
235 qFatal(
"Cannot create window: no screens available");
237 QGuiApplicationPrivate::window_list.prepend(q);
239 requestedFormat = QSurfaceFormat::defaultFormat();
240 devicePixelRatio = connectScreen->devicePixelRatio();
242 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
247 if (
const auto *handle = q->handle()) {
248 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q,
249 QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q),
250 QHighDpi::fromNativePixels(handle->geometry(), q));
251 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
256 updateDevicePixelRatio();
260 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
261 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316QWindow::Visibility QWindow::visibility()
const
319 return d->visibility;
322void QWindow::setVisibility(Visibility v)
328 case AutomaticVisibility:
349
350
351
352
353
354void QWindowPrivate::setVisible(
bool visible)
358 if (
this->visible != visible) {
359 this->visible = visible;
360 emit q->visibleChanged(visible);
362 }
else if (platformWindow) {
367 if (!platformWindow) {
370 if (parentWindow && !parentWindow->handle())
386 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
388 if (q->type() == Qt::Window) {
389 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
390 QString &firstWindowTitle = app_priv->firstWindowTitle;
391 if (!firstWindowTitle.isEmpty()) {
392 q->setTitle(firstWindowTitle);
393 firstWindowTitle = QString();
395 if (!app_priv->forcedWindowIcon.isNull())
396 q->setIcon(app_priv->forcedWindowIcon);
399 static bool geometryApplied =
false;
400 if (!geometryApplied) {
401 geometryApplied =
true;
402 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
406 QShowEvent showEvent;
407 QGuiApplication::sendEvent(q, &showEvent);
412 QGuiApplicationPrivate::showModalWindow(q);
414 QGuiApplicationPrivate::hideModalWindow(q);
417 }
else if (visible && QGuiApplication::modalWindow()
418#if QT_CONFIG(draganddrop)
419 && !qobject_cast<QShapedPixmapWindow *>(q)
422 QGuiApplicationPrivate::updateBlockedStatus(q);
425 if (q->type() == Qt::Popup) {
427 QGuiApplicationPrivate::activatePopup(q);
429 QGuiApplicationPrivate::closePopup(q);
433 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
438 platformWindow->setVisible(visible);
441 QHideEvent hideEvent;
442 QGuiApplication::sendEvent(q, &hideEvent);
446void QWindowPrivate::updateVisibility()
450 QWindow::Visibility old = visibility;
453 visibility = QWindow::Hidden;
454 else if (windowState & Qt::WindowMinimized)
455 visibility = QWindow::Minimized;
456 else if (windowState & Qt::WindowFullScreen)
457 visibility = QWindow::FullScreen;
458 else if (windowState & Qt::WindowMaximized)
459 visibility = QWindow::Maximized;
461 visibility = QWindow::Windowed;
463 if (visibility != old)
464 emit q->visibilityChanged(visibility);
467void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
474 QObjectList &siblings = q->parent()->d_ptr->children;
476 const qsizetype siblingCount = siblings.size() - 1;
477 if (siblingCount == 0)
480 const qsizetype currentPosition = siblings.indexOf(q);
481 Q_ASSERT(currentPosition >= 0);
483 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
485 if (currentPosition == targetPosition)
488 siblings.move(currentPosition, targetPosition);
491bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
494 const QScreen *oldScreen = q->screen();
495 return oldScreen != newScreen && (platformWindow || !oldScreen)
496 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
499void QWindowPrivate::disconnectFromScreen()
502 topLevelScreen =
nullptr;
505void QWindowPrivate::connectToScreen(QScreen *screen)
507 disconnectFromScreen();
508 topLevelScreen = screen;
511void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
514 emit q->screenChanged(newScreen);
515 for (QObject *child : q->children()) {
516 if (child->isWindowType())
517 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
521void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
525 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
528 if (newScreen != topLevelScreen) {
529 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
530 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
531 if (shouldRecreate && platformWindow)
533 connectToScreen(newScreen);
536 else if (newScreen && shouldRecreate)
538 emitScreenChangedRecursion(newScreen);
544void QWindowPrivate::create(
bool recursive)
551 const bool needsUpdate = updateRequestPending;
553 updateRequestPending =
false;
556 q->parent()->create();
558 if (platformWindow) {
567 if (q->isTopLevel()) {
568 if (QScreen *screen = screenForGeometry(geometry))
569 setTopLevelScreen(screen,
false);
572 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
574 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
575 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
576 : platformIntegration->createPlatformWindow(q);
577 Q_ASSERT(platformWindow);
579 if (!platformWindow) {
580 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
584 platformWindow->initialize();
586 QObjectList childObjects = q->children();
587 for (
int i = 0; i < childObjects.size(); i ++) {
588 QObject *object = childObjects.at(i);
589 if (!object->isWindowType())
592 QWindow *childWindow =
static_cast<QWindow *>(object);
594 childWindow->d_func()->create(recursive);
599 if (childWindow->isVisible())
600 childWindow->setVisible(
true);
602 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
603 childPlatformWindow->setParent(
this->platformWindow);
606 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
607 QGuiApplication::sendEvent(q, &e);
609 updateDevicePixelRatio();
615void QWindowPrivate::clearFocusObject()
622QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
628void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
629 qxp::function_ref<
void()> funcWidthChanged,
630 qxp::function_ref<
void()> funcHeightChanged)
633 Q_ASSERT(oldSizeMember);
634 const QSize adjustedSize =
635 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
636 if (*oldSizeMember == adjustedSize)
638 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
639 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
640 *oldSizeMember = adjustedSize;
642 if (platformWindow && q->isTopLevel())
643 platformWindow->propagateSizeHints();
651 if (minimumSize.width() <= maximumSize.width()
652 || minimumSize.height() <= maximumSize.height()) {
653 const QSize currentSize = q->size();
654 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
655 q->resize(boundedSize);
660
661
662
663
664
665
666
667
668
669
670
671
672void QWindow::setSurfaceType(SurfaceType surfaceType)
675 d->surfaceType = surfaceType;
679
680
681
682
683QWindow::SurfaceType QWindow::surfaceType()
const
686 return d->surfaceType;
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707void QWindow::setVisible(
bool visible)
711 d->setVisible(visible);
714bool QWindow::isVisible()
const
722
723
724
725
726
727
728
729
730
731
732
733
734
735void QWindow::create()
742
743
744
745
746
747
748
749
750
751
752WId QWindow::winId()
const
756 if (!d->platformWindow)
757 const_cast<QWindow *>(
this)->create();
759 if (!d->platformWindow)
762 return d->platformWindow->winId();
766
767
768
769
770
771
772
773
774
775QWindow *QWindow::parent(AncestorMode mode)
const
778 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
782
783
784
785
786
787
788
789
790
791void QWindow::setParent(QWindow *parent)
794 if (d->parentWindow == parent
796 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
800 QScreen *oldScreen = screen();
801 QScreen *newScreen = parent ? parent->screen() : oldScreen;
802 if (d->windowRecreationRequired(newScreen)) {
803 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
807 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
808 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
810 const auto previousParent = d->parentWindow;
811 QObject::setParent(parent);
812 d->parentWindow = parent;
815 d->disconnectFromScreen();
817 d->connectToScreen(newScreen);
822 if (isVisible() && (!parent || parent->handle()))
825 if (d->platformWindow) {
829 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
832 QGuiApplicationPrivate::updateBlockedStatus(
this);
834 if (previousParent) {
835 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
836 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
840 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
841 QCoreApplication::sendEvent(parent, &childAddedEvent);
844 QEvent parentChangedEvent(QEvent::ParentWindowChange);
845 QCoreApplication::sendEvent(
this, &parentChangedEvent);
846#if QT_CONFIG(accessibility)
847 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
848 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
849 QAccessible::updateAccessibility(&qaEvent);
859 if (parent && screen() != oldScreen)
860 d->emitScreenChangedRecursion(screen());
864
865
866bool QWindow::isTopLevel()
const
869 return d->parentWindow ==
nullptr;
873
874
875
876
877
878
879bool QWindow::isModal()
const
882 return d->modality != Qt::NonModal;
886
887
888
889
890
891
892
893
894
896Qt::WindowModality QWindow::modality()
const
902void QWindow::setModality(Qt::WindowModality modality)
905 if (d->modality == modality)
907 d->modality = modality;
908 emit modalityChanged(modality);
912
913
914
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942void QWindow::setFormat(
const QSurfaceFormat &format)
945 d->requestedFormat = format;
949
950
951
952
953
954
955
956
957
958QSurfaceFormat QWindow::requestedFormat()
const
961 return d->requestedFormat;
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981QSurfaceFormat QWindow::format()
const
984 if (d->platformWindow)
985 return d->platformWindow->format();
986 return d->requestedFormat;
990
991
992
993
994
995
996
997
998
999
1000
1001
1002void QWindow::setFlags(Qt::WindowFlags flags)
1005 if (d->windowFlags == flags)
1008 if (d->platformWindow)
1009 d->platformWindow->setWindowFlags(flags);
1010 d->windowFlags = flags;
1012 emit flagsChanged(
this->flags());
1015Qt::WindowFlags QWindow::flags()
const
1018 Qt::WindowFlags flags = d->windowFlags;
1020 if (d->platformWindow && d->platformWindow->isForeignWindow())
1021 flags |= Qt::ForeignWindow;
1027
1028
1029
1030
1031
1032
1033
1034void QWindow::setFlag(Qt::WindowType flag,
bool on)
1038 setFlags(d->windowFlags | flag);
1040 setFlags(d->windowFlags & ~flag);
1044
1045
1046
1047
1048
1049
1050
1051Qt::WindowType QWindow::type()
const
1053 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067void QWindow::setTitle(
const QString &title)
1070 bool changed =
false;
1071 if (d->windowTitle != title) {
1072 d->windowTitle = title;
1075 if (d->platformWindow)
1076 d->platformWindow->setWindowTitle(title);
1078 emit windowTitleChanged(title);
1081QString QWindow::title()
const
1084 return d->windowTitle;
1088
1089
1090
1091
1092
1093
1094void QWindow::setFilePath(
const QString &filePath)
1097 d->windowFilePath = filePath;
1098 if (d->platformWindow)
1099 d->platformWindow->setWindowFilePath(filePath);
1103
1104
1105
1106
1107QString QWindow::filePath()
const
1110 return d->windowFilePath;
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124void QWindow::setIcon(
const QIcon &icon)
1127 d->windowIcon = icon;
1128 if (d->platformWindow)
1129 d->platformWindow->setWindowIcon(icon);
1130 QEvent e(QEvent::WindowIconChange);
1131 QCoreApplication::sendEvent(
this, &e);
1135
1136
1137
1138
1139QIcon QWindow::icon()
const
1142 if (d->windowIcon.isNull())
1143 return QGuiApplication::windowIcon();
1144 return d->windowIcon;
1148
1149
1150
1151
1152void QWindow::raise()
1156 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1158 if (d->platformWindow)
1159 d->platformWindow->raise();
1163
1164
1165
1166
1167void QWindow::lower()
1171 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1173 if (d->platformWindow)
1174 d->platformWindow->lower();
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195bool QWindow::startSystemResize(Qt::Edges edges)
1198 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1201 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1202 const bool isCorner =
1203 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1204 edges == (Qt::TopEdge | Qt::RightEdge) ||
1205 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1206 edges == (Qt::BottomEdge | Qt::LeftEdge);
1208 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1209 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1213 return d->platformWindow->startSystemResize(edges);
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233bool QWindow::startSystemMove()
1236 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1239 return d->platformWindow->startSystemMove();
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256void QWindow::setOpacity(qreal level)
1259 if (level == d->opacity)
1262 if (d->platformWindow) {
1263 d->platformWindow->setOpacity(level);
1264 emit opacityChanged(level);
1268qreal QWindow::opacity()
const
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284void QWindow::setMask(
const QRegion ®ion)
1287 if (d->platformWindow)
1288 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1293
1294
1295
1296
1297
1298QRegion QWindow::mask()
const
1305
1306
1307
1308
1309void QWindow::requestActivate()
1312 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1313 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1316 if (d->platformWindow)
1317 d->platformWindow->requestActivateWindow();
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331bool QWindow::isExposed()
const
1338
1339
1340
1341
1342
1343
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357bool QWindow::isActive()
const
1360 if (!d->platformWindow)
1363 QWindow *focus = QGuiApplication::focusWindow();
1372 if (QWindow *p = parent(IncludeTransients))
1373 return p->isActive();
1375 return isAncestorOf(focus);
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1400 if (d->contentOrientation == orientation)
1402 if (d->platformWindow)
1403 d->platformWindow->handleContentOrientationChange(orientation);
1404 d->contentOrientation = orientation;
1405 emit contentOrientationChanged(orientation);
1408Qt::ScreenOrientation QWindow::contentOrientation()
const
1411 return d->contentOrientation;
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429qreal QWindow::devicePixelRatio()
const
1432 return d->devicePixelRatio;
1436
1437
1438
1439
1440bool QWindowPrivate::updateDevicePixelRatio()
1444 const qreal newDevicePixelRatio = [
this, q]{
1446 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1451 if (
auto *screen = q->screen())
1452 return screen->devicePixelRatio();
1455 return qGuiApp->devicePixelRatio();
1458 if (newDevicePixelRatio == devicePixelRatio)
1461 devicePixelRatio = newDevicePixelRatio;
1462 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1463 QGuiApplication::sendEvent(q, &dprChangeEvent);
1467Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1469 if (state & Qt::WindowMinimized)
1470 return Qt::WindowMinimized;
1471 else if (state & Qt::WindowFullScreen)
1472 return Qt::WindowFullScreen;
1473 else if (state & Qt::WindowMaximized)
1474 return Qt::WindowMaximized;
1475 return Qt::WindowNoState;
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488void QWindow::setWindowState(Qt::WindowState state)
1490 setWindowStates(state);
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509void QWindow::setWindowStates(Qt::WindowStates state)
1512 if (state & Qt::WindowActive) {
1513 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1514 state &= ~Qt::WindowActive;
1517 if (d->platformWindow)
1518 d->platformWindow->setWindowState(state);
1520 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1521 d->windowState = state;
1522 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1523 if (newEffectiveState != originalEffectiveState)
1524 emit windowStateChanged(newEffectiveState);
1526 d->updateVisibility();
1530
1531
1532
1533
1534Qt::WindowState QWindow::windowState()
const
1537 return QWindowPrivate::effectiveState(d->windowState);
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551Qt::WindowStates QWindow::windowStates()
const
1554 return d->windowState;
1558
1559
1560
1561
1562
1563
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579void QWindow::setTransientParent(QWindow *parent)
1582 if (parent && !parent->isTopLevel()) {
1583 qWarning() << parent <<
"must be a top level window.";
1586 if (parent ==
this) {
1587 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1591 d->transientParent = parent;
1593 QGuiApplicationPrivate::updateBlockedStatus(
this);
1594 emit transientParentChanged(parent);
1597QWindow *QWindow::transientParent()
const
1600 return d->transientParent.data();
1604
1605
1606
1607
1608
1609void QWindowPrivate::setTransientParent(QWindow *parent)
1612 q->setTransientParent(parent);
1613 transientParentPropertySet =
true;
1617
1618
1619
1620
1621
1622
1623
1624
1627
1628
1629
1630bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1632 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1635 if (QWindow *parent = child->parent(mode)) {
1636 if (isAncestorOf(parent, mode))
1638 }
else if (handle() && child->handle()) {
1639 if (handle()->isAncestorOf(child->handle()))
1647
1648
1649
1650
1651QSize QWindow::minimumSize()
const
1654 return d->minimumSize;
1658
1659
1660
1661
1662QSize QWindow::maximumSize()
const
1665 return d->maximumSize;
1669
1670
1671
1672
1673QSize QWindow::baseSize()
const
1680
1681
1682
1683
1684QSize QWindow::sizeIncrement()
const
1687 return d->sizeIncrement;
1691
1692
1693
1694
1695
1696
1697void QWindow::setMinimumSize(
const QSize &size)
1701 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1702 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1706
1707
1708
1709void QWindow::setX(
int arg)
1713 setGeometry(QRect(arg, y(), width(), height()));
1715 d->positionAutomatic =
false;
1719
1720
1721
1722void QWindow::setY(
int arg)
1726 setGeometry(QRect(x(), arg, width(), height()));
1728 d->positionAutomatic =
false;
1732
1733
1734
1735void QWindow::setWidth(
int w)
1737 resize(w, height());
1741
1742
1743
1744void QWindow::setHeight(
int h)
1750
1751
1752
1753void QWindow::setMinimumWidth(
int w)
1755 setMinimumSize(QSize(w, minimumHeight()));
1759
1760
1761
1762void QWindow::setMinimumHeight(
int h)
1764 setMinimumSize(QSize(minimumWidth(), h));
1768
1769
1770
1771
1772
1773
1774void QWindow::setMaximumSize(
const QSize &size)
1778 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1779 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1783
1784
1785
1786void QWindow::setMaximumWidth(
int w)
1788 setMaximumSize(QSize(w, maximumHeight()));
1792
1793
1794
1795void QWindow::setMaximumHeight(
int h)
1797 setMaximumSize(QSize(maximumWidth(), h));
1801
1802
1803
1804
1805
1806
1807
1808void QWindow::setBaseSize(
const QSize &size)
1811 if (d->baseSize == size)
1814 if (d->platformWindow && isTopLevel())
1815 d->platformWindow->propagateSizeHints();
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832void QWindow::setSizeIncrement(
const QSize &size)
1835 if (d->sizeIncrement == size)
1837 d->sizeIncrement = size;
1838 if (d->platformWindow && isTopLevel())
1839 d->platformWindow->propagateSizeHints();
1843
1844
1845
1846
1847
1848
1849
1850void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1852 setGeometry(QRect(posx, posy, w, h));
1856
1857
1858
1859
1860
1861
1862void QWindow::setGeometry(
const QRect &rect)
1865 d->positionAutomatic =
false;
1866 const QRect oldRect = geometry();
1867 if (rect == oldRect)
1870 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1871 if (d->platformWindow) {
1879 QScreen *newScreen = d->screenForGeometry(rect);
1880 if (newScreen && isTopLevel())
1881 d->setTopLevelScreen(newScreen,
true);
1882 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1886 if (rect.x() != oldRect.x())
1887 emit xChanged(rect.x());
1888 if (rect.y() != oldRect.y())
1889 emit yChanged(rect.y());
1890 if (rect.width() != oldRect.width())
1891 emit widthChanged(rect.width());
1892 if (rect.height() != oldRect.height())
1893 emit heightChanged(rect.height());
1898
1899
1900
1901
1902
1903QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1906 QScreen *currentScreen = q->screen();
1907 QScreen *fallback = currentScreen;
1908 QPoint center = newGeometry.center();
1909 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1910 const auto screens = currentScreen->virtualSiblings();
1911 for (QScreen* screen : screens) {
1912 if (screen->geometry().contains(center))
1914 if (screen->geometry().intersects(newGeometry))
1923
1924
1925
1926
1927
1928
1929QRect QWindow::geometry()
const
1932 if (d->platformWindow) {
1933 const auto nativeGeometry = d->platformWindow->geometry();
1934 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1940
1941
1942
1943
1944QMargins QWindow::frameMargins()
const
1947 if (d->platformWindow)
1948 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1953
1954
1955
1956
1957
1958
1959QRect QWindow::frameGeometry()
const
1962 if (d->platformWindow) {
1963 QMargins m = frameMargins();
1964 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1970
1971
1972
1973
1974
1975
1976QPoint QWindow::framePosition()
const
1979 if (d->platformWindow) {
1980 QMargins margins = frameMargins();
1981 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1983 return d->geometry.topLeft();
1987
1988
1989
1990
1991
1992
1993void QWindow::setFramePosition(
const QPoint &point)
1996 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1997 d->positionAutomatic =
false;
1998 if (d->platformWindow) {
1999 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
2001 d->geometry.moveTopLeft(point);
2006
2007
2008
2009
2010
2011
2012
2013
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038QMargins QWindow::safeAreaMargins()
const
2041 if (d->platformWindow)
2042 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2047
2048
2049
2050
2051
2052
2053
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069void QWindow::setPosition(
const QPoint &pt)
2071 setGeometry(QRect(pt, size()));
2075
2076
2077
2078
2079
2080
2081void QWindow::setPosition(
int posx,
int posy)
2083 setPosition(QPoint(posx, posy));
2087
2088
2089
2090
2091
2092
2093
2094
2095
2098
2099
2100
2101
2102
2105
2106
2107
2108
2109
2110
2111
2112void QWindow::resize(
int w,
int h)
2114 resize(QSize(w, h));
2118
2119
2120
2121
2122void QWindow::resize(
const QSize &newSize)
2126 const QSize oldSize = size();
2127 if (newSize == oldSize)
2130 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2131 if (d->platformWindow) {
2132 d->platformWindow->setGeometry(
2133 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2135 d->geometry.setSize(newSize);
2136 if (newSize.width() != oldSize.width())
2137 emit widthChanged(newSize.width());
2138 if (newSize.height() != oldSize.height())
2139 emit heightChanged(newSize.height());
2144
2145
2146
2147
2148void QWindow::destroy()
2151 if (!d->platformWindow)
2154 if (d->platformWindow->isForeignWindow())
2160void QWindowPrivate::destroy()
2162 if (!platformWindow)
2166 QObjectList childrenWindows = q->children();
2167 for (
int i = 0; i < childrenWindows.size(); i++) {
2168 QObject *object = childrenWindows.at(i);
2169 if (object->isWindowType()) {
2170 QWindow *w =
static_cast<QWindow*>(object);
2171 qt_window_private(w)->destroy();
2175 bool wasVisible = q->isVisible();
2176 visibilityOnDestroy = wasVisible && platformWindow;
2178 q->setVisible(
false);
2189 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2190 QGuiApplication::sendEvent(q, &e);
2195 delete std::exchange(platformWindow,
nullptr);
2197 if (QGuiApplicationPrivate::focus_window == q)
2198 QGuiApplicationPrivate::focus_window = q->parent();
2199 if (QGuiApplicationPrivate::currentMouseWindow == q)
2200 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2201 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2202 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2204 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2205 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2206 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2208 resizeEventPending =
true;
2209 receivedExpose =
false;
2215 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2219
2220
2221
2222
2223QPlatformWindow *QWindow::handle()
const
2226 return d->platformWindow;
2230
2231
2232
2233
2234QPlatformSurface *QWindow::surfaceHandle()
const
2237 return d->platformWindow;
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250bool QWindow::setKeyboardGrabEnabled(
bool grab)
2253 if (d->platformWindow)
2254 return d->platformWindow->setKeyboardGrabEnabled(grab);
2259
2260
2261
2262
2263
2264
2265
2266
2267bool QWindow::setMouseGrabEnabled(
bool grab)
2270 if (d->platformWindow)
2271 return d->platformWindow->setMouseGrabEnabled(grab);
2276
2277
2278
2279
2280
2281
2282QScreen *QWindow::screen()
const
2285 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301void QWindow::setScreen(QScreen *newScreen)
2305 newScreen = QGuiApplication::primaryScreen();
2306 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2310
2311
2312
2313
2314
2315
2318
2319
2320
2321
2322QAccessibleInterface *QWindow::accessibleRoot()
const
2328
2329
2330
2331
2332
2333
2334
2337
2338
2339
2340QObject *QWindow::focusObject()
const
2342 return const_cast<QWindow *>(
this);
2346
2347
2348
2349
2350
2351
2352
2353
2359 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2360 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2361 if (defaultState == Qt::WindowFullScreen)
2363 else if (defaultState == Qt::WindowMaximized)
2371
2372
2373
2374
2375
2376
2383
2384
2385
2386
2387
2388
2389
2390void QWindow::showMinimized()
2392 setWindowStates(Qt::WindowMinimized);
2397
2398
2399
2400
2401
2402
2403
2404void QWindow::showMaximized()
2406 setWindowStates(Qt::WindowMaximized);
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421void QWindow::showFullScreen()
2423 setWindowStates(Qt::WindowFullScreen);
2425#if !defined Q_OS_QNX
2432
2433
2434
2435
2436
2437
2438
2439void QWindow::showNormal()
2441 setWindowStates(Qt::WindowNoState);
2446
2447
2448
2449
2450
2451
2452
2453
2454bool QWindow::close()
2464 if (!d->platformWindow) {
2467 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2468 QGuiApplicationPrivate::closePopup(
this);
2474 QPointer guard(
this);
2476 bool success = d->platformWindow->close();
2483bool QWindowPrivate::participatesInLastWindowClosed()
const
2487 if (!q->isTopLevel())
2493 if (q->type() == Qt::ToolTip)
2498 if (q->transientParent())
2504bool QWindowPrivate::treatAsVisible()
const
2507 return q->isVisible();
2511
2512
2513
2514const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2517 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2518 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2519 QWindow *ret =
nullptr;
2520 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2521 if (q == popupWindow)
2523 if (event->isPointerEvent()) {
2525 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2526 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2527 QEventPoint &eventPoint = pointerEvent->point(i);
2528 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2529 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2530 QMutableEventPoint::setPosition(eventPoint, mapped);
2531 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2535
2536
2537 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2538 event->setAccepted(pointerEvent->isAccepted());
2539 if (pointerEvent->isAccepted())
2542 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2543 <<
"handled?" << (ret !=
nullptr)
2544 <<
"accepted?" << event->isAccepted();
2546 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2547 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2549 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2550 <<
"handled?" << (ret !=
nullptr)
2551 <<
"accepted?" << event->isAccepted();
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576void QWindow::exposeEvent(QExposeEvent *ev)
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595void QWindow::paintEvent(QPaintEvent *ev)
2601
2602
2603void QWindow::moveEvent(QMoveEvent *ev)
2609
2610
2611
2612
2613
2614
2615void QWindow::resizeEvent(QResizeEvent *ev)
2621
2622
2623
2624
2625
2626
2627
2628void QWindow::showEvent(QShowEvent *ev)
2634
2635
2636
2637
2638
2639void QWindow::hideEvent(QHideEvent *ev)
2645
2646
2647
2648
2649
2650
2651
2652void QWindow::closeEvent(QCloseEvent *ev)
2658
2659
2660
2661
2662
2663
2664bool QWindow::event(QEvent *ev)
2667 switch (ev->type()) {
2668 case QEvent::MouseMove:
2669 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2672 case QEvent::MouseButtonPress: {
2673 auto *me =
static_cast<QMouseEvent*>(ev);
2674 mousePressEvent(me);
2675 if (!ev->isAccepted())
2676 d->maybeSynthesizeContextMenuEvent(me);
2680 case QEvent::MouseButtonRelease: {
2681 auto *me =
static_cast<QMouseEvent*>(ev);
2682 mouseReleaseEvent(me);
2683 if (!ev->isAccepted())
2684 d->maybeSynthesizeContextMenuEvent(me);
2688 case QEvent::MouseButtonDblClick:
2689 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2692 case QEvent::TouchBegin:
2693 case QEvent::TouchUpdate:
2694 case QEvent::TouchEnd:
2695 case QEvent::TouchCancel:
2696 touchEvent(
static_cast<QTouchEvent *>(ev));
2700 moveEvent(
static_cast<QMoveEvent*>(ev));
2703 case QEvent::Resize:
2704 resizeEvent(
static_cast<QResizeEvent*>(ev));
2707 case QEvent::KeyPress:
2708 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2711 case QEvent::KeyRelease:
2712 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2715 case QEvent::FocusIn: {
2716 focusInEvent(
static_cast<QFocusEvent *>(ev));
2717#if QT_CONFIG(accessibility)
2718 QAccessible::State state;
2719 state.active =
true;
2720 QAccessibleStateChangeEvent event(
this, state);
2721 QAccessible::updateAccessibility(&event);
2725 case QEvent::FocusOut: {
2726 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2727#if QT_CONFIG(accessibility)
2728 QAccessible::State state;
2729 state.active =
true;
2730 QAccessibleStateChangeEvent event(
this, state);
2731 QAccessible::updateAccessibility(&event);
2735#if QT_CONFIG(wheelevent)
2737 wheelEvent(
static_cast<QWheelEvent*>(ev));
2741 case QEvent::Close: {
2743 const bool wasVisible = d->treatAsVisible();
2744 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2747 QPointer<QWindow> deletionGuard(
this);
2748 closeEvent(
static_cast<QCloseEvent*>(ev));
2750 if (ev->isAccepted()) {
2753 if (wasVisible && participatesInLastWindowClosed)
2754 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2760 case QEvent::Expose:
2761 exposeEvent(
static_cast<QExposeEvent *>(ev));
2765 paintEvent(
static_cast<QPaintEvent *>(ev));
2769 showEvent(
static_cast<QShowEvent *>(ev));
2773 hideEvent(
static_cast<QHideEvent *>(ev));
2776 case QEvent::ApplicationWindowIconChange:
2780#if QT_CONFIG(tabletevent)
2781 case QEvent::TabletPress:
2782 case QEvent::TabletMove:
2783 case QEvent::TabletRelease:
2784 tabletEvent(
static_cast<QTabletEvent *>(ev));
2788 case QEvent::PlatformSurface: {
2789 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2791 QOpenGLContext *context = QOpenGLContext::currentContext();
2792 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2793 context->doneCurrent();
2800 return QObject::event(ev);
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2846#ifndef QT_NO_CONTEXTMENU
2847 if (event->button() == Qt::RightButton
2848 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2849 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2850 event->globalPosition().toPoint(), event->modifiers());
2851 qCDebug(lcPopup) <<
"synthesized after"
2852 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2853 << event->type() <<
":" << &e;
2854 QCoreApplication::forwardEvent(q_func(), &e, event);
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888void QWindow::requestUpdate()
2890 Q_ASSERT_X(QThread::isMainThread(),
2891 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2894 if (d->updateRequestPending || !d->platformWindow)
2896 d->updateRequestPending =
true;
2897 d->platformWindow->requestUpdate();
2901
2902
2903
2904
2905void QWindow::keyPressEvent(QKeyEvent *ev)
2911
2912
2913
2914
2915void QWindow::keyReleaseEvent(QKeyEvent *ev)
2921
2922
2923
2924
2925
2926
2927void QWindow::focusInEvent(QFocusEvent *ev)
2933
2934
2935
2936
2937
2938
2939void QWindow::focusOutEvent(QFocusEvent *ev)
2945
2946
2947
2948
2949void QWindow::mousePressEvent(QMouseEvent *ev)
2955
2956
2957
2958
2959void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2965
2966
2967
2968
2969void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2975
2976
2977void QWindow::mouseMoveEvent(QMouseEvent *ev)
2982#if QT_CONFIG(wheelevent)
2984
2985
2986void QWindow::wheelEvent(QWheelEvent *ev)
2993
2994
2995void QWindow::touchEvent(QTouchEvent *ev)
3000#if QT_CONFIG(tabletevent)
3002
3003
3004
3005
3006
3007void QWindow::tabletEvent(QTabletEvent *ev)
3014
3015
3016
3017
3018
3019
3020
3022bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3024 Q_UNUSED(eventType);
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3044 if (d->platformWindow
3045 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3046 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3049 if (!QHighDpiScaling::isActive())
3050 return pos + d->globalPosition();
3058 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3062 QPointF nativeWindowGlobalPos = d->platformWindow
3063 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3064 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3065 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3066 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3067 return deviceIndependentGlobalPos;
3071
3072
3073QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3075 return mapToGlobal(QPointF(pos)).toPoint();
3079
3080
3081
3082
3083
3084
3085
3086
3087QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3091 if (d->platformWindow
3092 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3093 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3096 if (!QHighDpiScaling::isActive())
3097 return pos - d->globalPosition();
3101 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3105 QPointF nativeWindowGlobalPos = d->platformWindow
3106 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3107 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3108 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3109 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3110 return deviceIndependentLocalPos;
3114
3115
3116QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3118 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3121QPoint QWindowPrivate::globalPosition()
const
3124 QPoint offset = q->position();
3125 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3126 QPlatformWindow *pw = p->handle();
3127 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3129 offset += p->mapToGlobal(QPoint(0, 0));
3132 offset += p->position();
3140 return window->d_func();
3143QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3147 QWindow *window =
const_cast<QWindow *>(q);
3150 QWindow *parent = window->parent(mode);
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181QWindow *QWindow::fromWinId(WId id)
3183 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3184 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3188 QWindow *window =
new QWindow;
3192 window->setProperty(kForeignWindowId, id);
3195 if (!window->handle()) {
3204
3205
3206
3207
3208
3209
3210
3211
3212
3214void QWindow::alert(
int msec)
3217 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3219 d->platformWindow->setAlertState(
true);
3220 if (d->platformWindow->isAlertState() && msec)
3221 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3224void QWindowPrivate::_q_clearAlert()
3226 if (platformWindow && platformWindow->isAlertState())
3227 platformWindow->setAlertState(
false);
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251void QWindow::setCursor(
const QCursor &cursor)
3254 d->setCursor(&cursor);
3258
3259
3260void QWindow::unsetCursor()
3263 d->setCursor(
nullptr);
3267
3268
3269
3270
3271QCursor QWindow::cursor()
const
3277void QWindowPrivate::setCursor(
const QCursor *newCursor)
3282 const Qt::CursorShape newShape = newCursor->shape();
3283 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3285 cursor = *newCursor;
3290 cursor = QCursor(Qt::ArrowCursor);
3294 if (applyCursor()) {
3295 QEvent event(QEvent::CursorChange);
3296 QGuiApplication::sendEvent(q, &event);
3301bool QWindowPrivate::applyCursor()
3304 if (QScreen *screen = q->screen()) {
3305 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3306 if (!platformWindow)
3308 QCursor *c = QGuiApplication::overrideCursor();
3309 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3311 if (!c && hasCursor)
3313 platformCursor->changeCursor(c, q);
3321void *QWindow::resolveInterface(
const char *name,
int revision)
const
3323 using namespace QNativeInterface::Private;
3325 auto *platformWindow = handle();
3326 Q_UNUSED(platformWindow);
3330#if defined(Q_OS_WIN)
3331 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3335 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3338#if defined(Q_OS_MACOS)
3339 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3342#if QT_CONFIG(wayland)
3343 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3346#if defined(Q_OS_WASM)
3347 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3353#ifndef QT_NO_DEBUG_STREAM
3354QDebug operator<<(QDebug debug,
const QWindow *window)
3356 QDebugStateSaver saver(debug);
3359 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3360 if (!window->objectName().isEmpty())
3361 debug <<
", name=" << window->objectName();
3362 if (debug.verbosity() > 2) {
3363 const QRect geometry = window->geometry();
3364 if (window->isVisible())
3365 debug <<
", visible";
3366 if (window->isExposed())
3367 debug <<
", exposed";
3368 debug <<
", state=" << window->windowState()
3369 <<
", type=" << window->type() <<
", flags=" << window->flags()
3370 <<
", surface type=" << window->surfaceType();
3371 if (window->isTopLevel())
3372 debug <<
", toplevel";
3373 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3374 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3375 const QMargins margins = window->frameMargins();
3376 if (!margins.isNull())
3377 debug <<
", margins=" << margins;
3378 const QMargins safeAreaMargins = window->safeAreaMargins();
3379 if (!safeAreaMargins.isNull())
3380 debug <<
", safeAreaMargins=" << safeAreaMargins;
3381 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3382 if (
const QPlatformWindow *platformWindow = window->handle())
3383 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3384 if (
const QScreen *screen = window->screen())
3385 debug <<
", on " << screen->name();
3389 debug <<
"QWindow(0x0)";
3395#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3398
3399
3400
3401
3402void QWindow::setVulkanInstance(QVulkanInstance *instance)
3405 d->vulkanInstance = instance;
3409
3410
3411QVulkanInstance *QWindow::vulkanInstance()
const
3414 return d->vulkanInstance;
3421#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId