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 *newScreen = parent ? parent->screen() : screen();
801 if (d->windowRecreationRequired(newScreen)) {
802 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << screen() << newScreen <<
')';
806 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
807 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
809 const auto previousParent = d->parentWindow;
810 QObject::setParent(parent);
811 d->parentWindow = parent;
814 d->disconnectFromScreen();
816 d->connectToScreen(newScreen);
821 if (isVisible() && (!parent || parent->handle()))
824 if (d->platformWindow) {
828 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
831 QGuiApplicationPrivate::updateBlockedStatus(
this);
833 if (previousParent) {
834 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
835 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
839 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
840 QCoreApplication::sendEvent(parent, &childAddedEvent);
843 QEvent parentChangedEvent(QEvent::ParentWindowChange);
844 QCoreApplication::sendEvent(
this, &parentChangedEvent);
845#if QT_CONFIG(accessibility)
846 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
847 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
848 QAccessible::updateAccessibility(&qaEvent);
854
855
856bool QWindow::isTopLevel()
const
859 return d->parentWindow ==
nullptr;
863
864
865
866
867
868
869bool QWindow::isModal()
const
872 return d->modality != Qt::NonModal;
876
877
878
879
880
881
882
883
884
886Qt::WindowModality QWindow::modality()
const
892void QWindow::setModality(Qt::WindowModality modality)
895 if (d->modality == modality)
897 d->modality = modality;
898 emit modalityChanged(modality);
902
903
904
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932void QWindow::setFormat(
const QSurfaceFormat &format)
935 d->requestedFormat = format;
939
940
941
942
943
944
945
946
947
948QSurfaceFormat QWindow::requestedFormat()
const
951 return d->requestedFormat;
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971QSurfaceFormat QWindow::format()
const
974 if (d->platformWindow)
975 return d->platformWindow->format();
976 return d->requestedFormat;
980
981
982
983
984
985
986
987
988
989
990
991
992void QWindow::setFlags(Qt::WindowFlags flags)
995 if (d->windowFlags == flags)
998 if (d->platformWindow)
999 d->platformWindow->setWindowFlags(flags);
1000 d->windowFlags = flags;
1002 emit flagsChanged(
this->flags());
1005Qt::WindowFlags QWindow::flags()
const
1008 Qt::WindowFlags flags = d->windowFlags;
1010 if (d->platformWindow && d->platformWindow->isForeignWindow())
1011 flags |= Qt::ForeignWindow;
1017
1018
1019
1020
1021
1022
1023
1024void QWindow::setFlag(Qt::WindowType flag,
bool on)
1028 setFlags(d->windowFlags | flag);
1030 setFlags(d->windowFlags & ~flag);
1034
1035
1036
1037
1038
1039
1040
1041Qt::WindowType QWindow::type()
const
1043 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057void QWindow::setTitle(
const QString &title)
1060 bool changed =
false;
1061 if (d->windowTitle != title) {
1062 d->windowTitle = title;
1065 if (d->platformWindow)
1066 d->platformWindow->setWindowTitle(title);
1068 emit windowTitleChanged(title);
1071QString QWindow::title()
const
1074 return d->windowTitle;
1078
1079
1080
1081
1082
1083
1084void QWindow::setFilePath(
const QString &filePath)
1087 d->windowFilePath = filePath;
1088 if (d->platformWindow)
1089 d->platformWindow->setWindowFilePath(filePath);
1093
1094
1095
1096
1097QString QWindow::filePath()
const
1100 return d->windowFilePath;
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114void QWindow::setIcon(
const QIcon &icon)
1117 d->windowIcon = icon;
1118 if (d->platformWindow)
1119 d->platformWindow->setWindowIcon(icon);
1120 QEvent e(QEvent::WindowIconChange);
1121 QCoreApplication::sendEvent(
this, &e);
1125
1126
1127
1128
1129QIcon QWindow::icon()
const
1132 if (d->windowIcon.isNull())
1133 return QGuiApplication::windowIcon();
1134 return d->windowIcon;
1138
1139
1140
1141
1142void QWindow::raise()
1146 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1148 if (d->platformWindow)
1149 d->platformWindow->raise();
1153
1154
1155
1156
1157void QWindow::lower()
1161 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1163 if (d->platformWindow)
1164 d->platformWindow->lower();
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185bool QWindow::startSystemResize(Qt::Edges edges)
1188 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1191 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1192 const bool isCorner =
1193 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1194 edges == (Qt::TopEdge | Qt::RightEdge) ||
1195 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1196 edges == (Qt::BottomEdge | Qt::LeftEdge);
1198 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1199 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1203 return d->platformWindow->startSystemResize(edges);
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223bool QWindow::startSystemMove()
1226 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1229 return d->platformWindow->startSystemMove();
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246void QWindow::setOpacity(qreal level)
1249 if (level == d->opacity)
1252 if (d->platformWindow) {
1253 d->platformWindow->setOpacity(level);
1254 emit opacityChanged(level);
1258qreal QWindow::opacity()
const
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274void QWindow::setMask(
const QRegion ®ion)
1277 if (d->platformWindow)
1278 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1283
1284
1285
1286
1287
1288QRegion QWindow::mask()
const
1295
1296
1297
1298
1299void QWindow::requestActivate()
1302 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1303 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1306 if (d->platformWindow)
1307 d->platformWindow->requestActivateWindow();
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321bool QWindow::isExposed()
const
1328
1329
1330
1331
1332
1333
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347bool QWindow::isActive()
const
1350 if (!d->platformWindow)
1353 QWindow *focus = QGuiApplication::focusWindow();
1362 if (QWindow *p = parent(IncludeTransients))
1363 return p->isActive();
1365 return isAncestorOf(focus);
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1390 if (d->contentOrientation == orientation)
1392 if (d->platformWindow)
1393 d->platformWindow->handleContentOrientationChange(orientation);
1394 d->contentOrientation = orientation;
1395 emit contentOrientationChanged(orientation);
1398Qt::ScreenOrientation QWindow::contentOrientation()
const
1401 return d->contentOrientation;
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419qreal QWindow::devicePixelRatio()
const
1422 return d->devicePixelRatio;
1426
1427
1428
1429
1430bool QWindowPrivate::updateDevicePixelRatio()
1434 const qreal newDevicePixelRatio = [
this, q]{
1436 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1441 if (
auto *screen = q->screen())
1442 return screen->devicePixelRatio();
1445 return qGuiApp->devicePixelRatio();
1448 if (newDevicePixelRatio == devicePixelRatio)
1451 devicePixelRatio = newDevicePixelRatio;
1452 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1453 QGuiApplication::sendEvent(q, &dprChangeEvent);
1457Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1459 if (state & Qt::WindowMinimized)
1460 return Qt::WindowMinimized;
1461 else if (state & Qt::WindowFullScreen)
1462 return Qt::WindowFullScreen;
1463 else if (state & Qt::WindowMaximized)
1464 return Qt::WindowMaximized;
1465 return Qt::WindowNoState;
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478void QWindow::setWindowState(Qt::WindowState state)
1480 setWindowStates(state);
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499void QWindow::setWindowStates(Qt::WindowStates state)
1502 if (state & Qt::WindowActive) {
1503 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1504 state &= ~Qt::WindowActive;
1507 if (d->platformWindow)
1508 d->platformWindow->setWindowState(state);
1510 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1511 d->windowState = state;
1512 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1513 if (newEffectiveState != originalEffectiveState)
1514 emit windowStateChanged(newEffectiveState);
1516 d->updateVisibility();
1520
1521
1522
1523
1524Qt::WindowState QWindow::windowState()
const
1527 return QWindowPrivate::effectiveState(d->windowState);
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541Qt::WindowStates QWindow::windowStates()
const
1544 return d->windowState;
1548
1549
1550
1551
1552
1553
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569void QWindow::setTransientParent(QWindow *parent)
1572 if (parent && !parent->isTopLevel()) {
1573 qWarning() << parent <<
"must be a top level window.";
1576 if (parent ==
this) {
1577 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1581 d->transientParent = parent;
1583 QGuiApplicationPrivate::updateBlockedStatus(
this);
1584 emit transientParentChanged(parent);
1587QWindow *QWindow::transientParent()
const
1590 return d->transientParent.data();
1594
1595
1596
1597
1598
1599void QWindowPrivate::setTransientParent(QWindow *parent)
1602 q->setTransientParent(parent);
1603 transientParentPropertySet =
true;
1607
1608
1609
1610
1611
1612
1613
1614
1617
1618
1619
1620bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1622 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1625 if (QWindow *parent = child->parent(mode)) {
1626 if (isAncestorOf(parent, mode))
1628 }
else if (handle() && child->handle()) {
1629 if (handle()->isAncestorOf(child->handle()))
1637
1638
1639
1640
1641QSize QWindow::minimumSize()
const
1644 return d->minimumSize;
1648
1649
1650
1651
1652QSize QWindow::maximumSize()
const
1655 return d->maximumSize;
1659
1660
1661
1662
1663QSize QWindow::baseSize()
const
1670
1671
1672
1673
1674QSize QWindow::sizeIncrement()
const
1677 return d->sizeIncrement;
1681
1682
1683
1684
1685
1686
1687void QWindow::setMinimumSize(
const QSize &size)
1691 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1692 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1696
1697
1698
1699void QWindow::setX(
int arg)
1703 setGeometry(QRect(arg, y(), width(), height()));
1705 d->positionAutomatic =
false;
1709
1710
1711
1712void QWindow::setY(
int arg)
1716 setGeometry(QRect(x(), arg, width(), height()));
1718 d->positionAutomatic =
false;
1722
1723
1724
1725void QWindow::setWidth(
int w)
1727 resize(w, height());
1731
1732
1733
1734void QWindow::setHeight(
int h)
1740
1741
1742
1743void QWindow::setMinimumWidth(
int w)
1745 setMinimumSize(QSize(w, minimumHeight()));
1749
1750
1751
1752void QWindow::setMinimumHeight(
int h)
1754 setMinimumSize(QSize(minimumWidth(), h));
1758
1759
1760
1761
1762
1763
1764void QWindow::setMaximumSize(
const QSize &size)
1768 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1769 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1773
1774
1775
1776void QWindow::setMaximumWidth(
int w)
1778 setMaximumSize(QSize(w, maximumHeight()));
1782
1783
1784
1785void QWindow::setMaximumHeight(
int h)
1787 setMaximumSize(QSize(maximumWidth(), h));
1791
1792
1793
1794
1795
1796
1797
1798void QWindow::setBaseSize(
const QSize &size)
1801 if (d->baseSize == size)
1804 if (d->platformWindow && isTopLevel())
1805 d->platformWindow->propagateSizeHints();
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822void QWindow::setSizeIncrement(
const QSize &size)
1825 if (d->sizeIncrement == size)
1827 d->sizeIncrement = size;
1828 if (d->platformWindow && isTopLevel())
1829 d->platformWindow->propagateSizeHints();
1833
1834
1835
1836
1837
1838
1839
1840void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1842 setGeometry(QRect(posx, posy, w, h));
1846
1847
1848
1849
1850
1851
1852void QWindow::setGeometry(
const QRect &rect)
1855 d->positionAutomatic =
false;
1856 const QRect oldRect = geometry();
1857 if (rect == oldRect)
1860 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1861 if (d->platformWindow) {
1869 QScreen *newScreen = d->screenForGeometry(rect);
1870 if (newScreen && isTopLevel())
1871 d->setTopLevelScreen(newScreen,
true);
1872 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1876 if (rect.x() != oldRect.x())
1877 emit xChanged(rect.x());
1878 if (rect.y() != oldRect.y())
1879 emit yChanged(rect.y());
1880 if (rect.width() != oldRect.width())
1881 emit widthChanged(rect.width());
1882 if (rect.height() != oldRect.height())
1883 emit heightChanged(rect.height());
1888
1889
1890
1891
1892
1893QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1896 QScreen *currentScreen = q->screen();
1897 QScreen *fallback = currentScreen;
1898 QPoint center = newGeometry.center();
1899 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1900 const auto screens = currentScreen->virtualSiblings();
1901 for (QScreen* screen : screens) {
1902 if (screen->geometry().contains(center))
1904 if (screen->geometry().intersects(newGeometry))
1913
1914
1915
1916
1917
1918
1919QRect QWindow::geometry()
const
1922 if (d->platformWindow) {
1923 const auto nativeGeometry = d->platformWindow->geometry();
1924 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1930
1931
1932
1933
1934QMargins QWindow::frameMargins()
const
1937 if (d->platformWindow)
1938 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1943
1944
1945
1946
1947
1948
1949QRect QWindow::frameGeometry()
const
1952 if (d->platformWindow) {
1953 QMargins m = frameMargins();
1954 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1960
1961
1962
1963
1964
1965
1966QPoint QWindow::framePosition()
const
1969 if (d->platformWindow) {
1970 QMargins margins = frameMargins();
1971 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1973 return d->geometry.topLeft();
1977
1978
1979
1980
1981
1982
1983void QWindow::setFramePosition(
const QPoint &point)
1986 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1987 d->positionAutomatic =
false;
1988 if (d->platformWindow) {
1989 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
1991 d->geometry.moveTopLeft(point);
1996
1997
1998
1999
2000
2001
2002
2003
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028QMargins QWindow::safeAreaMargins()
const
2031 if (d->platformWindow)
2032 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2037
2038
2039
2040
2041
2042
2043
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059void QWindow::setPosition(
const QPoint &pt)
2061 setGeometry(QRect(pt, size()));
2065
2066
2067
2068
2069
2070
2071void QWindow::setPosition(
int posx,
int posy)
2073 setPosition(QPoint(posx, posy));
2077
2078
2079
2080
2081
2082
2083
2084
2085
2088
2089
2090
2091
2092
2095
2096
2097
2098
2099
2100
2101
2102void QWindow::resize(
int w,
int h)
2104 resize(QSize(w, h));
2108
2109
2110
2111
2112void QWindow::resize(
const QSize &newSize)
2116 const QSize oldSize = size();
2117 if (newSize == oldSize)
2120 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2121 if (d->platformWindow) {
2122 d->platformWindow->setGeometry(
2123 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2125 d->geometry.setSize(newSize);
2126 if (newSize.width() != oldSize.width())
2127 emit widthChanged(newSize.width());
2128 if (newSize.height() != oldSize.height())
2129 emit heightChanged(newSize.height());
2134
2135
2136
2137
2138void QWindow::destroy()
2141 if (!d->platformWindow)
2144 if (d->platformWindow->isForeignWindow())
2150void QWindowPrivate::destroy()
2152 if (!platformWindow)
2156 QObjectList childrenWindows = q->children();
2157 for (
int i = 0; i < childrenWindows.size(); i++) {
2158 QObject *object = childrenWindows.at(i);
2159 if (object->isWindowType()) {
2160 QWindow *w =
static_cast<QWindow*>(object);
2161 qt_window_private(w)->destroy();
2165 bool wasVisible = q->isVisible();
2166 visibilityOnDestroy = wasVisible && platformWindow;
2168 q->setVisible(
false);
2179 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2180 QGuiApplication::sendEvent(q, &e);
2185 delete std::exchange(platformWindow,
nullptr);
2187 if (QGuiApplicationPrivate::focus_window == q)
2188 QGuiApplicationPrivate::focus_window = q->parent();
2189 if (QGuiApplicationPrivate::currentMouseWindow == q)
2190 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2191 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2192 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2194 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2195 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2196 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2198 resizeEventPending =
true;
2199 receivedExpose =
false;
2205 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2209
2210
2211
2212
2213QPlatformWindow *QWindow::handle()
const
2216 return d->platformWindow;
2220
2221
2222
2223
2224QPlatformSurface *QWindow::surfaceHandle()
const
2227 return d->platformWindow;
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240bool QWindow::setKeyboardGrabEnabled(
bool grab)
2243 if (d->platformWindow)
2244 return d->platformWindow->setKeyboardGrabEnabled(grab);
2249
2250
2251
2252
2253
2254
2255
2256
2257bool QWindow::setMouseGrabEnabled(
bool grab)
2260 if (d->platformWindow)
2261 return d->platformWindow->setMouseGrabEnabled(grab);
2266
2267
2268
2269
2270
2271
2272QScreen *QWindow::screen()
const
2275 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291void QWindow::setScreen(QScreen *newScreen)
2295 newScreen = QGuiApplication::primaryScreen();
2296 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2300
2301
2302
2303
2304
2305
2308
2309
2310
2311
2312QAccessibleInterface *QWindow::accessibleRoot()
const
2318
2319
2320
2321
2322
2323
2324
2327
2328
2329
2330QObject *QWindow::focusObject()
const
2332 return const_cast<QWindow *>(
this);
2336
2337
2338
2339
2340
2341
2342
2343
2349 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2350 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2351 if (defaultState == Qt::WindowFullScreen)
2353 else if (defaultState == Qt::WindowMaximized)
2361
2362
2363
2364
2365
2366
2373
2374
2375
2376
2377
2378
2379
2380void QWindow::showMinimized()
2382 setWindowStates(Qt::WindowMinimized);
2387
2388
2389
2390
2391
2392
2393
2394void QWindow::showMaximized()
2396 setWindowStates(Qt::WindowMaximized);
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411void QWindow::showFullScreen()
2413 setWindowStates(Qt::WindowFullScreen);
2415#if !defined Q_OS_QNX
2422
2423
2424
2425
2426
2427
2428
2429void QWindow::showNormal()
2431 setWindowStates(Qt::WindowNoState);
2436
2437
2438
2439
2440
2441
2442
2443
2444bool QWindow::close()
2454 if (!d->platformWindow) {
2457 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2458 QGuiApplicationPrivate::closePopup(
this);
2464 QPointer guard(
this);
2466 bool success = d->platformWindow->close();
2473bool QWindowPrivate::participatesInLastWindowClosed()
const
2477 if (!q->isTopLevel())
2483 if (q->type() == Qt::ToolTip)
2488 if (q->transientParent())
2494bool QWindowPrivate::treatAsVisible()
const
2497 return q->isVisible();
2501
2502
2503
2504const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2507 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2508 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2509 QWindow *ret =
nullptr;
2510 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2511 if (q == popupWindow)
2513 if (event->isPointerEvent()) {
2515 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2516 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2517 QEventPoint &eventPoint = pointerEvent->point(i);
2518 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2519 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2520 QMutableEventPoint::setPosition(eventPoint, mapped);
2521 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2525
2526
2527 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2528 event->setAccepted(pointerEvent->isAccepted());
2529 if (pointerEvent->isAccepted())
2532 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2533 <<
"handled?" << (ret !=
nullptr)
2534 <<
"accepted?" << event->isAccepted();
2536 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2537 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2539 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2540 <<
"handled?" << (ret !=
nullptr)
2541 <<
"accepted?" << event->isAccepted();
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566void QWindow::exposeEvent(QExposeEvent *ev)
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585void QWindow::paintEvent(QPaintEvent *ev)
2591
2592
2593void QWindow::moveEvent(QMoveEvent *ev)
2599
2600
2601
2602
2603
2604
2605void QWindow::resizeEvent(QResizeEvent *ev)
2611
2612
2613
2614
2615
2616
2617
2618void QWindow::showEvent(QShowEvent *ev)
2624
2625
2626
2627
2628
2629void QWindow::hideEvent(QHideEvent *ev)
2635
2636
2637
2638
2639
2640
2641
2642void QWindow::closeEvent(QCloseEvent *ev)
2648
2649
2650
2651
2652
2653
2654bool QWindow::event(QEvent *ev)
2657 switch (ev->type()) {
2658 case QEvent::MouseMove:
2659 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2662 case QEvent::MouseButtonPress: {
2663 auto *me =
static_cast<QMouseEvent*>(ev);
2664 mousePressEvent(me);
2665 if (!ev->isAccepted())
2666 d->maybeSynthesizeContextMenuEvent(me);
2670 case QEvent::MouseButtonRelease: {
2671 auto *me =
static_cast<QMouseEvent*>(ev);
2672 mouseReleaseEvent(me);
2673 if (!ev->isAccepted())
2674 d->maybeSynthesizeContextMenuEvent(me);
2678 case QEvent::MouseButtonDblClick:
2679 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2682 case QEvent::TouchBegin:
2683 case QEvent::TouchUpdate:
2684 case QEvent::TouchEnd:
2685 case QEvent::TouchCancel:
2686 touchEvent(
static_cast<QTouchEvent *>(ev));
2690 moveEvent(
static_cast<QMoveEvent*>(ev));
2693 case QEvent::Resize:
2694 resizeEvent(
static_cast<QResizeEvent*>(ev));
2697 case QEvent::KeyPress:
2698 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2701 case QEvent::KeyRelease:
2702 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2705 case QEvent::FocusIn: {
2706 focusInEvent(
static_cast<QFocusEvent *>(ev));
2707#if QT_CONFIG(accessibility)
2708 QAccessible::State state;
2709 state.active =
true;
2710 QAccessibleStateChangeEvent event(
this, state);
2711 QAccessible::updateAccessibility(&event);
2715 case QEvent::FocusOut: {
2716 focusOutEvent(
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#if QT_CONFIG(wheelevent)
2727 wheelEvent(
static_cast<QWheelEvent*>(ev));
2731 case QEvent::Close: {
2733 const bool wasVisible = d->treatAsVisible();
2734 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2737 QPointer<QWindow> deletionGuard(
this);
2738 closeEvent(
static_cast<QCloseEvent*>(ev));
2740 if (ev->isAccepted()) {
2743 if (wasVisible && participatesInLastWindowClosed)
2744 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2750 case QEvent::Expose:
2751 exposeEvent(
static_cast<QExposeEvent *>(ev));
2755 paintEvent(
static_cast<QPaintEvent *>(ev));
2759 showEvent(
static_cast<QShowEvent *>(ev));
2763 hideEvent(
static_cast<QHideEvent *>(ev));
2766 case QEvent::ApplicationWindowIconChange:
2770#if QT_CONFIG(tabletevent)
2771 case QEvent::TabletPress:
2772 case QEvent::TabletMove:
2773 case QEvent::TabletRelease:
2774 tabletEvent(
static_cast<QTabletEvent *>(ev));
2778 case QEvent::PlatformSurface: {
2779 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2781 QOpenGLContext *context = QOpenGLContext::currentContext();
2782 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2783 context->doneCurrent();
2790 return QObject::event(ev);
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
2826
2827
2828
2829
2830
2831
2832
2833
2834void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2836#ifndef QT_NO_CONTEXTMENU
2837 if (event->button() == Qt::RightButton
2838 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2839 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2840 event->globalPosition().toPoint(), event->modifiers());
2841 qCDebug(lcPopup) <<
"synthesized after"
2842 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2843 << event->type() <<
":" << &e;
2844 QCoreApplication::forwardEvent(q_func(), &e, event);
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878void QWindow::requestUpdate()
2880 Q_ASSERT_X(QThread::isMainThread(),
2881 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2884 if (d->updateRequestPending || !d->platformWindow)
2886 d->updateRequestPending =
true;
2887 d->platformWindow->requestUpdate();
2891
2892
2893
2894
2895void QWindow::keyPressEvent(QKeyEvent *ev)
2901
2902
2903
2904
2905void QWindow::keyReleaseEvent(QKeyEvent *ev)
2911
2912
2913
2914
2915
2916
2917void QWindow::focusInEvent(QFocusEvent *ev)
2923
2924
2925
2926
2927
2928
2929void QWindow::focusOutEvent(QFocusEvent *ev)
2935
2936
2937
2938
2939void QWindow::mousePressEvent(QMouseEvent *ev)
2945
2946
2947
2948
2949void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2955
2956
2957
2958
2959void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2965
2966
2967void QWindow::mouseMoveEvent(QMouseEvent *ev)
2972#if QT_CONFIG(wheelevent)
2974
2975
2976void QWindow::wheelEvent(QWheelEvent *ev)
2983
2984
2985void QWindow::touchEvent(QTouchEvent *ev)
2990#if QT_CONFIG(tabletevent)
2992
2993
2994
2995
2996
2997void QWindow::tabletEvent(QTabletEvent *ev)
3004
3005
3006
3007
3008
3009
3010
3012bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3014 Q_UNUSED(eventType);
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3034 if (d->platformWindow
3035 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3036 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3039 if (!QHighDpiScaling::isActive())
3040 return pos + d->globalPosition();
3048 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3052 QPointF nativeWindowGlobalPos = d->platformWindow
3053 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3054 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3055 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3056 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3057 return deviceIndependentGlobalPos;
3061
3062
3063QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3065 return mapToGlobal(QPointF(pos)).toPoint();
3069
3070
3071
3072
3073
3074
3075
3076
3077QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3081 if (d->platformWindow
3082 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3083 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3086 if (!QHighDpiScaling::isActive())
3087 return pos - d->globalPosition();
3091 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3095 QPointF nativeWindowGlobalPos = d->platformWindow
3096 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3097 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3098 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3099 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3100 return deviceIndependentLocalPos;
3104
3105
3106QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3108 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3111QPoint QWindowPrivate::globalPosition()
const
3114 QPoint offset = q->position();
3115 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3116 QPlatformWindow *pw = p->handle();
3117 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3119 offset += p->mapToGlobal(QPoint(0, 0));
3122 offset += p->position();
3130 return window->d_func();
3133QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3137 QWindow *window =
const_cast<QWindow *>(q);
3140 QWindow *parent = window->parent(mode);
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171QWindow *QWindow::fromWinId(WId id)
3173 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3174 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3178 QWindow *window =
new QWindow;
3182 window->setProperty(kForeignWindowId, id);
3185 if (!window->handle()) {
3194
3195
3196
3197
3198
3199
3200
3201
3202
3204void QWindow::alert(
int msec)
3207 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3209 d->platformWindow->setAlertState(
true);
3210 if (d->platformWindow->isAlertState() && msec)
3211 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3214void QWindowPrivate::_q_clearAlert()
3216 if (platformWindow && platformWindow->isAlertState())
3217 platformWindow->setAlertState(
false);
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241void QWindow::setCursor(
const QCursor &cursor)
3244 d->setCursor(&cursor);
3248
3249
3250void QWindow::unsetCursor()
3253 d->setCursor(
nullptr);
3257
3258
3259
3260
3261QCursor QWindow::cursor()
const
3267void QWindowPrivate::setCursor(
const QCursor *newCursor)
3272 const Qt::CursorShape newShape = newCursor->shape();
3273 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3275 cursor = *newCursor;
3280 cursor = QCursor(Qt::ArrowCursor);
3284 if (applyCursor()) {
3285 QEvent event(QEvent::CursorChange);
3286 QGuiApplication::sendEvent(q, &event);
3291bool QWindowPrivate::applyCursor()
3294 if (QScreen *screen = q->screen()) {
3295 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3296 if (!platformWindow)
3298 QCursor *c = QGuiApplication::overrideCursor();
3299 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3301 if (!c && hasCursor)
3303 platformCursor->changeCursor(c, q);
3311void *QWindow::resolveInterface(
const char *name,
int revision)
const
3313 using namespace QNativeInterface::Private;
3315 auto *platformWindow = handle();
3316 Q_UNUSED(platformWindow);
3320#if defined(Q_OS_WIN)
3321 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3325 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3328#if defined(Q_OS_MACOS)
3329 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3332#if QT_CONFIG(wayland)
3333 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3336#if defined(Q_OS_WASM)
3337 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3343#ifndef QT_NO_DEBUG_STREAM
3344QDebug operator<<(QDebug debug,
const QWindow *window)
3346 QDebugStateSaver saver(debug);
3349 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3350 if (!window->objectName().isEmpty())
3351 debug <<
", name=" << window->objectName();
3352 if (debug.verbosity() > 2) {
3353 const QRect geometry = window->geometry();
3354 if (window->isVisible())
3355 debug <<
", visible";
3356 if (window->isExposed())
3357 debug <<
", exposed";
3358 debug <<
", state=" << window->windowState()
3359 <<
", type=" << window->type() <<
", flags=" << window->flags()
3360 <<
", surface type=" << window->surfaceType();
3361 if (window->isTopLevel())
3362 debug <<
", toplevel";
3363 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3364 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3365 const QMargins margins = window->frameMargins();
3366 if (!margins.isNull())
3367 debug <<
", margins=" << margins;
3368 const QMargins safeAreaMargins = window->safeAreaMargins();
3369 if (!safeAreaMargins.isNull())
3370 debug <<
", safeAreaMargins=" << safeAreaMargins;
3371 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3372 if (
const QPlatformWindow *platformWindow = window->handle())
3373 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3374 if (
const QScreen *screen = window->screen())
3375 debug <<
", on " << screen->name();
3379 debug <<
"QWindow(0x0)";
3385#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3388
3389
3390
3391
3392void QWindow::setVulkanInstance(QVulkanInstance *instance)
3395 d->vulkanInstance = instance;
3399
3400
3401QVulkanInstance *QWindow::vulkanInstance()
const
3404 return d->vulkanInstance;
3411#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId