7#include <qpa/qplatformwindow.h>
8#include <qpa/qplatformintegration.h>
9#include <qpa/qplatformscreen.h>
10#ifndef QT_NO_CONTEXTMENU
11#include <qpa/qplatformtheme.h>
15#include <qpa/qplatformopenglcontext.h>
23#if QT_CONFIG(accessibility)
24# include "qaccessible.h"
25# include <private/qaccessiblecache_p.h>
28#if QT_CONFIG(draganddrop)
29#include "qshapedpixmapdndwindow_p.h"
32#include <private/qevent_p.h>
33#include <private/qeventpoint_p.h>
34#include <private/qguiapplication_p.h>
36#include <QtCore/QTimer>
37#include <QtCore/QDebug>
40#include <qpa/qplatformcursor.h>
41#include <qpa/qplatformwindow_p.h>
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
122
125
126
127
128
129
130
131QWindow::QWindow(QScreen *targetScreen)
132 : QObject(*
new QWindowPrivate(),
nullptr)
133 , QSurface(QSurface::Window)
136 d->init(
nullptr, targetScreen);
140
141
142
143
144
145
146
147
148
149QWindow::QWindow(QWindow *parent)
150 : QWindow(*
new QWindowPrivate(), parent)
155
156
157
158
159
160
161
162
163
164
165
166QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
167 : QObject(dd,
nullptr)
168 , QSurface(QSurface::Window)
175
176
181#if QT_CONFIG(accessibility)
182 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
183 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
189 qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly));
194 QGuiApplicationPrivate::window_list.removeAll(
this);
195 QGuiApplicationPrivate::popup_list.removeAll(
this);
196 if (!QGuiApplicationPrivate::is_app_closing)
197 QGuiApplicationPrivate::instance()->modalWindowList.removeOne(
this);
202 if (QGuiApplicationPrivate::focus_window ==
this)
203 QGuiApplicationPrivate::focus_window =
nullptr;
204 if (QGuiApplicationPrivate::currentMouseWindow ==
this)
205 QGuiApplicationPrivate::currentMouseWindow =
nullptr;
206 if (QGuiApplicationPrivate::currentMousePressWindow ==
this)
207 QGuiApplicationPrivate::currentMousePressWindow =
nullptr;
212QWindowPrivate::QWindowPrivate(
decltype(QObjectPrivateVersion) version)
213 : QObjectPrivate(version)
216QWindowPrivate::~QWindowPrivate()
219void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen)
223 q->QObject::setParent(parent);
226 parentWindow =
static_cast<QWindow *>(q->QObject::parent());
228 QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen();
231 connectToScreen(connectScreen);
235 if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
236 qFatal(
"Cannot create window: no screens available");
238 QGuiApplicationPrivate::window_list.prepend(q);
240 requestedFormat = QSurfaceFormat::defaultFormat();
241 devicePixelRatio = connectScreen->devicePixelRatio();
243 QObject::connect(q, &QWindow::screenChanged, q, [q,
this](QScreen *){
248 if (
const auto *handle = q->handle()) {
249 QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q,
250 QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q),
251 QHighDpi::fromNativePixels(handle->geometry(), q));
252 QGuiApplicationPrivate::processGeometryChangeEvent(&gce);
257 updateDevicePixelRatio();
261 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q);
262 QCoreApplication::sendEvent(parentWindow, &childAddedEvent);
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
299
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317QWindow::Visibility QWindow::visibility()
const
320 return d->visibility;
323void QWindow::setVisibility(Visibility v)
329 case AutomaticVisibility:
350
351
352
353
354
355void QWindowPrivate::setVisible(
bool visible)
359 if (
this->visible != visible) {
360 this->visible = visible;
361 emit q->visibleChanged(visible);
363 }
else if (platformWindow) {
368 if (!platformWindow) {
371 if (parentWindow && !parentWindow->handle())
387 QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
389 if (q->type() == Qt::Window) {
390 QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
391 QString &firstWindowTitle = app_priv->firstWindowTitle;
392 if (!firstWindowTitle.isEmpty()) {
393 q->setTitle(firstWindowTitle);
394 firstWindowTitle = QString();
396 if (!app_priv->forcedWindowIcon.isNull())
397 q->setIcon(app_priv->forcedWindowIcon);
400 static bool geometryApplied =
false;
401 if (!geometryApplied) {
402 geometryApplied =
true;
403 QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q);
407 QShowEvent showEvent;
408 QGuiApplication::sendEvent(q, &showEvent);
413 QGuiApplicationPrivate::showModalWindow(q);
415 QGuiApplicationPrivate::hideModalWindow(q);
418 }
else if (visible && QGuiApplication::modalWindow()
419#if QT_CONFIG(draganddrop)
420 && !qobject_cast<QShapedPixmapWindow *>(q)
423 QGuiApplicationPrivate::updateBlockedStatus(q);
426 if (q->type() == Qt::Popup) {
428 QGuiApplicationPrivate::activatePopup(q);
430 QGuiApplicationPrivate::closePopup(q);
434 if (visible && (hasCursor || QGuiApplication::overrideCursor()))
439 platformWindow->setVisible(visible);
442 QHideEvent hideEvent;
443 QGuiApplication::sendEvent(q, &hideEvent);
447void QWindowPrivate::updateVisibility()
451 QWindow::Visibility old = visibility;
454 visibility = QWindow::Hidden;
455 else if (windowState & Qt::WindowMinimized)
456 visibility = QWindow::Minimized;
457 else if (windowState & Qt::WindowFullScreen)
458 visibility = QWindow::FullScreen;
459 else if (windowState & Qt::WindowMaximized)
460 visibility = QWindow::Maximized;
462 visibility = QWindow::Windowed;
464 if (visibility != old)
465 emit q->visibilityChanged(visibility);
468void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
475 QObjectList &siblings = q->parent()->d_ptr->children;
477 const qsizetype siblingCount = siblings.size() - 1;
478 if (siblingCount == 0)
481 const qsizetype currentPosition = siblings.indexOf(q);
482 Q_ASSERT(currentPosition >= 0);
484 const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
486 if (currentPosition == targetPosition)
489 siblings.move(currentPosition, targetPosition);
492bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen)
const
495 const QScreen *oldScreen = q->screen();
496 return oldScreen != newScreen && (platformWindow || !oldScreen)
497 && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen));
500void QWindowPrivate::disconnectFromScreen()
503 topLevelScreen =
nullptr;
506void QWindowPrivate::connectToScreen(QScreen *screen)
508 disconnectFromScreen();
509 topLevelScreen = screen;
512void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen)
515 emit q->screenChanged(newScreen);
516 for (QObject *child : q->children()) {
517 if (child->isWindowType())
518 static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen);
522void QWindowPrivate::setTopLevelScreen(QScreen *newScreen,
bool recreate)
527 qWarning() << q <<
'(' << newScreen <<
"): Attempt to set a screen on a child window.";
530 if (newScreen != topLevelScreen) {
531 const bool shouldRecreate = recreate && windowRecreationRequired(newScreen);
532 const bool shouldShow = visibilityOnDestroy && !topLevelScreen;
533 if (shouldRecreate && platformWindow)
535 connectToScreen(newScreen);
538 else if (newScreen && shouldRecreate)
540 emitScreenChangedRecursion(newScreen);
546void QWindowPrivate::create(
bool recursive)
553 const bool needsUpdate = updateRequestPending;
555 updateRequestPending =
false;
558 q->parent()->create();
560 if (platformWindow) {
569 if (q->isTopLevel()) {
570 if (QScreen *screen = screenForGeometry(geometry))
571 setTopLevelScreen(screen,
false);
574 const WId nativeHandle = q->property(kForeignWindowId).value<WId>();
576 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
577 platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
578 : platformIntegration->createPlatformWindow(q);
579 Q_ASSERT(platformWindow);
581 if (!platformWindow) {
582 qWarning() <<
"Failed to create platform window for" << q <<
"with flags" << q->flags();
586 platformWindow->initialize();
588 QObjectList childObjects = q->children();
589 for (
int i = 0; i < childObjects.size(); i ++) {
590 QObject *object = childObjects.at(i);
591 if (!object->isWindowType())
594 QWindow *childWindow =
static_cast<QWindow *>(object);
596 childWindow->d_func()->create(recursive);
601 if (childWindow->isVisible())
602 childWindow->setVisible(
true);
604 if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow)
605 childPlatformWindow->setParent(
this->platformWindow);
608 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
609 QGuiApplication::sendEvent(q, &e);
611 updateDevicePixelRatio();
617void QWindowPrivate::clearFocusObject()
624QRectF QWindowPrivate::closestAcceptableGeometry(
const QRectF &rect)
const
630void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember,
const QSize &size,
631 qxp::function_ref<
void()> funcWidthChanged,
632 qxp::function_ref<
void()> funcHeightChanged)
635 Q_ASSERT(oldSizeMember);
636 const QSize adjustedSize =
637 size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX));
638 if (*oldSizeMember == adjustedSize)
640 const bool widthChanged = adjustedSize.width() != oldSizeMember->width();
641 const bool heightChanged = adjustedSize.height() != oldSizeMember->height();
642 *oldSizeMember = adjustedSize;
644 if (platformWindow && q->isTopLevel())
645 platformWindow->propagateSizeHints();
653 if (minimumSize.width() <= maximumSize.width()
654 || minimumSize.height() <= maximumSize.height()) {
655 const QSize currentSize = q->size();
656 const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
657 q->resize(boundedSize);
662
663
664
665
666
667
668
669
670
671
672
673
674void QWindow::setSurfaceType(SurfaceType surfaceType)
677 d->surfaceType = surfaceType;
681
682
683
684
685QWindow::SurfaceType QWindow::surfaceType()
const
688 return d->surfaceType;
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709void QWindow::setVisible(
bool visible)
713 d->setVisible(visible);
716bool QWindow::isVisible()
const
724
725
726
727
728
729
730
731
732
733
734
735
736
737void QWindow::create()
744
745
746
747
748
749
750
751
752
753
754WId QWindow::winId()
const
758 if (!d->platformWindow)
759 const_cast<QWindow *>(
this)->create();
761 if (!d->platformWindow)
764 return d->platformWindow->winId();
768
769
770
771
772
773
774
775
776
777QWindow *QWindow::parent(AncestorMode mode)
const
780 return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() :
nullptr);
784
785
786
787
788
789
790
791
792
793void QWindow::setParent(QWindow *parent)
796 if (d->parentWindow == parent
798 && !(d->platformWindow && d->platformWindow->isEmbedded())) {
802 QScreen *oldScreen = screen();
803 QScreen *newScreen = parent ? parent->screen() : oldScreen;
804 if (d->windowRecreationRequired(newScreen)) {
805 qWarning() <<
this <<
'(' << parent <<
"): Cannot change screens (" << oldScreen << newScreen <<
')';
809 QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange);
810 QCoreApplication::sendEvent(
this, &parentAboutToChangeEvent);
812 const auto previousParent = d->parentWindow;
813 QObject::setParent(parent);
814 d->parentWindow = parent;
817 d->disconnectFromScreen();
819 d->connectToScreen(newScreen);
824 if (isVisible() && (!parent || parent->handle()))
827 if (d->platformWindow) {
831 d->platformWindow->setParent(parent ? parent->d_func()->platformWindow :
nullptr);
834 QGuiApplicationPrivate::updateBlockedStatus(
this);
836 if (previousParent) {
837 QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved,
this);
838 QCoreApplication::sendEvent(previousParent, &childRemovedEvent);
842 QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded,
this);
843 QCoreApplication::sendEvent(parent, &childAddedEvent);
846 QEvent parentChangedEvent(QEvent::ParentWindowChange);
847 QCoreApplication::sendEvent(
this, &parentChangedEvent);
849#if QT_CONFIG(accessibility)
850 if (!d->accessibleParent
851 && QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
852 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
853 QAccessible::updateAccessibility(&qaEvent);
863 if (parent && screen() != oldScreen)
864 d->emitScreenChangedRecursion(screen());
868
869
870bool QWindow::isTopLevel()
const
873 return d->parentWindow ==
nullptr;
877
878
879
880
881
882
883bool QWindow::isModal()
const
886 return d->modality != Qt::NonModal;
890
891
892
893
894
895
896
897
898
900Qt::WindowModality QWindow::modality()
const
906void QWindow::setModality(Qt::WindowModality modality)
909 if (d->modality == modality)
911 d->modality = modality;
912 emit modalityChanged(modality);
916
917
918
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946void QWindow::setFormat(
const QSurfaceFormat &format)
949 d->requestedFormat = format;
953
954
955
956
957
958
959
960
961
962QSurfaceFormat QWindow::requestedFormat()
const
965 return d->requestedFormat;
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985QSurfaceFormat QWindow::format()
const
988 if (d->platformWindow)
989 return d->platformWindow->format();
990 return d->requestedFormat;
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006void QWindow::setFlags(Qt::WindowFlags flags)
1009 if (d->windowFlags == flags)
1012 if (d->platformWindow)
1013 d->platformWindow->setWindowFlags(flags);
1015 d->windowFlags = flags;
1017 emit flagsChanged(
this->flags());
1020Qt::WindowFlags QWindow::flags()
const
1023 Qt::WindowFlags flags = d->windowFlags;
1025 if (d->platformWindow && d->platformWindow->isForeignWindow())
1026 flags |= Qt::ForeignWindow;
1032
1033
1034
1035
1036
1037
1038
1039void QWindow::setFlag(Qt::WindowType flag,
bool on)
1043 setFlags(d->windowFlags | flag);
1045 setFlags(d->windowFlags & ~flag);
1049
1050
1051
1052
1053
1054
1055
1056Qt::WindowType QWindow::type()
const
1058 return static_cast<Qt::WindowType>(
int(flags() & Qt::WindowType_Mask));
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072void QWindow::setTitle(
const QString &title)
1075 bool changed =
false;
1076 if (d->windowTitle != title) {
1077 d->windowTitle = title;
1080 if (d->platformWindow)
1081 d->platformWindow->setWindowTitle(title);
1083 emit windowTitleChanged(title);
1086QString QWindow::title()
const
1089 return d->windowTitle;
1093
1094
1095
1096
1097
1098
1099void QWindow::setFilePath(
const QString &filePath)
1102 d->windowFilePath = filePath;
1103 if (d->platformWindow)
1104 d->platformWindow->setWindowFilePath(filePath);
1108
1109
1110
1111
1112QString QWindow::filePath()
const
1115 return d->windowFilePath;
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129void QWindow::setIcon(
const QIcon &icon)
1132 d->windowIcon = icon;
1133 if (d->platformWindow)
1134 d->platformWindow->setWindowIcon(icon);
1135 QEvent e(QEvent::WindowIconChange);
1136 QCoreApplication::sendEvent(
this, &e);
1140
1141
1142
1143
1144QIcon QWindow::icon()
const
1147 if (d->windowIcon.isNull())
1148 return QGuiApplication::windowIcon();
1149 return d->windowIcon;
1153
1154
1155
1156
1157void QWindow::raise()
1161 d->updateSiblingPosition(QWindowPrivate::PositionTop);
1163 if (d->platformWindow)
1164 d->platformWindow->raise();
1168
1169
1170
1171
1172void QWindow::lower()
1176 d->updateSiblingPosition(QWindowPrivate::PositionBottom);
1178 if (d->platformWindow)
1179 d->platformWindow->lower();
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200bool QWindow::startSystemResize(Qt::Edges edges)
1203 if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize))
1206 const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge;
1207 const bool isCorner =
1208 edges == (Qt::TopEdge | Qt::LeftEdge) ||
1209 edges == (Qt::TopEdge | Qt::RightEdge) ||
1210 edges == (Qt::BottomEdge | Qt::RightEdge) ||
1211 edges == (Qt::BottomEdge | Qt::LeftEdge);
1213 if (Q_UNLIKELY(!isSingleEdge && !isCorner)) {
1214 qWarning() <<
"Invalid edges" << edges <<
"passed to QWindow::startSystemResize, ignoring.";
1218 return d->platformWindow->startSystemResize(edges);
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238bool QWindow::startSystemMove()
1241 if (Q_UNLIKELY(!isVisible() || !d->platformWindow))
1244 return d->platformWindow->startSystemMove();
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261void QWindow::setOpacity(qreal level)
1264 if (level == d->opacity)
1267 if (d->platformWindow) {
1268 d->platformWindow->setOpacity(level);
1269 emit opacityChanged(level);
1273qreal QWindow::opacity()
const
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289void QWindow::setMask(
const QRegion ®ion)
1292 if (d->platformWindow)
1293 d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region,
this));
1298
1299
1300
1301
1302
1303QRegion QWindow::mask()
const
1310
1311
1312
1313
1314void QWindow::requestActivate()
1317 if (flags() & Qt::WindowDoesNotAcceptFocus) {
1318 qWarning() <<
"requestActivate() called for " <<
this <<
" which has Qt::WindowDoesNotAcceptFocus set.";
1321 if (d->platformWindow)
1322 d->platformWindow->requestActivateWindow();
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336bool QWindow::isExposed()
const
1343
1344
1345
1346
1347
1348
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362bool QWindow::isActive()
const
1365 if (!d->platformWindow)
1368 QWindow *focus = QGuiApplication::focusWindow();
1377 if (QWindow *p = parent(IncludeTransients))
1378 return p->isActive();
1380 return isAncestorOf(focus);
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
1405 if (d->contentOrientation == orientation)
1407 if (d->platformWindow)
1408 d->platformWindow->handleContentOrientationChange(orientation);
1409 d->contentOrientation = orientation;
1410 emit contentOrientationChanged(orientation);
1413Qt::ScreenOrientation QWindow::contentOrientation()
const
1416 return d->contentOrientation;
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434qreal QWindow::devicePixelRatio()
const
1437 return d->devicePixelRatio;
1441
1442
1443
1444
1445bool QWindowPrivate::updateDevicePixelRatio()
1449 const qreal newDevicePixelRatio = [
this, q]{
1451 return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q);
1456 if (
auto *screen = q->screen())
1457 return screen->devicePixelRatio();
1460 return qGuiApp->devicePixelRatio();
1463 if (newDevicePixelRatio == devicePixelRatio)
1466 devicePixelRatio = newDevicePixelRatio;
1467 QEvent dprChangeEvent(QEvent::DevicePixelRatioChange);
1468 QGuiApplication::sendEvent(q, &dprChangeEvent);
1472Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state)
1474 if (state & Qt::WindowMinimized)
1475 return Qt::WindowMinimized;
1476 else if (state & Qt::WindowFullScreen)
1477 return Qt::WindowFullScreen;
1478 else if (state & Qt::WindowMaximized)
1479 return Qt::WindowMaximized;
1480 return Qt::WindowNoState;
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493void QWindow::setWindowState(Qt::WindowState state)
1495 setWindowStates(state);
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514void QWindow::setWindowStates(Qt::WindowStates state)
1517 if (state & Qt::WindowActive) {
1518 qWarning(
"QWindow::setWindowStates does not accept Qt::WindowActive");
1519 state &= ~Qt::WindowActive;
1522 if (d->platformWindow)
1523 d->platformWindow->setWindowState(state);
1525 auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1526 d->windowState = state;
1527 auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState);
1528 if (newEffectiveState != originalEffectiveState)
1529 emit windowStateChanged(newEffectiveState);
1531 d->updateVisibility();
1535
1536
1537
1538
1539Qt::WindowState QWindow::windowState()
const
1542 return QWindowPrivate::effectiveState(d->windowState);
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556Qt::WindowStates QWindow::windowStates()
const
1559 return d->windowState;
1563
1564
1565
1566
1567
1568
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584void QWindow::setTransientParent(QWindow *parent)
1587 if (parent && !parent->isTopLevel()) {
1588 qWarning() << parent <<
"must be a top level window.";
1591 if (parent ==
this) {
1592 qWarning() <<
"transient parent" << parent <<
"cannot be same as window";
1596 d->transientParent = parent;
1598 QGuiApplicationPrivate::updateBlockedStatus(
this);
1599 emit transientParentChanged(parent);
1602QWindow *QWindow::transientParent()
const
1605 return d->transientParent.data();
1609
1610
1611
1612
1613
1614void QWindowPrivate::setTransientParent(QWindow *parent)
1617 q->setTransientParent(parent);
1618 transientParentPropertySet =
true;
1622
1623
1624
1625
1626
1627
1628
1629
1632
1633
1634
1635bool QWindow::isAncestorOf(
const QWindow *child, AncestorMode mode)
const
1637 if (child->parent() ==
this || (mode == IncludeTransients && child->transientParent() ==
this))
1640 if (QWindow *parent = child->parent(mode)) {
1641 if (isAncestorOf(parent, mode))
1643 }
else if (handle() && child->handle()) {
1644 if (handle()->isAncestorOf(child->handle()))
1652
1653
1654
1655
1656QSize QWindow::minimumSize()
const
1659 return d->minimumSize;
1663
1664
1665
1666
1667QSize QWindow::maximumSize()
const
1670 return d->maximumSize;
1674
1675
1676
1677
1678QSize QWindow::baseSize()
const
1685
1686
1687
1688
1689QSize QWindow::sizeIncrement()
const
1692 return d->sizeIncrement;
1696
1697
1698
1699
1700
1701
1702void QWindow::setMinimumSize(
const QSize &size)
1706 &d->minimumSize, size, [
this, d]() { emit minimumWidthChanged(d->minimumSize.width()); },
1707 [
this, d]() { emit minimumHeightChanged(d->minimumSize.height()); });
1711
1712
1713
1714void QWindow::setX(
int arg)
1718 setGeometry(QRect(arg, y(), width(), height()));
1720 d->positionAutomatic =
false;
1724
1725
1726
1727void QWindow::setY(
int arg)
1731 setGeometry(QRect(x(), arg, width(), height()));
1733 d->positionAutomatic =
false;
1737
1738
1739
1740void QWindow::setWidth(
int w)
1742 resize(w, height());
1746
1747
1748
1749void QWindow::setHeight(
int h)
1755
1756
1757
1758void QWindow::setMinimumWidth(
int w)
1760 setMinimumSize(QSize(w, minimumHeight()));
1764
1765
1766
1767void QWindow::setMinimumHeight(
int h)
1769 setMinimumSize(QSize(minimumWidth(), h));
1773
1774
1775
1776
1777
1778
1779void QWindow::setMaximumSize(
const QSize &size)
1783 &d->maximumSize, size, [
this, d]() { emit maximumWidthChanged(d->maximumSize.width()); },
1784 [
this, d]() { emit maximumHeightChanged(d->maximumSize.height()); });
1788
1789
1790
1791void QWindow::setMaximumWidth(
int w)
1793 setMaximumSize(QSize(w, maximumHeight()));
1797
1798
1799
1800void QWindow::setMaximumHeight(
int h)
1802 setMaximumSize(QSize(maximumWidth(), h));
1806
1807
1808
1809
1810
1811
1812
1813void QWindow::setBaseSize(
const QSize &size)
1816 if (d->baseSize == size)
1819 if (d->platformWindow && isTopLevel())
1820 d->platformWindow->propagateSizeHints();
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837void QWindow::setSizeIncrement(
const QSize &size)
1840 if (d->sizeIncrement == size)
1842 d->sizeIncrement = size;
1843 if (d->platformWindow && isTopLevel())
1844 d->platformWindow->propagateSizeHints();
1848
1849
1850
1851
1852
1853
1854
1855void QWindow::setGeometry(
int posx,
int posy,
int w,
int h)
1857 setGeometry(QRect(posx, posy, w, h));
1861
1862
1863
1864
1865
1866
1867void QWindow::setGeometry(
const QRect &rect)
1870 d->positionAutomatic =
false;
1871 const QRect oldRect = geometry();
1872 if (rect == oldRect)
1875 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1876 if (d->platformWindow) {
1878 QScreen *newScreen = d->screenForGeometry(rect);
1879 d->platformWindow->setGeometry(QHighDpi::toNativeGlobalPosition(rect, newScreen));
1881 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect,
this));
1886 if (rect.x() != oldRect.x())
1887 emit xChanged(rect.x());
1888 if (rect.y() != oldRect.y())
1889 emit yChanged(rect.y());
1890 if (rect.width() != oldRect.width())
1891 emit widthChanged(rect.width());
1892 if (rect.height() != oldRect.height())
1893 emit heightChanged(rect.height());
1898
1899
1900
1901
1902
1903QScreen *QWindowPrivate::screenForGeometry(
const QRect &newGeometry)
const
1906 QScreen *currentScreen = q->screen();
1907 QScreen *fallback = currentScreen;
1908 QPoint center = newGeometry.center();
1909 if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) {
1910 const auto screens = currentScreen->virtualSiblings();
1911 for (QScreen* screen : screens) {
1912 if (screen->geometry().contains(center))
1914 if (screen->geometry().intersects(newGeometry))
1923
1924
1925
1926
1927
1928
1929QRect QWindow::geometry()
const
1932 if (d->platformWindow) {
1933 const auto nativeGeometry = d->platformWindow->geometry();
1934 return QHighDpi::fromNativeWindowGeometry(nativeGeometry,
this);
1940
1941
1942
1943
1944QMargins QWindow::frameMargins()
const
1947 if (d->platformWindow)
1948 return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(),
this);
1953
1954
1955
1956
1957
1958
1959QRect QWindow::frameGeometry()
const
1962 if (d->platformWindow) {
1963 QMargins m = frameMargins();
1964 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(),
this).adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1970
1971
1972
1973
1974
1975
1976QPoint QWindow::framePosition()
const
1979 if (d->platformWindow) {
1980 QMargins margins = frameMargins();
1981 return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(),
this) - QPoint(margins.left(), margins.top());
1983 return d->geometry.topLeft();
1987
1988
1989
1990
1991
1992
1993void QWindow::setFramePosition(
const QPoint &point)
1996 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1997 d->positionAutomatic =
false;
1998 if (d->platformWindow) {
1999 d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()),
this));
2001 d->geometry.moveTopLeft(point);
2006
2007
2008
2009
2010
2011
2012
2013
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038QMargins QWindow::safeAreaMargins()
const
2041 if (d->platformWindow)
2042 return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(),
this);
2047
2048
2049
2050
2051
2052
2053
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069void QWindow::setPosition(
const QPoint &pt)
2071 setGeometry(QRect(pt, size()));
2075
2076
2077
2078
2079
2080
2081void QWindow::setPosition(
int posx,
int posy)
2083 setPosition(QPoint(posx, posy));
2087
2088
2089
2090
2091
2092
2093
2094
2095
2098
2099
2100
2101
2102
2105
2106
2107
2108
2109
2110
2111
2112void QWindow::resize(
int w,
int h)
2114 resize(QSize(w, h));
2118
2119
2120
2121
2122void QWindow::resize(
const QSize &newSize)
2126 const QSize oldSize = size();
2127 if (newSize == oldSize)
2130 d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
2131 if (d->platformWindow) {
2138 const QRect nativeGeometry = d->platformWindow->geometry();
2139 const QPlatformScreen *targetScreen = screen()->handle()->screenForPosition(nativeGeometry.center());
2140 d->platformWindow->setGeometry(QRect(nativeGeometry.topLeft(),
2141 QHighDpi::toNativePixels(newSize, targetScreen->screen())));
2143 d->platformWindow->setGeometry(
2144 QHighDpi::toNativeWindowGeometry(QRect(position(), newSize),
this));
2147 d->geometry.setSize(newSize);
2148 if (newSize.width() != oldSize.width())
2149 emit widthChanged(newSize.width());
2150 if (newSize.height() != oldSize.height())
2151 emit heightChanged(newSize.height());
2156
2157
2158
2159
2160void QWindow::destroy()
2163 if (!d->platformWindow)
2166 if (d->platformWindow->isForeignWindow())
2172void QWindowPrivate::destroy()
2174 if (!platformWindow)
2178 QObjectList childrenWindows = q->children();
2179 for (
int i = 0; i < childrenWindows.size(); i++) {
2180 QObject *object = childrenWindows.at(i);
2181 if (object->isWindowType()) {
2182 QWindow *w =
static_cast<QWindow*>(object);
2183 qt_window_private(w)->destroy();
2187 bool wasVisible = q->isVisible();
2188 visibilityOnDestroy = wasVisible && platformWindow;
2190 q->setVisible(
false);
2201 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
2202 QGuiApplication::sendEvent(q, &e);
2207 delete std::exchange(platformWindow,
nullptr);
2209 if (QGuiApplicationPrivate::focus_window == q)
2210 QGuiApplicationPrivate::focus_window = q->parent();
2211 if (QGuiApplicationPrivate::currentMouseWindow == q)
2212 QGuiApplicationPrivate::currentMouseWindow = q->parent();
2213 if (QGuiApplicationPrivate::currentMousePressWindow == q)
2214 QGuiApplicationPrivate::currentMousePressWindow = q->parent();
2216 for (
int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i)
2217 if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q)
2218 QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent();
2220 resizeEventPending =
true;
2221 receivedExpose =
false;
2227 positionPolicy = QWindowPrivate::WindowFrameExclusive;
2231
2232
2233
2234
2235QPlatformWindow *QWindow::handle()
const
2238 return d->platformWindow;
2242
2243
2244
2245
2246QPlatformSurface *QWindow::surfaceHandle()
const
2249 return d->platformWindow;
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262bool QWindow::setKeyboardGrabEnabled(
bool grab)
2265 if (d->platformWindow)
2266 return d->platformWindow->setKeyboardGrabEnabled(grab);
2271
2272
2273
2274
2275
2276
2277
2278
2279bool QWindow::setMouseGrabEnabled(
bool grab)
2282 if (d->platformWindow)
2283 return d->platformWindow->setMouseGrabEnabled(grab);
2288
2289
2290
2291
2292
2293
2294QScreen *QWindow::screen()
const
2297 return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data();
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313void QWindow::setScreen(QScreen *newScreen)
2317 newScreen = QGuiApplication::primaryScreen();
2318 d->setTopLevelScreen(newScreen, newScreen !=
nullptr);
2322
2323
2324
2325
2326
2327
2330
2331
2332
2333
2334QAccessibleInterface *QWindow::accessibleRoot()
const
2339#if QT_CONFIG(accessibility)
2341
2342
2343
2344
2345
2346
2347
2348
2349void QWindowPrivate::setAccessibleParent(QObject *parent)
2353 if (accessibleParent == parent)
2356 accessibleParent = parent;
2358 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) {
2359 QAccessibleEvent event(q, QAccessible::ParentChanged);
2360 QAccessible::updateAccessibility(&event);
2366
2367
2368
2369
2370
2371
2372
2375
2376
2377
2378QObject *QWindow::focusObject()
const
2380 return const_cast<QWindow *>(
this);
2384
2385
2386
2387
2388
2389
2390
2391
2397 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
2398 Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags);
2399 if (defaultState == Qt::WindowFullScreen)
2401 else if (defaultState == Qt::WindowMaximized)
2409
2410
2411
2412
2413
2414
2421
2422
2423
2424
2425
2426
2427
2428void QWindow::showMinimized()
2430 setWindowStates(Qt::WindowMinimized);
2435
2436
2437
2438
2439
2440
2441
2442void QWindow::showMaximized()
2444 setWindowStates(Qt::WindowMaximized);
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459void QWindow::showFullScreen()
2461 setWindowStates(Qt::WindowFullScreen);
2463#if !defined Q_OS_QNX
2470
2471
2472
2473
2474
2475
2476
2477void QWindow::showNormal()
2479 setWindowStates(Qt::WindowNoState);
2484
2485
2486
2487
2488
2489
2490
2491
2492bool QWindow::close()
2502 if (!d->platformWindow) {
2505 if (QGuiApplicationPrivate::activePopupWindow() ==
this)
2506 QGuiApplicationPrivate::closePopup(
this);
2512 QPointer guard(
this);
2514 bool success = d->platformWindow->close();
2521bool QWindowPrivate::participatesInLastWindowClosed()
const
2525 if (!q->isTopLevel())
2531 if (q->type() == Qt::ToolTip)
2536 if (q->transientParent())
2542bool QWindowPrivate::treatAsVisible()
const
2545 return q->isVisible();
2549
2550
2551
2552const QWindow *QWindowPrivate::forwardToPopup(QEvent *event,
const QWindow *)
2555 qCDebug(lcPopup) <<
"checking for popup alternative to" << q <<
"for" << event
2556 <<
"active popup?" << QGuiApplicationPrivate::activePopupWindow();
2557 QWindow *ret =
nullptr;
2558 if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) {
2559 if (q == popupWindow)
2561 if (event->isPointerEvent()) {
2563 QScopedPointer<QPointerEvent> pointerEvent(
static_cast<QPointerEvent *>(event)->clone());
2564 for (
int i = 0; i < pointerEvent->pointCount(); ++i) {
2565 QEventPoint &eventPoint = pointerEvent->point(i);
2566 const QPoint globalPos = eventPoint.globalPosition().toPoint();
2567 const QPointF mapped = popupWindow->mapFromGlobal(globalPos);
2568 QMutableEventPoint::setPosition(eventPoint, mapped);
2569 QMutableEventPoint::setScenePosition(eventPoint, mapped);
2573
2574
2575 if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) {
2576 event->setAccepted(pointerEvent->isAccepted());
2577 if (pointerEvent->isAccepted())
2580 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2581 <<
"handled?" << (ret !=
nullptr)
2582 <<
"accepted?" << event->isAccepted();
2584 }
else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
2585 if (QCoreApplication::sendSpontaneousEvent(popupWindow, event))
2587 qCDebug(lcPopup) << q <<
"forwarded" << event->type() <<
"to popup" << popupWindow
2588 <<
"handled?" << (ret !=
nullptr)
2589 <<
"accepted?" << event->isAccepted();
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614void QWindow::exposeEvent(QExposeEvent *ev)
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633void QWindow::paintEvent(QPaintEvent *ev)
2639
2640
2641void QWindow::moveEvent(QMoveEvent *ev)
2647
2648
2649
2650
2651
2652
2653void QWindow::resizeEvent(QResizeEvent *ev)
2659
2660
2661
2662
2663
2664
2665
2666void QWindow::showEvent(QShowEvent *ev)
2672
2673
2674
2675
2676
2677void QWindow::hideEvent(QHideEvent *ev)
2683
2684
2685
2686
2687
2688
2689
2690void QWindow::closeEvent(QCloseEvent *ev)
2696
2697
2698
2699
2700
2701
2702bool QWindow::event(QEvent *ev)
2705 switch (ev->type()) {
2706 case QEvent::MouseMove:
2707 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
2710 case QEvent::MouseButtonPress: {
2711 auto *me =
static_cast<QMouseEvent*>(ev);
2712 mousePressEvent(me);
2713 if (!ev->isAccepted())
2714 d->maybeSynthesizeContextMenuEvent(me);
2718 case QEvent::MouseButtonRelease: {
2719 auto *me =
static_cast<QMouseEvent*>(ev);
2720 mouseReleaseEvent(me);
2721 if (!ev->isAccepted())
2722 d->maybeSynthesizeContextMenuEvent(me);
2726 case QEvent::MouseButtonDblClick:
2727 mouseDoubleClickEvent(
static_cast<QMouseEvent*>(ev));
2730 case QEvent::TouchBegin:
2731 case QEvent::TouchUpdate:
2732 case QEvent::TouchEnd:
2733 case QEvent::TouchCancel:
2734 touchEvent(
static_cast<QTouchEvent *>(ev));
2738 moveEvent(
static_cast<QMoveEvent*>(ev));
2741 case QEvent::Resize:
2742 resizeEvent(
static_cast<QResizeEvent*>(ev));
2745 case QEvent::KeyPress:
2746 keyPressEvent(
static_cast<QKeyEvent *>(ev));
2749 case QEvent::KeyRelease:
2750 keyReleaseEvent(
static_cast<QKeyEvent *>(ev));
2753 case QEvent::FocusIn: {
2754 focusInEvent(
static_cast<QFocusEvent *>(ev));
2755#if QT_CONFIG(accessibility)
2756 QAccessible::State state;
2757 state.active =
true;
2758 QAccessibleStateChangeEvent event(
this, state);
2759 QAccessible::updateAccessibility(&event);
2763 case QEvent::FocusOut: {
2764 focusOutEvent(
static_cast<QFocusEvent *>(ev));
2765#if QT_CONFIG(accessibility)
2766 QAccessible::State state;
2767 state.active =
true;
2768 QAccessibleStateChangeEvent event(
this, state);
2769 QAccessible::updateAccessibility(&event);
2773#if QT_CONFIG(wheelevent)
2775 wheelEvent(
static_cast<QWheelEvent*>(ev));
2779 case QEvent::Close: {
2781 const bool wasVisible = d->treatAsVisible();
2782 const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed();
2785 QPointer<QWindow> deletionGuard(
this);
2786 closeEvent(
static_cast<QCloseEvent*>(ev));
2788 if (ev->isAccepted()) {
2791 if (wasVisible && participatesInLastWindowClosed)
2792 QGuiApplicationPrivate::instance()->maybeLastWindowClosed();
2798 case QEvent::Expose:
2799 exposeEvent(
static_cast<QExposeEvent *>(ev));
2803 paintEvent(
static_cast<QPaintEvent *>(ev));
2807 showEvent(
static_cast<QShowEvent *>(ev));
2811 hideEvent(
static_cast<QHideEvent *>(ev));
2814 case QEvent::ApplicationWindowIconChange:
2818#if QT_CONFIG(tabletevent)
2819 case QEvent::TabletPress:
2820 case QEvent::TabletMove:
2821 case QEvent::TabletRelease:
2822 tabletEvent(
static_cast<QTabletEvent *>(ev));
2826 case QEvent::PlatformSurface: {
2827 if ((
static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
2829 QOpenGLContext *context = QOpenGLContext::currentContext();
2830 if (context && context->surface() ==
static_cast<QSurface *>(
this))
2831 context->doneCurrent();
2838 return QObject::event(ev);
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event)
2884#ifndef QT_NO_CONTEXTMENU
2885 if (event->button() == Qt::RightButton
2886 && event->type() == QGuiApplicationPrivate::contextMenuEventType()) {
2887 QContextMenuEvent e(event->scenePosition().toPoint(), event->globalPosition().toPoint(),
2888 event->modifiers(), event->pointingDevice());
2889 qCDebug(lcPopup) <<
"synthesized after"
2890 << (event->isAccepted() ?
"ACCEPTED (legacy behavior)" :
"ignored")
2891 << event->type() <<
":" << &e;
2892 QCoreApplication::forwardEvent(q_func(), &e, event);
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926void QWindow::requestUpdate()
2928 Q_ASSERT_X(QThread::isMainThread(),
2929 "QWindow",
"Updates can only be scheduled from the GUI (main) thread");
2932 if (d->updateRequestPending || !d->platformWindow)
2934 d->updateRequestPending =
true;
2935 d->platformWindow->requestUpdate();
2939
2940
2941
2942
2943void QWindow::keyPressEvent(QKeyEvent *ev)
2949
2950
2951
2952
2953void QWindow::keyReleaseEvent(QKeyEvent *ev)
2959
2960
2961
2962
2963
2964
2965void QWindow::focusInEvent(QFocusEvent *ev)
2971
2972
2973
2974
2975
2976
2977void QWindow::focusOutEvent(QFocusEvent *ev)
2983
2984
2985
2986
2987void QWindow::mousePressEvent(QMouseEvent *ev)
2993
2994
2995
2996
2997void QWindow::mouseReleaseEvent(QMouseEvent *ev)
3003
3004
3005
3006
3007void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
3013
3014
3015void QWindow::mouseMoveEvent(QMouseEvent *ev)
3020#if QT_CONFIG(wheelevent)
3022
3023
3024void QWindow::wheelEvent(QWheelEvent *ev)
3031
3032
3033void QWindow::touchEvent(QTouchEvent *ev)
3038#if QT_CONFIG(tabletevent)
3040
3041
3042
3043
3044
3045void QWindow::tabletEvent(QTabletEvent *ev)
3052
3053
3054
3055
3056
3057
3058
3060bool QWindow::nativeEvent(
const QByteArray &eventType,
void *message, qintptr *result)
3062 Q_UNUSED(eventType);
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078QPointF QWindow::mapToGlobal(
const QPointF &pos)
const
3082 if (d->platformWindow
3083 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3084 return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos,
this)),
this);
3087 if (!QHighDpiScaling::isActive())
3088 return pos + d->globalPosition();
3096 QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos,
this);
3100 QPointF nativeWindowGlobalPos = d->platformWindow
3101 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3102 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3103 QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos;
3104 QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos,
this);
3105 return deviceIndependentGlobalPos;
3109
3110
3111QPoint QWindow::mapToGlobal(
const QPoint &pos)
const
3113 return mapToGlobal(QPointF(pos)).toPoint();
3117
3118
3119
3120
3121
3122
3123
3124
3125QPointF QWindow::mapFromGlobal(
const QPointF &pos)
const
3129 if (d->platformWindow
3130 && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) {
3131 return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos,
this)),
this);
3134 if (!QHighDpiScaling::isActive())
3135 return pos - d->globalPosition();
3139 QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos,
this);
3143 QPointF nativeWindowGlobalPos = d->platformWindow
3144 ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF()
3145 : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()),
this);
3146 QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos;
3147 QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos,
this);
3148 return deviceIndependentLocalPos;
3152
3153
3154QPoint QWindow::mapFromGlobal(
const QPoint &pos)
const
3156 return QWindow::mapFromGlobal(QPointF(pos)).toPoint();
3159QPoint QWindowPrivate::globalPosition()
const
3162 QPoint offset = q->position();
3163 for (
const QWindow *p = q->parent(); p; p = p->parent()) {
3164 QPlatformWindow *pw = p->handle();
3165 if (pw && (pw->isForeignWindow() || pw->isEmbedded())) {
3167 offset += p->mapToGlobal(QPoint(0, 0));
3170 offset += p->position();
3178 return window->d_func();
3181QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode)
const
3185 QWindow *window =
const_cast<QWindow *>(q);
3188 QWindow *parent = window->parent(mode);
3199
3200
3201
3202
3203
3204
3209#if QT_CONFIG(accessibility)
3211
3212
3213
3214
3215
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244QWindow *QWindow::fromWinId(WId id)
3246 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
3247 qWarning(
"QWindow::fromWinId(): platform plugin does not support foreign windows.");
3251 QWindow *window =
new QForeignWindow;
3255 window->setProperty(kForeignWindowId, id);
3258 if (!window->handle()) {
3267
3268
3269
3270
3271
3272
3273
3274
3275
3277void QWindow::alert(
int msec)
3280 if (!d->platformWindow || d->platformWindow->isAlertState() || isActive())
3282 d->platformWindow->setAlertState(
true);
3283 if (d->platformWindow->isAlertState() && msec)
3284 QTimer::singleShot(msec,
this, SLOT(_q_clearAlert()));
3287void QWindowPrivate::_q_clearAlert()
3289 if (platformWindow && platformWindow->isAlertState())
3290 platformWindow->setAlertState(
false);
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314void QWindow::setCursor(
const QCursor &cursor)
3317 d->setCursor(&cursor);
3321
3322
3323void QWindow::unsetCursor()
3326 d->setCursor(
nullptr);
3330
3331
3332
3333
3334QCursor QWindow::cursor()
const
3340void QWindowPrivate::setCursor(
const QCursor *newCursor)
3345 const Qt::CursorShape newShape = newCursor->shape();
3346 if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape())
3348 cursor = *newCursor;
3353 cursor = QCursor(Qt::ArrowCursor);
3357 if (applyCursor()) {
3358 QEvent event(QEvent::CursorChange);
3359 QGuiApplication::sendEvent(q, &event);
3364bool QWindowPrivate::applyCursor()
3367 if (QScreen *screen = q->screen()) {
3368 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
3369 if (!platformWindow)
3371 QCursor *c = QGuiApplication::overrideCursor();
3372 if (c !=
nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor))
3374 if (!c && hasCursor)
3376 platformCursor->changeCursor(c, q);
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3397void *QWindow::resolveInterface(
const char *name,
int revision)
const
3399 using namespace QNativeInterface::Private;
3401 auto *platformWindow = handle();
3402 Q_UNUSED(platformWindow);
3406#if defined(Q_OS_WIN)
3407 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow);
3411 QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow);
3414#if defined(Q_OS_MACOS)
3415 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
3418#if QT_CONFIG(wayland)
3419 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
3422#if defined(Q_OS_WASM)
3423 QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
3426#if defined(Q_OS_HARMONY)
3427 QT_NATIVE_INTERFACE_RETURN_IF(QNativeInterface::QHarmonyWindow, platformWindow);
3433#ifndef QT_NO_DEBUG_STREAM
3434QDebug operator<<(QDebug debug,
const QWindow *window)
3436 QDebugStateSaver saver(debug);
3439 debug << window->metaObject()->className() <<
'(' << (
const void *)window;
3440 if (!window->objectName().isEmpty())
3441 debug <<
", name=" << window->objectName();
3442 if (debug.verbosity() > 2) {
3443 const QRect geometry = window->geometry();
3444 if (window->isVisible())
3445 debug <<
", visible";
3446 if (window->isExposed())
3447 debug <<
", exposed";
3448 debug <<
", state=" << window->windowState()
3449 <<
", type=" << window->type() <<
", flags=" << window->flags()
3450 <<
", surface type=" << window->surfaceType();
3451 if (window->isTopLevel())
3452 debug <<
", toplevel";
3453 debug <<
", " << geometry.width() <<
'x' << geometry.height()
3454 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
3455 const QMargins margins = window->frameMargins();
3456 if (!margins.isNull())
3457 debug <<
", margins=" << margins;
3458 const QMargins safeAreaMargins = window->safeAreaMargins();
3459 if (!safeAreaMargins.isNull())
3460 debug <<
", safeAreaMargins=" << safeAreaMargins;
3461 debug <<
", devicePixelRatio=" << window->devicePixelRatio();
3462 if (
const QPlatformWindow *platformWindow = window->handle())
3463 debug <<
", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec;
3464 if (
const QScreen *screen = window->screen())
3465 debug <<
", on " << screen->name();
3469 debug <<
"QWindow(0x0)";
3475#if QT_CONFIG(vulkan) || defined(Q_QDOC)
3478
3479
3480
3481
3482void QWindow::setVulkanInstance(QVulkanInstance *instance)
3485 d->vulkanInstance = instance;
3489
3490
3491QVulkanInstance *QWindow::vulkanInstance()
const
3494 return d->vulkanInstance;
3501#include "moc_qwindow.cpp"
3502#include "qwindow.moc"
Combined button and popup list for selecting options.
static constexpr auto kForeignWindowId