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)
526 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
529 if (newScreen != topLevelScreen) {
530 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
531 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
532 if (shouldRecreate && platformWindow)
534 connectToScreen(newScreen);
537 else if (newScreen && shouldRecreate)
539 emitScreenChangedRecursion(newScreen);
545void QWindowPrivate::create(
bool recursive)
552 const bool needsUpdate = updateRequestPending;
554 updateRequestPending =
false;
557 q->parent()->create();
559 if (platformWindow) {
568 if (q->isTopLevel()) {
569 if (QScreen *screen = screenForGeometry(geometry))
570 setTopLevelScreen(screen,
false);
573 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
575 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
576 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
577 : platformIntegration->createPlatformWindow(q);
578 Q_ASSERT(platformWindow);
580 if (!platformWindow) {
581 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
585 platformWindow->initialize();
587 QObjectList childObjects = q->children();
588 for (
int i = 0; i < childObjects.size(); i ++) {
589 QObject *object = childObjects.at(i);
590 if (!object->isWindowType())
593 QWindow *childWindow =
static_cast<QWindow *>(object);
595 childWindow->d_func()->create(recursive);
600 if (childWindow->isVisible())
601 childWindow->setVisible(
true);
603 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
604 childPlatformWindow->setParent(
this->platformWindow);
607 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
608 QGuiApplication::sendEvent(q, &e);
610 updateDevicePixelRatio();
616void QWindowPrivate::clearFocusObject()
623QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
629void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
630 qxp::function_ref<
void()> funcWidthChanged,
631 qxp::function_ref<
void()> funcHeightChanged)
634 Q_ASSERT(oldSizeMember);
635 const QSize adjustedSize =
636 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
637 if (*oldSizeMember == adjustedSize)
639 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
640 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
641 *oldSizeMember = adjustedSize;
643 if (platformWindow && q->isTopLevel())
644 platformWindow->propagateSizeHints();
652 if (minimumSize.width() <= maximumSize.width()
653 || minimumSize.height() <= maximumSize.height()) {
654 const QSize currentSize = q->size();
655 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
656 q->resize(boundedSize);
661
662
663
664
665
666
667
668
669
670
671
672
673void QWindow::setSurfaceType(SurfaceType surfaceType)
676 d->surfaceType = surfaceType;
680
681
682
683
684QWindow::SurfaceType QWindow::surfaceType()
const
687 return d->surfaceType;
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708void QWindow::setVisible(
bool visible)
712 d->setVisible(visible);
715bool QWindow::isVisible()
const
723
724
725
726
727
728
729
730
731
732
733
734
735
736void QWindow::create()
743
744
745
746
747
748
749
750
751
752
753WId QWindow::winId()
const
757 if (!d->platformWindow)
758 const_cast<QWindow *>(
this)->create();
760 if (!d->platformWindow)
763 return d->platformWindow->winId();
767
768
769
770
771
772
773
774
775
776QWindow *QWindow::parent(AncestorMode mode)
const
779 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
783
784
785
786
787
788
789
790
791
792void QWindow::setParent(QWindow *parent)
795 if (d->parentWindow == parent
797 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
801 QScreen *oldScreen = screen();
802 QScreen *newScreen = parent ? parent->screen() : oldScreen;
803 if (d->windowRecreationRequired(newScreen)) {
804 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
808 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
809 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
811 const auto previousParent = d->parentWindow;
812 QObject::setParent(parent);
813 d->parentWindow = parent;
816 d->disconnectFromScreen();
818 d->connectToScreen(newScreen);
823 if (isVisible() && (!parent || parent->handle()))
826 if (d->platformWindow) {
830 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
833 QGuiApplicationPrivate::updateBlockedStatus(
this);
835 if (previousParent) {
836 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
837 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
841 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
842 QCoreApplication::sendEvent(parent, &childAddedEvent);
845 QEvent parentChangedEvent(QEvent::ParentWindowChange);
846 QCoreApplication::sendEvent(
this, &parentChangedEvent);
847#if QT_CONFIG(accessibility)
848 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
849 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
850 QAccessible::updateAccessibility(&qaEvent);
860 if (parent && screen() != oldScreen)
861 d->emitScreenChangedRecursion(screen());
865
866
867bool QWindow::isTopLevel()
const
870 return d->parentWindow ==
nullptr;
874
875
876
877
878
879
880bool QWindow::isModal()
const
883 return d->modality != Qt::NonModal;
887
888
889
890
891
892
893
894
895
897Qt::WindowModality QWindow::modality()
const
903void QWindow::setModality(Qt::WindowModality modality)
906 if (d->modality == modality)
908 d->modality = modality;
909 emit modalityChanged(modality);
913
914
915
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943void QWindow::setFormat(
const QSurfaceFormat &format)
946 d->requestedFormat = format;
950
951
952
953
954
955
956
957
958
959QSurfaceFormat QWindow::requestedFormat()
const
962 return d->requestedFormat;
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982QSurfaceFormat QWindow::format()
const
985 if (d->platformWindow)
986 return d->platformWindow->format();
987 return d->requestedFormat;
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003void QWindow::setFlags(Qt::WindowFlags flags)
1006 if (d->windowFlags == flags)
1009 if (d->platformWindow)
1010 d->platformWindow->setWindowFlags(flags);
1012 d->windowFlags = flags;
1014 emit flagsChanged(
this->flags());
1017Qt::WindowFlags QWindow::flags()
const
1020 Qt::WindowFlags flags = d->windowFlags;
1022 if (d->platformWindow && d->platformWindow->isForeignWindow())
1023 flags |= Qt::ForeignWindow;
1029
1030
1031
1032
1033
1034
1035
1036void QWindow::setFlag(Qt::WindowType flag,
bool on)
1040 setFlags(d->windowFlags | flag);
1042 setFlags(d->windowFlags & ~flag);
1046
1047
1048
1049
1050
1051
1052
1053Qt::WindowType QWindow::type()
const
1055 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069void QWindow::setTitle(
const QString &title)
1072 bool changed =
false;
1073 if (d->windowTitle != title) {
1074 d->windowTitle = title;
1077 if (d->platformWindow)
1078 d->platformWindow->setWindowTitle(title);
1080 emit windowTitleChanged(title);
1083QString QWindow::title()
const
1086 return d->windowTitle;
1090
1091
1092
1093
1094
1095
1096void QWindow::setFilePath(
const QString &filePath)
1099 d->windowFilePath = filePath;
1100 if (d->platformWindow)
1101 d->platformWindow->setWindowFilePath(filePath);
1105
1106
1107
1108
1109QString QWindow::filePath()
const
1112 return d->windowFilePath;
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126void QWindow::setIcon(
const QIcon &icon)
1129 d->windowIcon = icon;
1130 if (d->platformWindow)
1131 d->platformWindow->setWindowIcon(icon);
1132 QEvent e(QEvent::WindowIconChange);
1133 QCoreApplication::sendEvent(
this, &e);
1137
1138
1139
1140
1141QIcon QWindow::icon()
const
1144 if (d->windowIcon.isNull())
1145 return QGuiApplication::windowIcon();
1146 return d->windowIcon;
1150
1151
1152
1153
1154void QWindow::raise()
1158 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1160 if (d->platformWindow)
1161 d->platformWindow->raise();
1165
1166
1167
1168
1169void QWindow::lower()
1173 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1175 if (d->platformWindow)
1176 d->platformWindow->lower();
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197bool QWindow::startSystemResize(Qt::Edges edges)
1200 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1203 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1204 const bool isCorner =
1205 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1206 edges == (Qt::TopEdge | Qt::RightEdge) ||
1207 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1208 edges == (Qt::BottomEdge | Qt::LeftEdge);
1210 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1211 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1215 return d->platformWindow->startSystemResize(edges);
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235bool QWindow::startSystemMove()
1238 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1241 return d->platformWindow->startSystemMove();
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258void QWindow::setOpacity(qreal level)
1261 if (level == d->opacity)
1264 if (d->platformWindow) {
1265 d->platformWindow->setOpacity(level);
1266 emit opacityChanged(level);
1270qreal QWindow::opacity()
const
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286void QWindow::setMask(
const QRegion ®ion)
1289 if (d->platformWindow)
1290 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1295
1296
1297
1298
1299
1300QRegion QWindow::mask()
const
1307
1308
1309
1310
1311void QWindow::requestActivate()
1314 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1315 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1318 if (d->platformWindow)
1319 d->platformWindow->requestActivateWindow();
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333bool QWindow::isExposed()
const
1340
1341
1342
1343
1344
1345
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359bool QWindow::isActive()
const
1362 if (!d->platformWindow)
1365 QWindow *focus = QGuiApplication::focusWindow();
1374 if (QWindow *p = parent(IncludeTransients))
1375 return p->isActive();
1377 return isAncestorOf(focus);
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1402 if (d->contentOrientation == orientation)
1404 if (d->platformWindow)
1405 d->platformWindow->handleContentOrientationChange(orientation);
1406 d->contentOrientation = orientation;
1407 emit contentOrientationChanged(orientation);
1410Qt::ScreenOrientation QWindow::contentOrientation()
const
1413 return d->contentOrientation;
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431qreal QWindow::devicePixelRatio()
const
1434 return d->devicePixelRatio;
1438
1439
1440
1441
1442bool QWindowPrivate::updateDevicePixelRatio()
1446 const qreal newDevicePixelRatio = [
this, q]{
1448 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1453 if (
auto *screen = q->screen())
1454 return screen->devicePixelRatio();
1457 return qGuiApp->devicePixelRatio();
1460 if (newDevicePixelRatio == devicePixelRatio)
1463 devicePixelRatio = newDevicePixelRatio;
1464 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1465 QGuiApplication::sendEvent(q, &dprChangeEvent);
1469Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1471 if (state & Qt::WindowMinimized)
1472 return Qt::WindowMinimized;
1473 else if (state & Qt::WindowFullScreen)
1474 return Qt::WindowFullScreen;
1475 else if (state & Qt::WindowMaximized)
1476 return Qt::WindowMaximized;
1477 return Qt::WindowNoState;
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490void QWindow::setWindowState(Qt::WindowState state)
1492 setWindowStates(state);
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511void QWindow::setWindowStates(Qt::WindowStates state)
1514 if (state & Qt::WindowActive) {
1515 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1516 state &= ~Qt::WindowActive;
1519 if (d->platformWindow)
1520 d->platformWindow->setWindowState(state);
1522 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1523 d->windowState = state;
1524 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1525 if (newEffectiveState != originalEffectiveState)
1526 emit windowStateChanged(newEffectiveState);
1528 d->updateVisibility();
1532
1533
1534
1535
1536Qt::WindowState QWindow::windowState()
const
1539 return QWindowPrivate::effectiveState(d->windowState);
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553Qt::WindowStates QWindow::windowStates()
const
1556 return d->windowState;
1560
1561
1562
1563
1564
1565
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581void QWindow::setTransientParent(QWindow *parent)
1584 if (parent && !parent->isTopLevel()) {
1585 qWarning() << parent <<
"must be a top level window.";
1588 if (parent ==
this) {
1589 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1593 d->transientParent = parent;
1595 QGuiApplicationPrivate::updateBlockedStatus(
this);
1596 emit transientParentChanged(parent);
1599QWindow *QWindow::transientParent()
const
1602 return d->transientParent.data();
1606
1607
1608
1609
1610
1611void QWindowPrivate::setTransientParent(QWindow *parent)
1614 q->setTransientParent(parent);
1615 transientParentPropertySet =
true;
1619
1620
1621
1622
1623
1624
1625
1626
1629
1630
1631
1632bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1634 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1637 if (QWindow *parent = child->parent(mode)) {
1638 if (isAncestorOf(parent, mode))
1640 }
else if (handle() && child->handle()) {
1641 if (handle()->isAncestorOf(child->handle()))
1649
1650
1651
1652
1653QSize QWindow::minimumSize()
const
1656 return d->minimumSize;
1660
1661
1662
1663
1664QSize QWindow::maximumSize()
const
1667 return d->maximumSize;
1671
1672
1673
1674
1675QSize QWindow::baseSize()
const
1682
1683
1684
1685
1686QSize QWindow::sizeIncrement()
const
1689 return d->sizeIncrement;
1693
1694
1695
1696
1697
1698
1699void QWindow::setMinimumSize(
const QSize &size)
1703 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1704 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1708
1709
1710
1711void QWindow::setX(
int arg)
1715 setGeometry(QRect(arg, y(), width(), height()));
1717 d->positionAutomatic =
false;
1721
1722
1723
1724void QWindow::setY(
int arg)
1728 setGeometry(QRect(x(), arg, width(), height()));
1730 d->positionAutomatic =
false;
1734
1735
1736
1737void QWindow::setWidth(
int w)
1739 resize(w, height());
1743
1744
1745
1746void QWindow::setHeight(
int h)
1752
1753
1754
1755void QWindow::setMinimumWidth(
int w)
1757 setMinimumSize(QSize(w, minimumHeight()));
1761
1762
1763
1764void QWindow::setMinimumHeight(
int h)
1766 setMinimumSize(QSize(minimumWidth(), h));
1770
1771
1772
1773
1774
1775
1776void QWindow::setMaximumSize(
const QSize &size)
1780 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1781 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1785
1786
1787
1788void QWindow::setMaximumWidth(
int w)
1790 setMaximumSize(QSize(w, maximumHeight()));
1794
1795
1796
1797void QWindow::setMaximumHeight(
int h)
1799 setMaximumSize(QSize(maximumWidth(), h));
1803
1804
1805
1806
1807
1808
1809
1810void QWindow::setBaseSize(
const QSize &size)
1813 if (d->baseSize == size)
1816 if (d->platformWindow && isTopLevel())
1817 d->platformWindow->propagateSizeHints();
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834void QWindow::setSizeIncrement(
const QSize &size)
1837 if (d->sizeIncrement == size)
1839 d->sizeIncrement = size;
1840 if (d->platformWindow && isTopLevel())
1841 d->platformWindow->propagateSizeHints();
1845
1846
1847
1848
1849
1850
1851
1852void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1854 setGeometry(QRect(posx, posy, w, h));
1858
1859
1860
1861
1862
1863
1864void QWindow::setGeometry(
const QRect &rect)
1867 d->positionAutomatic =
false;
1868 const QRect oldRect = geometry();
1869 if (rect == oldRect)
1872 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1873 if (d->platformWindow) {
1875 QScreen *newScreen = d->screenForGeometry(rect);
1876 d->platformWindow->setGeometry(QHighDpi::toNativeGlobalPosition(rect, newScreen));
1878 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1883 if (rect.x() != oldRect.x())
1884 emit xChanged(rect.x());
1885 if (rect.y() != oldRect.y())
1886 emit yChanged(rect.y());
1887 if (rect.width() != oldRect.width())
1888 emit widthChanged(rect.width());
1889 if (rect.height() != oldRect.height())
1890 emit heightChanged(rect.height());
1895
1896
1897
1898
1899
1900QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1903 QScreen *currentScreen = q->screen();
1904 QScreen *fallback = currentScreen;
1905 QPoint center = newGeometry.center();
1906 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1907 const auto screens = currentScreen->virtualSiblings();
1908 for (QScreen* screen : screens) {
1909 if (screen->geometry().contains(center))
1911 if (screen->geometry().intersects(newGeometry))
1920
1921
1922
1923
1924
1925
1926QRect QWindow::geometry()
const
1929 if (d->platformWindow) {
1930 const auto nativeGeometry = d->platformWindow->geometry();
1931 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1937
1938
1939
1940
1941QMargins QWindow::frameMargins()
const
1944 if (d->platformWindow)
1945 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1950
1951
1952
1953
1954
1955
1956QRect QWindow::frameGeometry()
const
1959 if (d->platformWindow) {
1960 QMargins m = frameMargins();
1961 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1967
1968
1969
1970
1971
1972
1973QPoint QWindow::framePosition()
const
1976 if (d->platformWindow) {
1977 QMargins margins = frameMargins();
1978 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1980 return d->geometry.topLeft();
1984
1985
1986
1987
1988
1989
1990void QWindow::setFramePosition(
const QPoint &point)
1993 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1994 d->positionAutomatic =
false;
1995 if (d->platformWindow) {
1996 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
1998 d->geometry.moveTopLeft(point);
2003
2004
2005
2006
2007
2008
2009
2010
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035QMargins QWindow::safeAreaMargins()
const
2038 if (d->platformWindow)
2039 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2044
2045
2046
2047
2048
2049
2050
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066void QWindow::setPosition(
const QPoint &pt)
2068 setGeometry(QRect(pt, size()));
2072
2073
2074
2075
2076
2077
2078void QWindow::setPosition(
int posx,
int posy)
2080 setPosition(QPoint(posx, posy));
2084
2085
2086
2087
2088
2089
2090
2091
2092
2095
2096
2097
2098
2099
2102
2103
2104
2105
2106
2107
2108
2109void QWindow::resize(
int w,
int h)
2111 resize(QSize(w, h));
2115
2116
2117
2118
2119void QWindow::resize(
const QSize &newSize)
2123 const QSize oldSize = size();
2124 if (newSize == oldSize)
2127 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2128 if (d->platformWindow) {
2129 d->platformWindow->setGeometry(
2130 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2132 d->geometry.setSize(newSize);
2133 if (newSize.width() != oldSize.width())
2134 emit widthChanged(newSize.width());
2135 if (newSize.height() != oldSize.height())
2136 emit heightChanged(newSize.height());
2141
2142
2143
2144
2145void QWindow::destroy()
2148 if (!d->platformWindow)
2151 if (d->platformWindow->isForeignWindow())
2157void QWindowPrivate::destroy()
2159 if (!platformWindow)
2163 QObjectList childrenWindows = q->children();
2164 for (
int i = 0; i < childrenWindows.size(); i++) {
2165 QObject *object = childrenWindows.at(i);
2166 if (object->isWindowType()) {
2167 QWindow *w =
static_cast<QWindow*>(object);
2168 qt_window_private(w)->destroy();
2172 bool wasVisible = q->isVisible();
2173 visibilityOnDestroy = wasVisible && platformWindow;
2175 q->setVisible(
false);
2186 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2187 QGuiApplication::sendEvent(q, &e);
2192 delete std::exchange(platformWindow,
nullptr);
2194 if (QGuiApplicationPrivate::focus_window == q)
2195 QGuiApplicationPrivate::focus_window = q->parent();
2196 if (QGuiApplicationPrivate::currentMouseWindow == q)
2197 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2198 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2199 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2201 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2202 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2203 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2205 resizeEventPending =
true;
2206 receivedExpose =
false;
2212 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2216
2217
2218
2219
2220QPlatformWindow *QWindow::handle()
const
2223 return d->platformWindow;
2227
2228
2229
2230
2231QPlatformSurface *QWindow::surfaceHandle()
const
2234 return d->platformWindow;
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247bool QWindow::setKeyboardGrabEnabled(
bool grab)
2250 if (d->platformWindow)
2251 return d->platformWindow->setKeyboardGrabEnabled(grab);
2256
2257
2258
2259
2260
2261
2262
2263
2264bool QWindow::setMouseGrabEnabled(
bool grab)
2267 if (d->platformWindow)
2268 return d->platformWindow->setMouseGrabEnabled(grab);
2273
2274
2275
2276
2277
2278
2279QScreen *QWindow::screen()
const
2282 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298void QWindow::setScreen(QScreen *newScreen)
2302 newScreen = QGuiApplication::primaryScreen();
2303 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2307
2308
2309
2310
2311
2312
2315
2316
2317
2318
2319QAccessibleInterface *QWindow::accessibleRoot()
const
2325
2326
2327
2328
2329
2330
2331
2334
2335
2336
2337QObject *QWindow::focusObject()
const
2339 return const_cast<QWindow *>(
this);
2343
2344
2345
2346
2347
2348
2349
2350
2356 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2357 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2358 if (defaultState == Qt::WindowFullScreen)
2360 else if (defaultState == Qt::WindowMaximized)
2368
2369
2370
2371
2372
2373
2380
2381
2382
2383
2384
2385
2386
2387void QWindow::showMinimized()
2389 setWindowStates(Qt::WindowMinimized);
2394
2395
2396
2397
2398
2399
2400
2401void QWindow::showMaximized()
2403 setWindowStates(Qt::WindowMaximized);
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418void QWindow::showFullScreen()
2420 setWindowStates(Qt::WindowFullScreen);
2422#if !defined Q_OS_QNX
2429
2430
2431
2432
2433
2434
2435
2436void QWindow::showNormal()
2438 setWindowStates(Qt::WindowNoState);
2443
2444
2445
2446
2447
2448
2449
2450
2451bool QWindow::close()
2461 if (!d->platformWindow) {
2464 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2465 QGuiApplicationPrivate::closePopup(
this);
2471 QPointer guard(
this);
2473 bool success = d->platformWindow->close();
2480bool QWindowPrivate::participatesInLastWindowClosed()
const
2484 if (!q->isTopLevel())
2490 if (q->type() == Qt::ToolTip)
2495 if (q->transientParent())
2501bool QWindowPrivate::treatAsVisible()
const
2504 return q->isVisible();
2508
2509
2510
2511const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2514 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2515 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2516 QWindow *ret =
nullptr;
2517 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2518 if (q == popupWindow)
2520 if (event->isPointerEvent()) {
2522 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2523 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2524 QEventPoint &eventPoint = pointerEvent->point(i);
2525 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2526 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2527 QMutableEventPoint::setPosition(eventPoint, mapped);
2528 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2532
2533
2534 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2535 event->setAccepted(pointerEvent->isAccepted());
2536 if (pointerEvent->isAccepted())
2539 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2540 <<
"handled?" << (ret !=
nullptr)
2541 <<
"accepted?" << event->isAccepted();
2543 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2544 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2546 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2547 <<
"handled?" << (ret !=
nullptr)
2548 <<
"accepted?" << event->isAccepted();
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573void QWindow::exposeEvent(QExposeEvent *ev)
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592void QWindow::paintEvent(QPaintEvent *ev)
2598
2599
2600void QWindow::moveEvent(QMoveEvent *ev)
2606
2607
2608
2609
2610
2611
2612void QWindow::resizeEvent(QResizeEvent *ev)
2618
2619
2620
2621
2622
2623
2624
2625void QWindow::showEvent(QShowEvent *ev)
2631
2632
2633
2634
2635
2636void QWindow::hideEvent(QHideEvent *ev)
2642
2643
2644
2645
2646
2647
2648
2649void QWindow::closeEvent(QCloseEvent *ev)
2655
2656
2657
2658
2659
2660
2661bool QWindow::event(QEvent *ev)
2664 switch (ev->type()) {
2665 case QEvent::MouseMove:
2666 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2669 case QEvent::MouseButtonPress: {
2670 auto *me =
static_cast<QMouseEvent*>(ev);
2671 mousePressEvent(me);
2672 if (!ev->isAccepted())
2673 d->maybeSynthesizeContextMenuEvent(me);
2677 case QEvent::MouseButtonRelease: {
2678 auto *me =
static_cast<QMouseEvent*>(ev);
2679 mouseReleaseEvent(me);
2680 if (!ev->isAccepted())
2681 d->maybeSynthesizeContextMenuEvent(me);
2685 case QEvent::MouseButtonDblClick:
2686 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2689 case QEvent::TouchBegin:
2690 case QEvent::TouchUpdate:
2691 case QEvent::TouchEnd:
2692 case QEvent::TouchCancel:
2693 touchEvent(
static_cast<QTouchEvent *>(ev));
2697 moveEvent(
static_cast<QMoveEvent*>(ev));
2700 case QEvent::Resize:
2701 resizeEvent(
static_cast<QResizeEvent*>(ev));
2704 case QEvent::KeyPress:
2705 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2708 case QEvent::KeyRelease:
2709 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2712 case QEvent::FocusIn: {
2713 focusInEvent(
static_cast<QFocusEvent *>(ev));
2714#if QT_CONFIG(accessibility)
2715 QAccessible::State state;
2716 state.active =
true;
2717 QAccessibleStateChangeEvent event(
this, state);
2718 QAccessible::updateAccessibility(&event);
2722 case QEvent::FocusOut: {
2723 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2724#if QT_CONFIG(accessibility)
2725 QAccessible::State state;
2726 state.active =
true;
2727 QAccessibleStateChangeEvent event(
this, state);
2728 QAccessible::updateAccessibility(&event);
2732#if QT_CONFIG(wheelevent)
2734 wheelEvent(
static_cast<QWheelEvent*>(ev));
2738 case QEvent::Close: {
2740 const bool wasVisible = d->treatAsVisible();
2741 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2744 QPointer<QWindow> deletionGuard(
this);
2745 closeEvent(
static_cast<QCloseEvent*>(ev));
2747 if (ev->isAccepted()) {
2750 if (wasVisible && participatesInLastWindowClosed)
2751 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2757 case QEvent::Expose:
2758 exposeEvent(
static_cast<QExposeEvent *>(ev));
2762 paintEvent(
static_cast<QPaintEvent *>(ev));
2766 showEvent(
static_cast<QShowEvent *>(ev));
2770 hideEvent(
static_cast<QHideEvent *>(ev));
2773 case QEvent::ApplicationWindowIconChange:
2777#if QT_CONFIG(tabletevent)
2778 case QEvent::TabletPress:
2779 case QEvent::TabletMove:
2780 case QEvent::TabletRelease:
2781 tabletEvent(
static_cast<QTabletEvent *>(ev));
2785 case QEvent::PlatformSurface: {
2786 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2788 QOpenGLContext *context = QOpenGLContext::currentContext();
2789 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2790 context->doneCurrent();
2797 return QObject::event(ev);
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
2834
2835
2836
2837
2838
2839
2840
2841void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2843#ifndef QT_NO_CONTEXTMENU
2844 if (event->button() == Qt::RightButton
2845 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2846 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2847 event->globalPosition().toPoint(), event->modifiers());
2848 qCDebug(lcPopup) <<
"synthesized after"
2849 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2850 << event->type() <<
":" << &e;
2851 QCoreApplication::forwardEvent(q_func(), &e, event);
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885void QWindow::requestUpdate()
2887 Q_ASSERT_X(QThread::isMainThread(),
2888 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2891 if (d->updateRequestPending || !d->platformWindow)
2893 d->updateRequestPending =
true;
2894 d->platformWindow->requestUpdate();
2898
2899
2900
2901
2902void QWindow::keyPressEvent(QKeyEvent *ev)
2908
2909
2910
2911
2912void QWindow::keyReleaseEvent(QKeyEvent *ev)
2918
2919
2920
2921
2922
2923
2924void QWindow::focusInEvent(QFocusEvent *ev)
2930
2931
2932
2933
2934
2935
2936void QWindow::focusOutEvent(QFocusEvent *ev)
2942
2943
2944
2945
2946void QWindow::mousePressEvent(QMouseEvent *ev)
2952
2953
2954
2955
2956void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2962
2963
2964
2965
2966void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2972
2973
2974void QWindow::mouseMoveEvent(QMouseEvent *ev)
2979#if QT_CONFIG(wheelevent)
2981
2982
2983void QWindow::wheelEvent(QWheelEvent *ev)
2990
2991
2992void QWindow::touchEvent(QTouchEvent *ev)
2997#if QT_CONFIG(tabletevent)
2999
3000
3001
3002
3003
3004void QWindow::tabletEvent(QTabletEvent *ev)
3011
3012
3013
3014
3015
3016
3017
3019bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3021 Q_UNUSED(eventType);
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3041 if (d->platformWindow
3042 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3043 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3046 if (!QHighDpiScaling::isActive())
3047 return pos + d->globalPosition();
3055 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3059 QPointF nativeWindowGlobalPos = d->platformWindow
3060 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3061 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3062 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3063 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3064 return deviceIndependentGlobalPos;
3068
3069
3070QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3072 return mapToGlobal(QPointF(pos)).toPoint();
3076
3077
3078
3079
3080
3081
3082
3083
3084QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3088 if (d->platformWindow
3089 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3090 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3093 if (!QHighDpiScaling::isActive())
3094 return pos - d->globalPosition();
3098 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3102 QPointF nativeWindowGlobalPos = d->platformWindow
3103 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3104 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3105 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3106 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3107 return deviceIndependentLocalPos;
3111
3112
3113QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3115 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3118QPoint QWindowPrivate::globalPosition()
const
3121 QPoint offset = q->position();
3122 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3123 QPlatformWindow *pw = p->handle();
3124 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3126 offset += p->mapToGlobal(QPoint(0, 0));
3129 offset += p->position();
3137 return window->d_func();
3140QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3144 QWindow *window =
const_cast<QWindow *>(q);
3147 QWindow *parent = window->parent(mode);
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178QWindow *QWindow::fromWinId(WId id)
3180 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3181 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3185 QWindow *window =
new QWindow;
3189 window->setProperty(kForeignWindowId, id);
3192 if (!window->handle()) {
3201
3202
3203
3204
3205
3206
3207
3208
3209
3211void QWindow::alert(
int msec)
3214 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3216 d->platformWindow->setAlertState(
true);
3217 if (d->platformWindow->isAlertState() && msec)
3218 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3221void QWindowPrivate::_q_clearAlert()
3223 if (platformWindow && platformWindow->isAlertState())
3224 platformWindow->setAlertState(
false);
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248void QWindow::setCursor(
const QCursor &cursor)
3251 d->setCursor(&cursor);
3255
3256
3257void QWindow::unsetCursor()
3260 d->setCursor(
nullptr);
3264
3265
3266
3267
3268QCursor QWindow::cursor()
const
3274void QWindowPrivate::setCursor(
const QCursor *newCursor)
3279 const Qt::CursorShape newShape = newCursor->shape();
3280 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3282 cursor = *newCursor;
3287 cursor = QCursor(Qt::ArrowCursor);
3291 if (applyCursor()) {
3292 QEvent event(QEvent::CursorChange);
3293 QGuiApplication::sendEvent(q, &event);
3298bool QWindowPrivate::applyCursor()
3301 if (QScreen *screen = q->screen()) {
3302 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3303 if (!platformWindow)
3305 QCursor *c = QGuiApplication::overrideCursor();
3306 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3308 if (!c && hasCursor)
3310 platformCursor->changeCursor(c, q);
3318void *QWindow::resolveInterface(
const char *name,
int revision)
const
3320 using namespace QNativeInterface::Private;
3322 auto *platformWindow = handle();
3323 Q_UNUSED(platformWindow);
3327#if defined(Q_OS_WIN)
3328 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3332 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3335#if defined(Q_OS_MACOS)
3336 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3339#if QT_CONFIG(wayland)
3340 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3343#if defined(Q_OS_WASM)
3344 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3350#ifndef QT_NO_DEBUG_STREAM
3351QDebug operator<<(QDebug debug,
const QWindow *window)
3353 QDebugStateSaver saver(debug);
3356 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3357 if (!window->objectName().isEmpty())
3358 debug <<
", name=" << window->objectName();
3359 if (debug.verbosity() > 2) {
3360 const QRect geometry = window->geometry();
3361 if (window->isVisible())
3362 debug <<
", visible";
3363 if (window->isExposed())
3364 debug <<
", exposed";
3365 debug <<
", state=" << window->windowState()
3366 <<
", type=" << window->type() <<
", flags=" << window->flags()
3367 <<
", surface type=" << window->surfaceType();
3368 if (window->isTopLevel())
3369 debug <<
", toplevel";
3370 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3371 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3372 const QMargins margins = window->frameMargins();
3373 if (!margins.isNull())
3374 debug <<
", margins=" << margins;
3375 const QMargins safeAreaMargins = window->safeAreaMargins();
3376 if (!safeAreaMargins.isNull())
3377 debug <<
", safeAreaMargins=" << safeAreaMargins;
3378 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3379 if (
const QPlatformWindow *platformWindow = window->handle())
3380 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3381 if (
const QScreen *screen = window->screen())
3382 debug <<
", on " << screen->name();
3386 debug <<
"QWindow(0x0)";
3392#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3395
3396
3397
3398
3399void QWindow::setVulkanInstance(QVulkanInstance *instance)
3402 d->vulkanInstance = instance;
3406
3407
3408QVulkanInstance *QWindow::vulkanInstance()
const
3411 return d->vulkanInstance;
3418#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId