7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformintegration.h>
9#ifndef QT_NO_CONTEXTMENU
10#include <qpa/qplatformtheme.h>
14#include <qpa/qplatformopenglcontext.h>
22#if QT_CONFIG(accessibility)
23# include "qaccessible.h"
24# include <private/qaccessiblecache_p.h>
27#if QT_CONFIG(draganddrop)
28#include "qshapedpixmapdndwindow_p.h"
31#include <private/qevent_p.h>
32#include <private/qeventpoint_p.h>
33#include <private/qguiapplication_p.h>
35#include <QtCore/QTimer>
36#include <QtCore/QDebug>
39#include <qpa/qplatformcursor.h>
40#include <qpa/qplatformwindow_p.h>
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
124
125
126
127
128
129
130QWindow::QWindow(QScreen *targetScreen)
131 : QObject(*
new QWindowPrivate(),
nullptr)
132 , QSurface(QSurface::Window)
135 d->init(
nullptr, targetScreen);
139
140
141
142
143
144
145
146
147
148QWindow::QWindow(QWindow *parent)
149 : QWindow(*
new QWindowPrivate(), parent)
154
155
156
157
158
159
160
161
162
163
164
165QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
166 : QObject(dd,
nullptr)
167 , QSurface(QSurface::Window)
174
175
180#if QT_CONFIG(accessibility)
181 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
182 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
188 qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly));
193 QGuiApplicationPrivate::window_list.removeAll(
this);
194 QGuiApplicationPrivate::popup_list.removeAll(
this);
195 if (!QGuiApplicationPrivate::is_app_closing)
196 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
201 if (QGuiApplicationPrivate::focus_window ==
this)
202 QGuiApplicationPrivate::focus_window =
nullptr;
203 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
204 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
205 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
206 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
211QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
212 : QObjectPrivate(version)
215QWindowPrivate::~QWindowPrivate()
218void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
222 q->QObject::setParent(parent);
225 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
227 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
230 connectToScreen(connectScreen);
234 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
235 qFatal(
"Cannot create window: no screens available");
237 QGuiApplicationPrivate::window_list.prepend(q);
239 requestedFormat = QSurfaceFormat::defaultFormat();
240 devicePixelRatio = connectScreen->devicePixelRatio();
242 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
247 if (
const auto *handle = q->handle()) {
248 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q,
249 QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q),
250 QHighDpi::fromNativePixels(handle->geometry(), q));
251 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
256 updateDevicePixelRatio();
260 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
261 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316QWindow::Visibility QWindow::visibility()
const
319 return d->visibility;
322void QWindow::setVisibility(Visibility v)
328 case AutomaticVisibility:
349
350
351
352
353
354void QWindowPrivate::setVisible(
bool visible)
358 if (
this->visible != visible) {
359 this->visible = visible;
360 emit q->visibleChanged(visible);
362 }
else if (platformWindow) {
367 if (!platformWindow) {
370 if (parentWindow && !parentWindow->handle())
386 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
388 if (q->type() == Qt::Window) {
389 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
390 QString &firstWindowTitle = app_priv->firstWindowTitle;
391 if (!firstWindowTitle.isEmpty()) {
392 q->setTitle(firstWindowTitle);
393 firstWindowTitle = QString();
395 if (!app_priv->forcedWindowIcon.isNull())
396 q->setIcon(app_priv->forcedWindowIcon);
399 static bool geometryApplied =
false;
400 if (!geometryApplied) {
401 geometryApplied =
true;
402 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
406 QShowEvent showEvent;
407 QGuiApplication::sendEvent(q, &showEvent);
412 QGuiApplicationPrivate::showModalWindow(q);
414 QGuiApplicationPrivate::hideModalWindow(q);
417 }
else if (visible && QGuiApplication::modalWindow()
418#if QT_CONFIG(draganddrop)
419 && !qobject_cast<QShapedPixmapWindow *>(q)
422 QGuiApplicationPrivate::updateBlockedStatus(q);
425 if (q->type() == Qt::Popup) {
427 QGuiApplicationPrivate::activatePopup(q);
429 QGuiApplicationPrivate::closePopup(q);
433 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
438 platformWindow->setVisible(visible);
441 QHideEvent hideEvent;
442 QGuiApplication::sendEvent(q, &hideEvent);
446void QWindowPrivate::updateVisibility()
450 QWindow::Visibility old = visibility;
453 visibility = QWindow::Hidden;
454 else if (windowState & Qt::WindowMinimized)
455 visibility = QWindow::Minimized;
456 else if (windowState & Qt::WindowFullScreen)
457 visibility = QWindow::FullScreen;
458 else if (windowState & Qt::WindowMaximized)
459 visibility = QWindow::Maximized;
461 visibility = QWindow::Windowed;
463 if (visibility != old)
464 emit q->visibilityChanged(visibility);
467void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
474 QObjectList &siblings = q->parent()->d_ptr->children;
476 const qsizetype siblingCount = siblings.size() - 1;
477 if (siblingCount == 0)
480 const qsizetype currentPosition = siblings.indexOf(q);
481 Q_ASSERT(currentPosition >= 0);
483 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
485 if (currentPosition == targetPosition)
488 siblings.move(currentPosition, targetPosition);
491bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
494 const QScreen *oldScreen = q->screen();
495 return oldScreen != newScreen && (platformWindow || !oldScreen)
496 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
499void QWindowPrivate::disconnectFromScreen()
502 topLevelScreen =
nullptr;
505void QWindowPrivate::connectToScreen(QScreen *screen)
507 disconnectFromScreen();
508 topLevelScreen = screen;
511void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
514 emit q->screenChanged(newScreen);
515 for (QObject *child : q->children()) {
516 if (child->isWindowType())
517 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
521void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
525 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
528 if (newScreen != topLevelScreen) {
529 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
530 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
531 if (shouldRecreate && platformWindow)
533 connectToScreen(newScreen);
536 else if (newScreen && shouldRecreate)
538 emitScreenChangedRecursion(newScreen);
544void QWindowPrivate::create(
bool recursive)
551 const bool needsUpdate = updateRequestPending;
553 updateRequestPending =
false;
556 q->parent()->create();
558 if (platformWindow) {
567 if (q->isTopLevel()) {
568 if (QScreen *screen = screenForGeometry(geometry))
569 setTopLevelScreen(screen,
false);
572 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
574 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
575 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
576 : platformIntegration->createPlatformWindow(q);
577 Q_ASSERT(platformWindow);
579 if (!platformWindow) {
580 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
584 platformWindow->initialize();
586 QObjectList childObjects = q->children();
587 for (
int i = 0; i < childObjects.size(); i ++) {
588 QObject *object = childObjects.at(i);
589 if (!object->isWindowType())
592 QWindow *childWindow =
static_cast<QWindow *>(object);
594 childWindow->d_func()->create(recursive);
599 if (childWindow->isVisible())
600 childWindow->setVisible(
true);
602 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
603 childPlatformWindow->setParent(
this->platformWindow);
606 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
607 QGuiApplication::sendEvent(q, &e);
609 updateDevicePixelRatio();
615void QWindowPrivate::clearFocusObject()
622QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
628void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
629 qxp::function_ref<
void()> funcWidthChanged,
630 qxp::function_ref<
void()> funcHeightChanged)
633 Q_ASSERT(oldSizeMember);
634 const QSize adjustedSize =
635 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
636 if (*oldSizeMember == adjustedSize)
638 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
639 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
640 *oldSizeMember = adjustedSize;
642 if (platformWindow && q->isTopLevel())
643 platformWindow->propagateSizeHints();
651 if (minimumSize.width() <= maximumSize.width()
652 || minimumSize.height() <= maximumSize.height()) {
653 const QSize currentSize = q->size();
654 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
655 q->resize(boundedSize);
660
661
662
663
664
665
666
667
668
669
670
671
672void QWindow::setSurfaceType(SurfaceType surfaceType)
675 d->surfaceType = surfaceType;
679
680
681
682
683QWindow::SurfaceType QWindow::surfaceType()
const
686 return d->surfaceType;
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707void QWindow::setVisible(
bool visible)
711 d->setVisible(visible);
714bool QWindow::isVisible()
const
722
723
724
725
726
727
728
729
730
731
732
733
734
735void QWindow::create()
742
743
744
745
746
747
748
749
750
751
752WId QWindow::winId()
const
756 if (!d->platformWindow)
757 const_cast<QWindow *>(
this)->create();
759 if (!d->platformWindow)
762 return d->platformWindow->winId();
766
767
768
769
770
771
772
773
774
775QWindow *QWindow::parent(AncestorMode mode)
const
778 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
782
783
784
785
786
787
788
789
790
791void QWindow::setParent(QWindow *parent)
794 if (d->parentWindow == parent
796 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
800 QScreen *oldScreen = screen();
801 QScreen *newScreen = parent ? parent->screen() : oldScreen;
802 if (d->windowRecreationRequired(newScreen)) {
803 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
807 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
808 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
810 const auto previousParent = d->parentWindow;
811 QObject::setParent(parent);
812 d->parentWindow = parent;
815 d->disconnectFromScreen();
817 d->connectToScreen(newScreen);
822 if (isVisible() && (!parent || parent->handle()))
825 if (d->platformWindow) {
829 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
832 QGuiApplicationPrivate::updateBlockedStatus(
this);
834 if (previousParent) {
835 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
836 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
840 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
841 QCoreApplication::sendEvent(parent, &childAddedEvent);
844 QEvent parentChangedEvent(QEvent::ParentWindowChange);
845 QCoreApplication::sendEvent(
this, &parentChangedEvent);
846#if QT_CONFIG(accessibility)
847 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
848 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
849 QAccessible::updateAccessibility(&qaEvent);
859 if (parent && screen() != oldScreen)
860 d->emitScreenChangedRecursion(screen());
864
865
866bool QWindow::isTopLevel()
const
869 return d->parentWindow ==
nullptr;
873
874
875
876
877
878
879bool QWindow::isModal()
const
882 return d->modality != Qt::NonModal;
886
887
888
889
890
891
892
893
894
896Qt::WindowModality QWindow::modality()
const
902void QWindow::setModality(Qt::WindowModality modality)
905 if (d->modality == modality)
907 d->modality = modality;
908 emit modalityChanged(modality);
912
913
914
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942void QWindow::setFormat(
const QSurfaceFormat &format)
945 d->requestedFormat = format;
949
950
951
952
953
954
955
956
957
958QSurfaceFormat QWindow::requestedFormat()
const
961 return d->requestedFormat;
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981QSurfaceFormat QWindow::format()
const
984 if (d->platformWindow)
985 return d->platformWindow->format();
986 return d->requestedFormat;
990
991
992
993
994
995
996
997
998
999
1000
1001
1002void QWindow::setFlags(Qt::WindowFlags flags)
1005 if (d->windowFlags == flags)
1008 if (d->platformWindow) {
1009 d->platformWindow->setWindowFlags(flags);
1010 }
else if (d->windowFlags & Qt::ExpandedClientAreaHint &&
1011 !(flags & Qt::ExpandedClientAreaHint)) {
1016 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1019 d->windowFlags = flags;
1021 emit flagsChanged(
this->flags());
1024Qt::WindowFlags QWindow::flags()
const
1027 Qt::WindowFlags flags = d->windowFlags;
1029 if (d->platformWindow && d->platformWindow->isForeignWindow())
1030 flags |= Qt::ForeignWindow;
1036
1037
1038
1039
1040
1041
1042
1043void QWindow::setFlag(Qt::WindowType flag,
bool on)
1047 setFlags(d->windowFlags | flag);
1049 setFlags(d->windowFlags & ~flag);
1053
1054
1055
1056
1057
1058
1059
1060Qt::WindowType QWindow::type()
const
1062 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076void QWindow::setTitle(
const QString &title)
1079 bool changed =
false;
1080 if (d->windowTitle != title) {
1081 d->windowTitle = title;
1084 if (d->platformWindow)
1085 d->platformWindow->setWindowTitle(title);
1087 emit windowTitleChanged(title);
1090QString QWindow::title()
const
1093 return d->windowTitle;
1097
1098
1099
1100
1101
1102
1103void QWindow::setFilePath(
const QString &filePath)
1106 d->windowFilePath = filePath;
1107 if (d->platformWindow)
1108 d->platformWindow->setWindowFilePath(filePath);
1112
1113
1114
1115
1116QString QWindow::filePath()
const
1119 return d->windowFilePath;
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133void QWindow::setIcon(
const QIcon &icon)
1136 d->windowIcon = icon;
1137 if (d->platformWindow)
1138 d->platformWindow->setWindowIcon(icon);
1139 QEvent e(QEvent::WindowIconChange);
1140 QCoreApplication::sendEvent(
this, &e);
1144
1145
1146
1147
1148QIcon QWindow::icon()
const
1151 if (d->windowIcon.isNull())
1152 return QGuiApplication::windowIcon();
1153 return d->windowIcon;
1157
1158
1159
1160
1161void QWindow::raise()
1165 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1167 if (d->platformWindow)
1168 d->platformWindow->raise();
1172
1173
1174
1175
1176void QWindow::lower()
1180 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1182 if (d->platformWindow)
1183 d->platformWindow->lower();
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204bool QWindow::startSystemResize(Qt::Edges edges)
1207 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1210 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1211 const bool isCorner =
1212 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1213 edges == (Qt::TopEdge | Qt::RightEdge) ||
1214 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1215 edges == (Qt::BottomEdge | Qt::LeftEdge);
1217 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1218 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1222 return d->platformWindow->startSystemResize(edges);
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242bool QWindow::startSystemMove()
1245 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1248 return d->platformWindow->startSystemMove();
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265void QWindow::setOpacity(qreal level)
1268 if (level == d->opacity)
1271 if (d->platformWindow) {
1272 d->platformWindow->setOpacity(level);
1273 emit opacityChanged(level);
1277qreal QWindow::opacity()
const
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293void QWindow::setMask(
const QRegion ®ion)
1296 if (d->platformWindow)
1297 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1302
1303
1304
1305
1306
1307QRegion QWindow::mask()
const
1314
1315
1316
1317
1318void QWindow::requestActivate()
1321 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1322 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1325 if (d->platformWindow)
1326 d->platformWindow->requestActivateWindow();
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340bool QWindow::isExposed()
const
1347
1348
1349
1350
1351
1352
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366bool QWindow::isActive()
const
1369 if (!d->platformWindow)
1372 QWindow *focus = QGuiApplication::focusWindow();
1381 if (QWindow *p = parent(IncludeTransients))
1382 return p->isActive();
1384 return isAncestorOf(focus);
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1409 if (d->contentOrientation == orientation)
1411 if (d->platformWindow)
1412 d->platformWindow->handleContentOrientationChange(orientation);
1413 d->contentOrientation = orientation;
1414 emit contentOrientationChanged(orientation);
1417Qt::ScreenOrientation QWindow::contentOrientation()
const
1420 return d->contentOrientation;
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438qreal QWindow::devicePixelRatio()
const
1441 return d->devicePixelRatio;
1445
1446
1447
1448
1449bool QWindowPrivate::updateDevicePixelRatio()
1453 const qreal newDevicePixelRatio = [
this, q]{
1455 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1460 if (
auto *screen = q->screen())
1461 return screen->devicePixelRatio();
1464 return qGuiApp->devicePixelRatio();
1467 if (newDevicePixelRatio == devicePixelRatio)
1470 devicePixelRatio = newDevicePixelRatio;
1471 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1472 QGuiApplication::sendEvent(q, &dprChangeEvent);
1476Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1478 if (state & Qt::WindowMinimized)
1479 return Qt::WindowMinimized;
1480 else if (state & Qt::WindowFullScreen)
1481 return Qt::WindowFullScreen;
1482 else if (state & Qt::WindowMaximized)
1483 return Qt::WindowMaximized;
1484 return Qt::WindowNoState;
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497void QWindow::setWindowState(Qt::WindowState state)
1499 setWindowStates(state);
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518void QWindow::setWindowStates(Qt::WindowStates state)
1521 if (state & Qt::WindowActive) {
1522 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1523 state &= ~Qt::WindowActive;
1526 if (d->platformWindow)
1527 d->platformWindow->setWindowState(state);
1529 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1530 d->windowState = state;
1531 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1532 if (newEffectiveState != originalEffectiveState)
1533 emit windowStateChanged(newEffectiveState);
1535 d->updateVisibility();
1539
1540
1541
1542
1543Qt::WindowState QWindow::windowState()
const
1546 return QWindowPrivate::effectiveState(d->windowState);
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560Qt::WindowStates QWindow::windowStates()
const
1563 return d->windowState;
1567
1568
1569
1570
1571
1572
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588void QWindow::setTransientParent(QWindow *parent)
1591 if (parent && !parent->isTopLevel()) {
1592 qWarning() << parent <<
"must be a top level window.";
1595 if (parent ==
this) {
1596 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1600 d->transientParent = parent;
1602 QGuiApplicationPrivate::updateBlockedStatus(
this);
1603 emit transientParentChanged(parent);
1606QWindow *QWindow::transientParent()
const
1609 return d->transientParent.data();
1613
1614
1615
1616
1617
1618void QWindowPrivate::setTransientParent(QWindow *parent)
1621 q->setTransientParent(parent);
1622 transientParentPropertySet =
true;
1626
1627
1628
1629
1630
1631
1632
1633
1636
1637
1638
1639bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1641 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1644 if (QWindow *parent = child->parent(mode)) {
1645 if (isAncestorOf(parent, mode))
1647 }
else if (handle() && child->handle()) {
1648 if (handle()->isAncestorOf(child->handle()))
1656
1657
1658
1659
1660QSize QWindow::minimumSize()
const
1663 return d->minimumSize;
1667
1668
1669
1670
1671QSize QWindow::maximumSize()
const
1674 return d->maximumSize;
1678
1679
1680
1681
1682QSize QWindow::baseSize()
const
1689
1690
1691
1692
1693QSize QWindow::sizeIncrement()
const
1696 return d->sizeIncrement;
1700
1701
1702
1703
1704
1705
1706void QWindow::setMinimumSize(
const QSize &size)
1710 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1711 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1715
1716
1717
1718void QWindow::setX(
int arg)
1722 setGeometry(QRect(arg, y(), width(), height()));
1724 d->positionAutomatic =
false;
1728
1729
1730
1731void QWindow::setY(
int arg)
1735 setGeometry(QRect(x(), arg, width(), height()));
1737 d->positionAutomatic =
false;
1741
1742
1743
1744void QWindow::setWidth(
int w)
1746 resize(w, height());
1750
1751
1752
1753void QWindow::setHeight(
int h)
1759
1760
1761
1762void QWindow::setMinimumWidth(
int w)
1764 setMinimumSize(QSize(w, minimumHeight()));
1768
1769
1770
1771void QWindow::setMinimumHeight(
int h)
1773 setMinimumSize(QSize(minimumWidth(), h));
1777
1778
1779
1780
1781
1782
1783void QWindow::setMaximumSize(
const QSize &size)
1787 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1788 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1792
1793
1794
1795void QWindow::setMaximumWidth(
int w)
1797 setMaximumSize(QSize(w, maximumHeight()));
1801
1802
1803
1804void QWindow::setMaximumHeight(
int h)
1806 setMaximumSize(QSize(maximumWidth(), h));
1810
1811
1812
1813
1814
1815
1816
1817void QWindow::setBaseSize(
const QSize &size)
1820 if (d->baseSize == size)
1823 if (d->platformWindow && isTopLevel())
1824 d->platformWindow->propagateSizeHints();
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841void QWindow::setSizeIncrement(
const QSize &size)
1844 if (d->sizeIncrement == size)
1846 d->sizeIncrement = size;
1847 if (d->platformWindow && isTopLevel())
1848 d->platformWindow->propagateSizeHints();
1852
1853
1854
1855
1856
1857
1858
1859void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1861 setGeometry(QRect(posx, posy, w, h));
1865
1866
1867
1868
1869
1870
1871void QWindow::setGeometry(
const QRect &rect)
1874 d->positionAutomatic =
false;
1875 const QRect oldRect = geometry();
1876 if (rect == oldRect)
1879 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1880 if (d->platformWindow) {
1888 QScreen *newScreen = d->screenForGeometry(rect);
1889 if (newScreen && isTopLevel())
1890 d->setTopLevelScreen(newScreen,
true);
1891 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1895 if (rect.x() != oldRect.x())
1896 emit xChanged(rect.x());
1897 if (rect.y() != oldRect.y())
1898 emit yChanged(rect.y());
1899 if (rect.width() != oldRect.width())
1900 emit widthChanged(rect.width());
1901 if (rect.height() != oldRect.height())
1902 emit heightChanged(rect.height());
1907
1908
1909
1910
1911
1912QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1915 QScreen *currentScreen = q->screen();
1916 QScreen *fallback = currentScreen;
1917 QPoint center = newGeometry.center();
1918 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1919 const auto screens = currentScreen->virtualSiblings();
1920 for (QScreen* screen : screens) {
1921 if (screen->geometry().contains(center))
1923 if (screen->geometry().intersects(newGeometry))
1932
1933
1934
1935
1936
1937
1938QRect QWindow::geometry()
const
1941 if (d->platformWindow) {
1942 const auto nativeGeometry = d->platformWindow->geometry();
1943 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1949
1950
1951
1952
1953QMargins QWindow::frameMargins()
const
1956 if (d->platformWindow)
1957 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1962
1963
1964
1965
1966
1967
1968QRect QWindow::frameGeometry()
const
1971 if (d->platformWindow) {
1972 QMargins m = frameMargins();
1973 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1979
1980
1981
1982
1983
1984
1985QPoint QWindow::framePosition()
const
1988 if (d->platformWindow) {
1989 QMargins margins = frameMargins();
1990 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1992 return d->geometry.topLeft();
1996
1997
1998
1999
2000
2001
2002void QWindow::setFramePosition(
const QPoint &point)
2005 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
2006 d->positionAutomatic =
false;
2007 if (d->platformWindow) {
2008 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
2010 d->geometry.moveTopLeft(point);
2015
2016
2017
2018
2019
2020
2021
2022
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047QMargins QWindow::safeAreaMargins()
const
2050 if (d->platformWindow)
2051 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2056
2057
2058
2059
2060
2061
2062
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078void QWindow::setPosition(
const QPoint &pt)
2080 setGeometry(QRect(pt, size()));
2084
2085
2086
2087
2088
2089
2090void QWindow::setPosition(
int posx,
int posy)
2092 setPosition(QPoint(posx, posy));
2096
2097
2098
2099
2100
2101
2102
2103
2104
2107
2108
2109
2110
2111
2114
2115
2116
2117
2118
2119
2120
2121void QWindow::resize(
int w,
int h)
2123 resize(QSize(w, h));
2127
2128
2129
2130
2131void QWindow::resize(
const QSize &newSize)
2135 const QSize oldSize = size();
2136 if (newSize == oldSize)
2139 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2140 if (d->platformWindow) {
2141 d->platformWindow->setGeometry(
2142 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2144 d->geometry.setSize(newSize);
2145 if (newSize.width() != oldSize.width())
2146 emit widthChanged(newSize.width());
2147 if (newSize.height() != oldSize.height())
2148 emit heightChanged(newSize.height());
2153
2154
2155
2156
2157void QWindow::destroy()
2160 if (!d->platformWindow)
2163 if (d->platformWindow->isForeignWindow())
2169void QWindowPrivate::destroy()
2171 if (!platformWindow)
2175 QObjectList childrenWindows = q->children();
2176 for (
int i = 0; i < childrenWindows.size(); i++) {
2177 QObject *object = childrenWindows.at(i);
2178 if (object->isWindowType()) {
2179 QWindow *w =
static_cast<QWindow*>(object);
2180 qt_window_private(w)->destroy();
2184 bool wasVisible = q->isVisible();
2185 visibilityOnDestroy = wasVisible && platformWindow;
2187 q->setVisible(
false);
2198 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2199 QGuiApplication::sendEvent(q, &e);
2204 delete std::exchange(platformWindow,
nullptr);
2206 if (QGuiApplicationPrivate::focus_window == q)
2207 QGuiApplicationPrivate::focus_window = q->parent();
2208 if (QGuiApplicationPrivate::currentMouseWindow == q)
2209 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2210 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2211 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2213 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2214 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2215 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2217 resizeEventPending =
true;
2218 receivedExpose =
false;
2224 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2228
2229
2230
2231
2232QPlatformWindow *QWindow::handle()
const
2235 return d->platformWindow;
2239
2240
2241
2242
2243QPlatformSurface *QWindow::surfaceHandle()
const
2246 return d->platformWindow;
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259bool QWindow::setKeyboardGrabEnabled(
bool grab)
2262 if (d->platformWindow)
2263 return d->platformWindow->setKeyboardGrabEnabled(grab);
2268
2269
2270
2271
2272
2273
2274
2275
2276bool QWindow::setMouseGrabEnabled(
bool grab)
2279 if (d->platformWindow)
2280 return d->platformWindow->setMouseGrabEnabled(grab);
2285
2286
2287
2288
2289
2290
2291QScreen *QWindow::screen()
const
2294 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310void QWindow::setScreen(QScreen *newScreen)
2314 newScreen = QGuiApplication::primaryScreen();
2315 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2319
2320
2321
2322
2323
2324
2327
2328
2329
2330
2331QAccessibleInterface *QWindow::accessibleRoot()
const
2337
2338
2339
2340
2341
2342
2343
2346
2347
2348
2349QObject *QWindow::focusObject()
const
2351 return const_cast<QWindow *>(
this);
2355
2356
2357
2358
2359
2360
2361
2362
2368 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2369 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2370 if (defaultState == Qt::WindowFullScreen)
2372 else if (defaultState == Qt::WindowMaximized)
2380
2381
2382
2383
2384
2385
2392
2393
2394
2395
2396
2397
2398
2399void QWindow::showMinimized()
2401 setWindowStates(Qt::WindowMinimized);
2406
2407
2408
2409
2410
2411
2412
2413void QWindow::showMaximized()
2415 setWindowStates(Qt::WindowMaximized);
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430void QWindow::showFullScreen()
2432 setWindowStates(Qt::WindowFullScreen);
2434#if !defined Q_OS_QNX
2441
2442
2443
2444
2445
2446
2447
2448void QWindow::showNormal()
2450 setWindowStates(Qt::WindowNoState);
2455
2456
2457
2458
2459
2460
2461
2462
2463bool QWindow::close()
2473 if (!d->platformWindow) {
2476 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2477 QGuiApplicationPrivate::closePopup(
this);
2483 QPointer guard(
this);
2485 bool success = d->platformWindow->close();
2492bool QWindowPrivate::participatesInLastWindowClosed()
const
2496 if (!q->isTopLevel())
2502 if (q->type() == Qt::ToolTip)
2507 if (q->transientParent())
2513bool QWindowPrivate::treatAsVisible()
const
2516 return q->isVisible();
2520
2521
2522
2523const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2526 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2527 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2528 QWindow *ret =
nullptr;
2529 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2530 if (q == popupWindow)
2532 if (event->isPointerEvent()) {
2534 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2535 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2536 QEventPoint &eventPoint = pointerEvent->point(i);
2537 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2538 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2539 QMutableEventPoint::setPosition(eventPoint, mapped);
2540 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2544
2545
2546 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2547 event->setAccepted(pointerEvent->isAccepted());
2548 if (pointerEvent->isAccepted())
2551 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2552 <<
"handled?" << (ret !=
nullptr)
2553 <<
"accepted?" << event->isAccepted();
2555 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2556 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2558 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2559 <<
"handled?" << (ret !=
nullptr)
2560 <<
"accepted?" << event->isAccepted();
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585void QWindow::exposeEvent(QExposeEvent *ev)
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604void QWindow::paintEvent(QPaintEvent *ev)
2610
2611
2612void QWindow::moveEvent(QMoveEvent *ev)
2618
2619
2620
2621
2622
2623
2624void QWindow::resizeEvent(QResizeEvent *ev)
2630
2631
2632
2633
2634
2635
2636
2637void QWindow::showEvent(QShowEvent *ev)
2643
2644
2645
2646
2647
2648void QWindow::hideEvent(QHideEvent *ev)
2654
2655
2656
2657
2658
2659
2660
2661void QWindow::closeEvent(QCloseEvent *ev)
2667
2668
2669
2670
2671
2672
2673bool QWindow::event(QEvent *ev)
2676 switch (ev->type()) {
2677 case QEvent::MouseMove:
2678 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2681 case QEvent::MouseButtonPress: {
2682 auto *me =
static_cast<QMouseEvent*>(ev);
2683 mousePressEvent(me);
2684 if (!ev->isAccepted())
2685 d->maybeSynthesizeContextMenuEvent(me);
2689 case QEvent::MouseButtonRelease: {
2690 auto *me =
static_cast<QMouseEvent*>(ev);
2691 mouseReleaseEvent(me);
2692 if (!ev->isAccepted())
2693 d->maybeSynthesizeContextMenuEvent(me);
2697 case QEvent::MouseButtonDblClick:
2698 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2701 case QEvent::TouchBegin:
2702 case QEvent::TouchUpdate:
2703 case QEvent::TouchEnd:
2704 case QEvent::TouchCancel:
2705 touchEvent(
static_cast<QTouchEvent *>(ev));
2709 moveEvent(
static_cast<QMoveEvent*>(ev));
2712 case QEvent::Resize:
2713 resizeEvent(
static_cast<QResizeEvent*>(ev));
2716 case QEvent::KeyPress:
2717 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2720 case QEvent::KeyRelease:
2721 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2724 case QEvent::FocusIn: {
2725 focusInEvent(
static_cast<QFocusEvent *>(ev));
2726#if QT_CONFIG(accessibility)
2727 QAccessible::State state;
2728 state.active =
true;
2729 QAccessibleStateChangeEvent event(
this, state);
2730 QAccessible::updateAccessibility(&event);
2734 case QEvent::FocusOut: {
2735 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2736#if QT_CONFIG(accessibility)
2737 QAccessible::State state;
2738 state.active =
true;
2739 QAccessibleStateChangeEvent event(
this, state);
2740 QAccessible::updateAccessibility(&event);
2744#if QT_CONFIG(wheelevent)
2746 wheelEvent(
static_cast<QWheelEvent*>(ev));
2750 case QEvent::Close: {
2752 const bool wasVisible = d->treatAsVisible();
2753 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2756 QPointer<QWindow> deletionGuard(
this);
2757 closeEvent(
static_cast<QCloseEvent*>(ev));
2759 if (ev->isAccepted()) {
2762 if (wasVisible && participatesInLastWindowClosed)
2763 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2769 case QEvent::Expose:
2770 exposeEvent(
static_cast<QExposeEvent *>(ev));
2774 paintEvent(
static_cast<QPaintEvent *>(ev));
2778 showEvent(
static_cast<QShowEvent *>(ev));
2782 hideEvent(
static_cast<QHideEvent *>(ev));
2785 case QEvent::ApplicationWindowIconChange:
2789#if QT_CONFIG(tabletevent)
2790 case QEvent::TabletPress:
2791 case QEvent::TabletMove:
2792 case QEvent::TabletRelease:
2793 tabletEvent(
static_cast<QTabletEvent *>(ev));
2797 case QEvent::PlatformSurface: {
2798 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2800 QOpenGLContext *context = QOpenGLContext::currentContext();
2801 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2802 context->doneCurrent();
2809 return QObject::event(ev);
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2855#ifndef QT_NO_CONTEXTMENU
2856 if (event->button() == Qt::RightButton
2857 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2858 QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(),
2859 event->globalPosition().toPoint(), event->modifiers());
2860 qCDebug(lcPopup) <<
"synthesized after"
2861 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2862 << event->type() <<
":" << &e;
2863 QCoreApplication::forwardEvent(q_func(), &e, event);
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897void QWindow::requestUpdate()
2899 Q_ASSERT_X(QThread::isMainThread(),
2900 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2903 if (d->updateRequestPending || !d->platformWindow)
2905 d->updateRequestPending =
true;
2906 d->platformWindow->requestUpdate();
2910
2911
2912
2913
2914void QWindow::keyPressEvent(QKeyEvent *ev)
2920
2921
2922
2923
2924void QWindow::keyReleaseEvent(QKeyEvent *ev)
2930
2931
2932
2933
2934
2935
2936void QWindow::focusInEvent(QFocusEvent *ev)
2942
2943
2944
2945
2946
2947
2948void QWindow::focusOutEvent(QFocusEvent *ev)
2954
2955
2956
2957
2958void QWindow::mousePressEvent(QMouseEvent *ev)
2964
2965
2966
2967
2968void QWindow::mouseReleaseEvent(QMouseEvent *ev)
2974
2975
2976
2977
2978void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
2984
2985
2986void QWindow::mouseMoveEvent(QMouseEvent *ev)
2991#if QT_CONFIG(wheelevent)
2993
2994
2995void QWindow::wheelEvent(QWheelEvent *ev)
3002
3003
3004void QWindow::touchEvent(QTouchEvent *ev)
3009#if QT_CONFIG(tabletevent)
3011
3012
3013
3014
3015
3016void QWindow::tabletEvent(QTabletEvent *ev)
3023
3024
3025
3026
3027
3028
3029
3031bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3033 Q_UNUSED(eventType);
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3053 if (d->platformWindow
3054 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3055 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3058 if (!QHighDpiScaling::isActive())
3059 return pos + d->globalPosition();
3067 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3071 QPointF nativeWindowGlobalPos = d->platformWindow
3072 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3073 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3074 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3075 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3076 return deviceIndependentGlobalPos;
3080
3081
3082QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3084 return mapToGlobal(QPointF(pos)).toPoint();
3088
3089
3090
3091
3092
3093
3094
3095
3096QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3100 if (d->platformWindow
3101 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3102 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3105 if (!QHighDpiScaling::isActive())
3106 return pos - d->globalPosition();
3110 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3114 QPointF nativeWindowGlobalPos = d->platformWindow
3115 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3116 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3117 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3118 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3119 return deviceIndependentLocalPos;
3123
3124
3125QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3127 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3130QPoint QWindowPrivate::globalPosition()
const
3133 QPoint offset = q->position();
3134 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3135 QPlatformWindow *pw = p->handle();
3136 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3138 offset += p->mapToGlobal(QPoint(0, 0));
3141 offset += p->position();
3149 return window->d_func();
3152QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3156 QWindow *window =
const_cast<QWindow *>(q);
3159 QWindow *parent = window->parent(mode);
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190QWindow *QWindow::fromWinId(WId id)
3192 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3193 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3197 QWindow *window =
new QWindow;
3201 window->setProperty(kForeignWindowId, id);
3204 if (!window->handle()) {
3213
3214
3215
3216
3217
3218
3219
3220
3221
3223void QWindow::alert(
int msec)
3226 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3228 d->platformWindow->setAlertState(
true);
3229 if (d->platformWindow->isAlertState() && msec)
3230 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3233void QWindowPrivate::_q_clearAlert()
3235 if (platformWindow && platformWindow->isAlertState())
3236 platformWindow->setAlertState(
false);
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260void QWindow::setCursor(
const QCursor &cursor)
3263 d->setCursor(&cursor);
3267
3268
3269void QWindow::unsetCursor()
3272 d->setCursor(
nullptr);
3276
3277
3278
3279
3280QCursor QWindow::cursor()
const
3286void QWindowPrivate::setCursor(
const QCursor *newCursor)
3291 const Qt::CursorShape newShape = newCursor->shape();
3292 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3294 cursor = *newCursor;
3299 cursor = QCursor(Qt::ArrowCursor);
3303 if (applyCursor()) {
3304 QEvent event(QEvent::CursorChange);
3305 QGuiApplication::sendEvent(q, &event);
3310bool QWindowPrivate::applyCursor()
3313 if (QScreen *screen = q->screen()) {
3314 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3315 if (!platformWindow)
3317 QCursor *c = QGuiApplication::overrideCursor();
3318 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3320 if (!c && hasCursor)
3322 platformCursor->changeCursor(c, q);
3330void *QWindow::resolveInterface(
const char *name,
int revision)
const
3332 using namespace QNativeInterface::Private;
3334 auto *platformWindow = handle();
3335 Q_UNUSED(platformWindow);
3339#if defined(Q_OS_WIN)
3340 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3344 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3347#if defined(Q_OS_MACOS)
3348 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3351#if QT_CONFIG(wayland)
3352 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3355#if defined(Q_OS_WASM)
3356 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3362#ifndef QT_NO_DEBUG_STREAM
3363QDebug operator<<(QDebug debug,
const QWindow *window)
3365 QDebugStateSaver saver(debug);
3368 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3369 if (!window->objectName().isEmpty())
3370 debug <<
", name=" << window->objectName();
3371 if (debug.verbosity() > 2) {
3372 const QRect geometry = window->geometry();
3373 if (window->isVisible())
3374 debug <<
", visible";
3375 if (window->isExposed())
3376 debug <<
", exposed";
3377 debug <<
", state=" << window->windowState()
3378 <<
", type=" << window->type() <<
", flags=" << window->flags()
3379 <<
", surface type=" << window->surfaceType();
3380 if (window->isTopLevel())
3381 debug <<
", toplevel";
3382 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3383 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3384 const QMargins margins = window->frameMargins();
3385 if (!margins.isNull())
3386 debug <<
", margins=" << margins;
3387 const QMargins safeAreaMargins = window->safeAreaMargins();
3388 if (!safeAreaMargins.isNull())
3389 debug <<
", safeAreaMargins=" << safeAreaMargins;
3390 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3391 if (
const QPlatformWindow *platformWindow = window->handle())
3392 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3393 if (
const QScreen *screen = window->screen())
3394 debug <<
", on " << screen->name();
3398 debug <<
"QWindow(0x0)";
3404#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3407
3408
3409
3410
3411void QWindow::setVulkanInstance(QVulkanInstance *instance)
3414 d->vulkanInstance = instance;
3418
3419
3420QVulkanInstance *QWindow::vulkanInstance()
const
3423 return d->vulkanInstance;
3430#include "moc_qwindow.cpp"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId