100#include <private/qvulkandefaultinstance_p.h>
104#include <QtCore/QThreadPool>
107#include <qtgui_tracepoints_p.h>
109#include <private/qtools_p.h>
118using namespace Qt::StringLiterals;
119using namespace QtMiscUtils;
122#define CHECK_QAPP_INSTANCE(...)
123 if (Q_LIKELY(QCoreApplication::instance())) {
125 qWarning("Must construct a QGuiApplication first.");
132Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
133Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
135Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
141Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
143Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
144 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
146Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
148Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
153Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
170Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
177Q_CONSTINIT
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
178Q_CONSTINIT
static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
181Q_DECL_DEPRECATED_X(
"Use QGuiApplicationPrivate::instance() instead")
182Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self =
nullptr;
184Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
186#ifndef QT_NO_CLIPBOARD
190Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
192Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
193Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
194Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
197Q_CONSTINIT
static QBasicMutex applicationFontMutex;
200Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
201Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
205Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
206Q_CONSTINIT QBasicAtomicInt QGuiApplicationPrivate::m_primaryScreenDpis = Q_BASIC_ATOMIC_INITIALIZER(0);
208Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
210Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
213#if QT_CONFIG(animation)
214extern void qRegisterGuiGetInterpolator();
219 return force_reverse ^
220 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
221 "Translate this string to the string 'LTR' in left-to-right"
222 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
223 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
228 if (!QGuiApplicationPrivate::app_font) {
229 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
230 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
231 QGuiApplicationPrivate::app_font =
new QFont(*font);
233 if (!QGuiApplicationPrivate::app_font)
234 QGuiApplicationPrivate::app_font =
235 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
240 delete QGuiApplicationPrivate::app_font;
241 QGuiApplicationPrivate::app_font =
nullptr;
246 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
247 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
250#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
251static bool checkNeedPortalSupport()
254 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
262#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
282 const qsizetype size = a.size();
287 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
289 else if (isAsciiDigit(*op))
294 const int numberPos = pos;
295 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
298 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
299 return ok ? result : -1;
306 for (
int i = 0; i < 4; ++i) {
308 const int value = nextGeometryToken(a, pos, &op);
320 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
324 result.corner = Qt::TopRightCorner;
333 QRect windowGeometry = window->frameGeometry();
334 QSize size = windowGeometry.size();
336 const QSize windowMinimumSize = window->minimumSize();
337 const QSize windowMaximumSize = window->maximumSize();
339 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
341 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
342 window->resize(size);
345 const QRect availableGeometry = window->screen()->virtualGeometry();
346 QPoint topLeft = windowGeometry.topLeft();
348 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
350 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
353 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
355 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
357 window->setFramePosition(topLeft);
364
365
366
367
368
369
370
371
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
497
498
499
500
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
657QGuiApplication::QGuiApplication(
int &argc,
char **argv)
659QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
661 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
665 QCoreApplicationPrivate::eventDispatcher->startingUp();
669
670
671QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
672 : QCoreApplication(p)
677
678
679QGuiApplication::~QGuiApplication()
681 Q_D(QGuiApplication);
683 qt_call_post_routines();
685 d->eventDispatcher->closingDown();
686 d->eventDispatcher =
nullptr;
688#ifndef QT_NO_CLIPBOARD
689 delete QGuiApplicationPrivate::qt_clipboard;
690 QGuiApplicationPrivate::qt_clipboard =
nullptr;
693#ifndef QT_NO_SESSIONMANAGER
694 delete d->session_manager;
695 d->session_manager =
nullptr;
698 QGuiApplicationPrivate::clearPalette();
699 QFontDatabase::removeAllApplicationFonts();
702 d->cursor_list.clear();
705#if QT_CONFIG(qtgui_threadpool)
707 QThreadPool *guiThreadPool =
nullptr;
709 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
714 guiThreadPool->waitForDone();
715 delete guiThreadPool;
719 delete QGuiApplicationPrivate::app_icon;
720 QGuiApplicationPrivate::app_icon =
nullptr;
721 delete QGuiApplicationPrivate::platform_name;
722 QGuiApplicationPrivate::platform_name =
nullptr;
723 delete QGuiApplicationPrivate::displayName;
724 QGuiApplicationPrivate::displayName =
nullptr;
725 delete QGuiApplicationPrivate::m_inputDeviceManager;
726 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
727 delete QGuiApplicationPrivate::desktopFileName;
728 QGuiApplicationPrivate::desktopFileName =
nullptr;
729 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
730 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
731 QGuiApplicationPrivate::lastCursorPosition.reset();
732 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
733 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
734 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
735 QGuiApplicationPrivate::currentDragWindow =
nullptr;
736 QGuiApplicationPrivate::tabletDevicePoints.clear();
737 QGuiApplicationPrivate::m_primaryScreenDpis.storeRelaxed(0);
740QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
741 : QCoreApplicationPrivate(argc, argv),
742 inputMethod(
nullptr),
743 lastTouchType(QEvent::TouchEnd)
746 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
this;)
748 application_type = QCoreApplicationPrivate::Gui;
749#ifndef QT_NO_SESSIONMANAGER
750 is_session_restored =
false;
751 is_saving_session =
false;
756
757
758
759
760
761
762
763
764
765
766
767void QGuiApplication::setApplicationDisplayName(
const QString &name)
769 if (!QGuiApplicationPrivate::displayName) {
770 QGuiApplicationPrivate::displayName =
new QString(name);
772 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
773 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
775 if (*QGuiApplicationPrivate::displayName != applicationName())
776 emit
qGuiApp->applicationDisplayNameChanged();
778 }
else if (name != *QGuiApplicationPrivate::displayName) {
779 *QGuiApplicationPrivate::displayName = name;
781 emit
qGuiApp->applicationDisplayNameChanged();
785QString QGuiApplication::applicationDisplayName()
787 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809void QGuiApplication::setBadgeNumber(qint64 number)
811 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830void QGuiApplication::setDesktopFileName(
const QString &name)
832 if (!QGuiApplicationPrivate::desktopFileName)
833 QGuiApplicationPrivate::desktopFileName =
new QString;
834 *QGuiApplicationPrivate::desktopFileName = name;
835 if (name.endsWith(QLatin1String(
".desktop"))) {
836 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
837 if (!filePath.isEmpty()) {
838 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
839 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
840 "be removed. Please specify a desktop file name without .desktop suffix");
841 (*QGuiApplicationPrivate::desktopFileName).chop(8);
846QString QGuiApplication::desktopFileName()
848 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
852
853
854
855
856
857
858
859
860
861
862
863
864
865QWindow *QGuiApplication::modalWindow()
868 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
869 if (modalWindows.isEmpty())
871 return modalWindows.constFirst();
876 QWindowPrivate *p = qt_window_private(window);
877 if (p->blockedByModalWindow != shouldBeBlocked) {
878 p->blockedByModalWindow = shouldBeBlocked;
879 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
880 QGuiApplication::sendEvent(window, &e);
881 for (QObject *c : window->children()) {
882 if (c->isWindowType())
883 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
888void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
890 bool shouldBeBlocked =
false;
891 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
892 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
893 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
894 updateBlockedStatusRecursion(window, shouldBeBlocked);
902 return w->isTopLevel();
905void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
907 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
908 guiAppPrivate->modalWindowList.prepend(modal);
911 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
912 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
913 if (shouldBeBlocked) {
915 guiAppPrivate->modalWindowList.removeFirst();
916 QEvent e(QEvent::Leave);
917 QGuiApplication::sendEvent(currentMouseWindow, &e);
918 currentMouseWindow =
nullptr;
919 guiAppPrivate->modalWindowList.prepend(modal);
923 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
924 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
925 updateBlockedStatus(window);
928 updateBlockedStatus(modal);
931void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
933 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
935 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
936 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
937 updateBlockedStatus(window);
941Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
946bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
953
954
955
956
957bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
959 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
961 QWindow *unused =
nullptr;
963 blockingWindow = &unused;
964 *blockingWindow =
nullptr;
966 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
969 for (
int i = 0; i < modalWindowList.size(); ++i) {
970 QWindow *modalWindow = modalWindowList.at(i);
974 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
977 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
978 : modalWindow->modality()) {
979 case Qt::ApplicationModal:
980 *blockingWindow = modalWindow;
982 case Qt::WindowModal: {
985 auto *current = window;
987 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
988 *blockingWindow = modalWindow;
991 current = current->parent(QWindow::IncludeTransients);
996 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1003QWindow *QGuiApplicationPrivate::activePopupWindow()
1006 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1007 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1010void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1012 if (!popup->isVisible())
1014 popup_list.removeOne(popup);
1015 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1016 popup_list.append(popup);
1019bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1021 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1022 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1027
1028
1029bool QGuiApplicationPrivate::closeAllPopups()
1035 while ((popup = activePopupWindow()) && maxiter--)
1037 return QGuiApplicationPrivate::popup_list.isEmpty();
1041
1042
1043
1044
1045
1046QWindow *QGuiApplication::focusWindow()
1048 return QGuiApplicationPrivate::focus_window;
1052
1053
1054
1055
1056
1057
1058
1061
1062
1063
1064
1065
1066
1067
1070
1071
1072
1073QObject *QGuiApplication::focusObject()
1076 return focusWindow()->focusObject();
1081
1082
1083
1084
1085
1086
1087
1088
1089QWindowList QGuiApplication::allWindows()
1091 return QGuiApplicationPrivate::window_list;
1095
1096
1097
1098
1099
1100
1101QWindowList QGuiApplication::topLevelWindows()
1103 const QWindowList &list = QGuiApplicationPrivate::window_list;
1104 QWindowList topLevelWindows;
1105 for (
int i = 0; i < list.size(); ++i) {
1106 QWindow *window = list.at(i);
1107 if (!window->isTopLevel())
1112 if (window->handle() && window->handle()->isEmbedded())
1115 topLevelWindows.prepend(window);
1118 return topLevelWindows;
1121QScreen *QGuiApplication::primaryScreen()
1123 if (QGuiApplicationPrivate::screen_list.isEmpty())
1125 return QGuiApplicationPrivate::screen_list.at(0);
1129
1130
1131
1132QList<QScreen *> QGuiApplication::screens()
1134 return QGuiApplicationPrivate::screen_list;
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148QScreen *QGuiApplication::screenAt(
const QPoint &point)
1150 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1151 for (
const QScreen *screen : QGuiApplication::screens()) {
1152 if (visitedScreens.contains(screen))
1156 for (QScreen *sibling : screen->virtualSiblings()) {
1157 if (sibling->geometry().contains(point))
1160 visitedScreens.append(sibling);
1168
1169
1170
1171
1172
1173
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210qreal QGuiApplication::devicePixelRatio()
const
1212 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1213 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1215 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1216 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1217 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1219 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1222void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1224 m_maxDevicePixelRatio = 0.0;
1227void QGuiApplicationPrivate::_q_updatePrimaryScreenDpis()
1230 const QScreen *screen = QGuiApplication::primaryScreen();
1232 int dpiX = qRound(screen->logicalDotsPerInchX());
1233 int dpiY = qRound(screen->logicalDotsPerInchY());
1234 dpis = (dpiX << 16) | (dpiY & 0xffff);
1235 QObject::connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
1236 q_func(), SLOT(_q_updatePrimaryScreenDpis()), Qt::UniqueConnection);
1238 m_primaryScreenDpis.storeRelaxed(dpis);
1242
1243
1244QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1246 if (QScreen *windowScreen = screenAt(pos)) {
1247 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1248 return windowScreen->handle()->topLevelAt(devicePosition);
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1290QString QGuiApplication::platformName()
1292 if (!QGuiApplication::instance()) {
1293#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1294 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1299 return QGuiApplicationPrivate::platform_name ?
1300 *QGuiApplicationPrivate::platform_name : QString();
1308static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1310 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1311 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1312 <<
"platformPluginPath" << platformPluginPath
1313 <<
"platformThemeName" << platformThemeName;
1315 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1316 QStringList platformArguments;
1317 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1318 for (
const auto &pluginArgument : std::as_const(plugins)) {
1320 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1321 if (arguments.isEmpty())
1323 const QString name = arguments.takeFirst().toLower();
1324 QString argumentsKey = name;
1327 argumentsKey[0] = argumentsKey.at(0).toUpper();
1328 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1330 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1333 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1334 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1335 if (availablePlugins.contains(name)) {
1336 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1337 qCWarning(lcQpaPluginLoading).nospace().noquote()
1338 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1340 qCInfo(lcQpaPluginLoading).nospace().noquote()
1341 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1342 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1344 qCWarning(lcQpaPluginLoading).nospace().noquote()
1345 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1346 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1349 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1350 QGuiApplicationPrivate::platform_name =
new QString(name);
1351 platformArguments = arguments;
1356 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1357 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1358 "Reinstalling the application may fix this problem.\n");
1360 if (!availablePlugins.isEmpty())
1361 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1363#if defined(Q_OS_WIN)
1366 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1367 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1369 qFatal(
"%s", qPrintable(fatalMessage));
1377 QStringList themeNames;
1378 if (!platformThemeName.isEmpty()) {
1379 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1380 themeNames.append(platformThemeName);
1383#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1385 if (checkNeedPortalSupport()) {
1386 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1387 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1392 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1393 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1394 themeNames.append(platformIntegrationThemeNames);
1397 for (
const QString &themeName : std::as_const(themeNames)) {
1398 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1399 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1400 if (QGuiApplicationPrivate::platform_theme) {
1401 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1404 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1405 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1406 if (QGuiApplicationPrivate::platform_theme) {
1407 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1413 if (!QGuiApplicationPrivate::platform_theme) {
1414 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1415 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1420 if (!platformArguments.isEmpty()) {
1421 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1422 for (
const QString &argument : std::as_const(platformArguments)) {
1423 const qsizetype equalsPos = argument.indexOf(u'=');
1424 const QByteArray name =
1425 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1427 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1428 nativeInterface->setProperty(name.constData(), std::move(value));
1433 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1434 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1435 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1436 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1438 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1439 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1440 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1446 for (
int i = 0; i < pluginList.size(); ++i) {
1447 QByteArray pluginSpec = pluginList.at(i);
1448 qsizetype colonPos = pluginSpec.indexOf(
':');
1451 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1453 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1454 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1456 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1458 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1462#if QT_CONFIG(commandlineparser)
1463void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1465 QCoreApplicationPrivate::addQtOptions(options);
1467#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1468 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1469 const bool x11 = sessionType ==
"x11";
1472 const bool x11 =
false;
1475 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1476 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1477 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1478 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1479 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1480 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1481 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1482 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1483 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1484 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1485 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1486 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1487 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1488 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1489 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1490 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1491 options->append(QCommandLineOption(QStringLiteral(
"session"),
1492 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1495 options->append(QCommandLineOption(QStringLiteral(
"display"),
1496 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1497 options->append(QCommandLineOption(QStringLiteral(
"name"),
1498 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1499 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1500 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1501 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1502 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1503 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1504 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1506 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1507 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1508 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1509 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1510 options->append(QCommandLineOption(QStringLiteral(
"title"),
1511 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1516void QGuiApplicationPrivate::createPlatformIntegration()
1518 QHighDpiScaling::initHighDpiScaling();
1521 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1524 QByteArray platformName;
1525#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1526 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1528#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1529 QList<QByteArray> platformArguments = platformName.split(
':');
1530 QByteArray platformPluginBase = platformArguments.first();
1532 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1533 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1535 QVector<QByteArray> preferredPlatformOrder;
1536 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1537 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1538 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1539 preferredPlatformOrder << xcbPlatformName;
1541 platformName.clear();
1544 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1545 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1546 if (hasWaylandDisplay || isWaylandSessionType) {
1547 preferredPlatformOrder.prepend(waylandPlatformName);
1549 if (defaultIsWayland)
1550 platformName.clear();
1553 if (!platformName.isEmpty())
1554 preferredPlatformOrder.append(platformName);
1556 platformName = preferredPlatformOrder.join(
';');
1559 bool platformExplicitlySelected =
false;
1560 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1561 if (!platformNameEnv.isEmpty()) {
1562 platformName = platformNameEnv;
1563 platformExplicitlySelected =
true;
1566 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1572 int j = argc ? 1 : 0;
1573 for (
int i=1; i<argc; i++) {
1576 if (*argv[i] !=
'-') {
1577 argv[j++] = argv[i];
1580 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1581 const char *arg = argv[i];
1584 if (strcmp(arg,
"-platformpluginpath") == 0) {
1586 platformPluginPath = QFile::decodeName(argv[i]);
1587 }
else if (strcmp(arg,
"-platform") == 0) {
1589 platformExplicitlySelected =
true;
1590 platformName = argv[i];
1592 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1594 platformThemeName = QString::fromLocal8Bit(argv[i]);
1595 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1597 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1598 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1600 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1601 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1603 icon = QFile::decodeName(argv[i]);
1606 argv[j++] = argv[i];
1615 Q_UNUSED(platformExplicitlySelected);
1617 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1618 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1620 if (!icon.isEmpty())
1621 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1625
1626
1627
1628
1629
1630void QGuiApplicationPrivate::createEventDispatcher()
1632 Q_ASSERT(!eventDispatcher);
1634 if (platform_integration ==
nullptr)
1635 createPlatformIntegration();
1638 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1639 "Creating the platform integration resulted in creating an event dispatcher");
1642 Q_ASSERT(!eventDispatcher);
1644 eventDispatcher = platform_integration->createEventDispatcher();
1647void QGuiApplicationPrivate::eventDispatcherReady()
1649 if (platform_integration ==
nullptr)
1650 createPlatformIntegration();
1652 platform_integration->initialize();
1655void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1657 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1659#if defined(Q_OS_MACOS)
1660 QMacAutoReleasePool pool;
1663 QObject::connect(q_func(), SIGNAL(screenAdded(QScreen*)),
1664 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1665 QObject::connect(q_func(), SIGNAL(primaryScreenChanged(QScreen *)),
1666 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1668 QCoreApplicationPrivate::init();
1670 QCoreApplicationPrivate::is_app_running =
false;
1672 bool loadTestability =
false;
1673 QList<QByteArray> pluginList;
1675#ifndef QT_NO_SESSIONMANAGER
1677 QString session_key;
1678# if defined(Q_OS_WIN)
1679 wchar_t guidstr[40];
1681 CoCreateGuid(&guid);
1682 StringFromGUID2(guid, guidstr, 40);
1683 session_id = QString::fromWCharArray(guidstr);
1684 CoCreateGuid(&guid);
1685 StringFromGUID2(guid, guidstr, 40);
1686 session_key = QString::fromWCharArray(guidstr);
1690 int j = argc ? 1 : 0;
1691 for (
int i=1; i<argc; i++) {
1694 if (*argv[i] !=
'-') {
1695 argv[j++] = argv[i];
1698 const char *arg = argv[i];
1701 if (strcmp(arg,
"-plugin") == 0) {
1703 pluginList << argv[i];
1704 }
else if (strcmp(arg,
"-reverse") == 0) {
1705 force_reverse =
true;
1707 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1710 if (QDir::currentPath() ==
"/"_L1) {
1711 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1712 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1713 kCFURLPOSIXPathStyle));
1714 if (qbundlePath.endsWith(
".app"_L1))
1715 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1718#ifndef QT_NO_SESSIONMANAGER
1719 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1721 if (argv[i] && *argv[i]) {
1722 session_id = QString::fromLatin1(argv[i]);
1723 qsizetype p = session_id.indexOf(u'_');
1725 session_key = session_id.mid(p +1);
1726 session_id = session_id.left(p);
1728 is_session_restored =
true;
1731 }
else if (strcmp(arg,
"-testability") == 0) {
1732 loadTestability =
true;
1733 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1734 s = QString::fromLocal8Bit(arg + 7);
1735 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1736 s = QString::fromLocal8Bit(argv[++i]);
1738 argv[j++] = argv[i];
1751 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1752 if (!envPlugins.isEmpty())
1753 pluginList += envPlugins.split(
',');
1755 if (platform_integration ==
nullptr)
1756 createPlatformIntegration();
1759 QFont::initialize();
1763 QCursorData::initialize();
1767 qRegisterGuiVariant();
1769#if QT_CONFIG(animation)
1771 qRegisterGuiGetInterpolator();
1774 QWindowSystemInterfacePrivate::eventTime.start();
1776 is_app_running =
true;
1777 init_plugins(pluginList);
1778 QWindowSystemInterface::flushWindowSystemEvents();
1780 Q_Q(QGuiApplication);
1781#ifndef QT_NO_SESSIONMANAGER
1783 session_manager =
new QSessionManager(q, session_id, session_key);
1786#if QT_CONFIG(library)
1787 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1788 loadTestability =
true;
1790 if (loadTestability) {
1791 QLibrary testLib(QStringLiteral(
"qttestability"));
1792 if (Q_UNLIKELY(!testLib.load())) {
1793 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1795 typedef void (*TasInitialize)(
void);
1796 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1797 if (Q_UNLIKELY(!initFunction)) {
1798 qCritical(
"Library qttestability resolve failed!");
1805 Q_UNUSED(loadTestability);
1809 QGuiApplication::setLayoutDirection(layout_direction);
1811 if (!QGuiApplicationPrivate::displayName)
1812 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1813 q, &QGuiApplication::applicationDisplayNameChanged);
1816extern void qt_cleanupFontDatabase();
1818QGuiApplicationPrivate::~QGuiApplicationPrivate()
1820#if defined(Q_OS_MACOS)
1821 QMacAutoReleasePool pool;
1824 is_app_closing =
true;
1825 is_app_running =
false;
1827 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1828 delete generic_plugin_list.at(i);
1829 generic_plugin_list.clear();
1831 clearFontUnlocked();
1836 QCursorData::cleanup();
1839 layout_direction = Qt::LayoutDirectionAuto;
1841 cleanupThreadData();
1843 delete QGuiApplicationPrivate::styleHints;
1844 QGuiApplicationPrivate::styleHints =
nullptr;
1847 qt_cleanupFontDatabase();
1849 QPixmapCache::clear();
1852 if (ownGlobalShareContext) {
1853 delete qt_gl_global_share_context();
1854 qt_gl_set_global_share_context(
nullptr);
1858#if QT_CONFIG(vulkan)
1859 QVulkanDefaultInstance::cleanup();
1862 platform_integration->destroy();
1864 delete platform_theme;
1865 platform_theme =
nullptr;
1866 delete platform_integration;
1867 platform_integration =
nullptr;
1869 window_list.clear();
1871 screen_list.clear();
1874 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1879QCursor *overrideCursor();
1880void setOverrideCursor(
const QCursor &);
1881void changeOverrideCursor(
const QCursor &);
1882void restoreOverrideCursor();
1886static QFont font(
const QWidget*);
1887static QFont font(
const char *className);
1888static void setFont(
const QFont &,
const char *className =
nullptr);
1889static QFontMetrics fontMetrics();
1891#ifndef QT_NO_CLIPBOARD
1892static QClipboard *clipboard();
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1911 return QGuiApplicationPrivate::modifier_buttons;
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1933 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1934 return pi->keyMapper()->queryKeyboardModifiers();
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950Qt::MouseButtons QGuiApplication::mouseButtons()
1952 return QGuiApplicationPrivate::mouse_buttons;
1956
1957
1958
1959
1960QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1962 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1963 return pi ? pi->nativeInterface() :
nullptr;
1967
1968
1969
1970QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1972 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1974 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1978 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005int QGuiApplication::exec()
2007#if QT_CONFIG(accessibility)
2008 QAccessible::setRootObject(qApp);
2010 return QCoreApplication::exec();
2013void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
2015 if (e->spontaneous()) {
2023 switch (e->type()) {
2024 case QEvent::MouseButtonPress: {
2025 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2026 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2027 QGuiApplicationPrivate::mouse_buttons |= me->button();
2030 case QEvent::MouseButtonDblClick: {
2031 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2032 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2033 QGuiApplicationPrivate::mouse_buttons |= me->button();
2036 case QEvent::MouseButtonRelease: {
2037 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2038 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2039 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2042 case QEvent::KeyPress:
2043 case QEvent::KeyRelease:
2044 case QEvent::MouseMove:
2045#if QT_CONFIG(wheelevent)
2048 case QEvent::TouchBegin:
2049 case QEvent::TouchUpdate:
2050 case QEvent::TouchEnd:
2051#if QT_CONFIG(tabletevent)
2052 case QEvent::TabletMove:
2053 case QEvent::TabletPress:
2054 case QEvent::TabletRelease:
2057 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2058 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2068
2069bool QGuiApplication::notify(QObject *object, QEvent *event)
2071 Q_D(QGuiApplication);
2072 if (object->isWindowType()) {
2073 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2077 switch (event->type()) {
2078 case QEvent::ApplicationDeactivate:
2079 case QEvent::OrientationChange:
2085 d->closeAllPopups();
2091 QGuiApplicationPrivate::captureGlobalModifierState(event);
2093 return QCoreApplication::notify(object, event);
2097
2098bool QGuiApplication::event(QEvent *e)
2100 switch (e->type()) {
2101 case QEvent::LanguageChange:
2103 if (layout_direction == Qt::LayoutDirectionAuto)
2104 setLayoutDirection(layout_direction);
2105 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2106 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2108 case QEvent::ApplicationFontChange:
2109 case QEvent::ApplicationPaletteChange:
2110 postEvent(QGuiApplication::styleHints(), e->clone());
2111 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2112 postEvent(topLevelWindow,
new QEvent(e->type()));
2114 case QEvent::ThemeChange:
2115 forwardEvent(QGuiApplication::styleHints(), e);
2116 for (
auto *w : QGuiApplication::allWindows())
2122 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2124 if (!topLevelWindow->handle())
2126 if (!topLevelWindow->close()) {
2135 return QCoreApplication::event(e);
2138#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2140
2141
2142bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2144 QT_IGNORE_DEPRECATIONS(
2145 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2150bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2154 QPlatformWindow *platformWindow = window->handle();
2155 if (!platformWindow)
2158 if (event->spontaneous())
2161 return platformWindow->windowEvent(event);
2164bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2166 return window->nativeEvent(eventType, message, result);
2169bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2171 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArray(
"qtvirtualkeyboard");
2172 return usingVirtualKeyboard;
2176bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2178 if (!isUsingVirtualKeyboard()) {
2179 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2183 static QPointer<QWindow> virtualKeyboard;
2184 const QEvent::Type type = e->type();
2185 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2186 const auto me =
static_cast<QMouseEvent *>(e);
2187 const QPointF posF = me->globalPosition();
2188 const QPoint pos = posF.toPoint();
2191 if (!virtualKeyboard) {
2192 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2193 win->inherits(
"QtVirtualKeyboard::InputView")) {
2194 virtualKeyboard = win;
2196 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2201 Q_ASSERT(virtualKeyboard);
2202 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2203 && virtualKeyboard->geometry().contains(pos);
2205 if (!virtualKeyboardUnderMouse) {
2206 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2207 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2211 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2212 me->button(), me->buttons(), me->modifiers(),
2213 me->pointingDevice());
2215 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2216 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2222void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2224 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2225 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2227 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2228 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2229 if (!haveGuiApplication) {
2230 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2231 e->eventAccepted =
false;
2236 case QWindowSystemInterfacePrivate::Mouse:
2237 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2239 case QWindowSystemInterfacePrivate::Wheel:
2240 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2242 case QWindowSystemInterfacePrivate::Key:
2243 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2245 case QWindowSystemInterfacePrivate::Touch:
2246 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2248 case QWindowSystemInterfacePrivate::GeometryChange:
2249 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2251 case QWindowSystemInterfacePrivate::Enter:
2252 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2254 case QWindowSystemInterfacePrivate::Leave:
2255 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2257 case QWindowSystemInterfacePrivate::FocusWindow:
2258 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2260 case QWindowSystemInterfacePrivate::WindowStateChanged:
2261 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2263 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2264 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2266 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2267 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2269 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2270 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2272 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2273 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2274 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2276 case QWindowSystemInterfacePrivate::ApplicationTermination:
2277 QGuiApplicationPrivate::processApplicationTermination(e);
2279 case QWindowSystemInterfacePrivate::FlushEvents: {
2280 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2281 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2283 case QWindowSystemInterfacePrivate::Close:
2284 QGuiApplicationPrivate::processCloseEvent(
2285 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2287 case QWindowSystemInterfacePrivate::ScreenOrientation:
2288 QGuiApplicationPrivate::processScreenOrientationChange(
2289 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2291 case QWindowSystemInterfacePrivate::ScreenGeometry:
2292 QGuiApplicationPrivate::processScreenGeometryChange(
2293 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2295 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2296 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2297 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2299 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2300 QGuiApplicationPrivate::processScreenRefreshRateChange(
2301 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2303 case QWindowSystemInterfacePrivate::ThemeChange:
2304 QGuiApplicationPrivate::processThemeChanged(
2305 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2307 case QWindowSystemInterfacePrivate::Expose:
2308 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2310 case QWindowSystemInterfacePrivate::Paint:
2311 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2313 case QWindowSystemInterfacePrivate::Tablet:
2314 QGuiApplicationPrivate::processTabletEvent(
2315 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2317 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2318 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2319 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2321 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2322 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2323 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2325#ifndef QT_NO_GESTURES
2326 case QWindowSystemInterfacePrivate::Gesture:
2327 QGuiApplicationPrivate::processGestureEvent(
2328 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2331 case QWindowSystemInterfacePrivate::PlatformPanel:
2332 QGuiApplicationPrivate::processPlatformPanelEvent(
2333 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2335 case QWindowSystemInterfacePrivate::FileOpen:
2336 QGuiApplicationPrivate::processFileOpenEvent(
2337 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2339#ifndef QT_NO_CONTEXTMENU
2340 case QWindowSystemInterfacePrivate::ContextMenu:
2341 QGuiApplicationPrivate::processContextMenuEvent(
2342 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2345 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2346 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2349 qWarning() <<
"Unknown user input event type:" << e->type;
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2368 QEvent::Type type = QEvent::None;
2369 Qt::MouseButton button = Qt::NoButton;
2370 QWindow *window = e->window.data();
2371 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2373 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2374 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2375 bool mouseMove =
false;
2376 bool mousePress =
false;
2377 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2378 QPointF globalPoint = e->globalPos;
2380 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2381 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2385 type = e->buttonType;
2388 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2390 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2393 if (!mouseMove && positionChanged) {
2394 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2395 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2396 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2397 e->source, e->nonClientArea, device, e->eventPointId);
2399 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2400 processMouseEvent(&moveEvent);
2401 processMouseEvent(e);
2404 if (type == QEvent::MouseMove && !positionChanged) {
2412 modifier_buttons = e->modifiers;
2413 QPointF localPoint = e->localPos;
2414 bool doubleClick =
false;
2415 auto persistentEPD = devPriv->pointById(0);
2417 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2418 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2421 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2422 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2423 mouseDoubleClickDistance : touchDoubleTapDistance);
2424 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2425 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2426 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2427 mousePressButton = Qt::NoButton;
2429 static unsigned long lastPressTimestamp = 0;
2430 static QPointer<QWindow> lastPressWindow =
nullptr;
2431 mouse_buttons = e->buttons;
2433 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2434 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2435 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2436 && button == mousePressButton && lastPressWindow == e->window;
2437 mousePressButton = button;
2438 lastPressTimestamp = e ->timestamp;
2439 lastPressWindow = e->window;
2443 if (e->nullWindow()) {
2444 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2448 if (e->buttons != Qt::NoButton) {
2449 if (!currentMousePressWindow)
2450 currentMousePressWindow = window;
2452 window = currentMousePressWindow;
2453 }
else if (currentMousePressWindow) {
2454 window = currentMousePressWindow;
2455 currentMousePressWindow =
nullptr;
2457 localPoint = window->mapFromGlobal(globalPoint);
2465 if (!e->synthetic()) {
2466 if (
const QScreen *screen = window->screen())
2467 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2468 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2469 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2470 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2471 button, e->buttons, e->modifiers, e->source, device);
2475 ev.QInputEvent::setTimestamp(e->timestamp);
2476 cursor->pointerEvent(ev);
2481 const auto *activePopup = activePopupWindow();
2482 if (type == QEvent::MouseButtonPress)
2483 active_popup_on_press = activePopup;
2484 if (window->d_func()->blockedByModalWindow && !activePopup) {
2489 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2490 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2493 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2494 persistentEPD =
nullptr;
2496 ev.setTimestamp(e->timestamp);
2498 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2500 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2501 if (handlingPopup) {
2502 if (type == QEvent::MouseButtonPress)
2503 active_popup_on_press = handlingPopup;
2508 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2510 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2513 QGuiApplication::sendSpontaneousEvent(window, &ev);
2514 e->eventAccepted = ev.isAccepted();
2515 if (!e->synthetic() && !ev.isAccepted()
2516 && !e->nonClientArea
2517 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2518 QList<QWindowSystemInterface::TouchPoint> points;
2519 QWindowSystemInterface::TouchPoint point;
2521 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2526 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2527 point.state = QEventPoint::State::Pressed;
2528 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2529 point.state = QEventPoint::State::Released;
2530 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2531 point.state = QEventPoint::State::Updated;
2539 const QList<QEventPoint> &touchPoints =
2540 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2542 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2543 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2544 processTouchEvent(&fake);
2547 mousePressButton = Qt::NoButton;
2548 if (!e->window.isNull() || e->nullWindow()) {
2549 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2550 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2551 button, e->buttons, e->modifiers, e->source, device);
2552 dblClickEvent.setTimestamp(e->timestamp);
2553 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2556 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2557 popup_closed_on_press =
false;
2558 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2559 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2560 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2565void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2567#if QT_CONFIG(wheelevent)
2568 QWindow *window = e->window.data();
2569 QPointF globalPoint = e->globalPos;
2570 QPointF localPoint = e->localPos;
2572 if (e->nullWindow()) {
2573 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2575 localPoint = window->mapFromGlobal(globalPoint);
2581 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2582 modifier_buttons = e->modifiers;
2584 if (window->d_func()->blockedByModalWindow) {
2589 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2590 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2591 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2592 ev.setTimestamp(e->timestamp);
2593 QGuiApplication::sendSpontaneousEvent(window, &ev);
2594 e->eventAccepted = ev.isAccepted();
2600void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2602 QWindow *window = e->window.data();
2603 modifier_buttons = e->modifiers;
2606 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2609 window = QGuiApplication::focusWindow();
2613 e->eventAccepted =
false;
2617#if defined(Q_OS_ANDROID)
2618 static bool backKeyPressAccepted =
false;
2619 static bool menuKeyPressAccepted =
false;
2622#if !defined(Q_OS_MACOS)
2625 if (e->keyType == QEvent::KeyPress) {
2626 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2627 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2628#if defined(Q_OS_ANDROID)
2629 backKeyPressAccepted = e->key == Qt::Key_Back;
2630 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2637 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2638 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2639 e->unicode, e->repeat, e->repeatCount);
2640 ev.setTimestamp(e->timestamp);
2642 const auto *activePopup = activePopupWindow();
2643 if (activePopup && activePopup != window) {
2645 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2651 if (!window->d_func()->blockedByModalWindow)
2652 QGuiApplication::sendSpontaneousEvent(window, &ev);
2655 ev.setAccepted(
false);
2657 if (e->keyType == QEvent::KeyPress) {
2658 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2659 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2660 }
else if (e->keyType == QEvent::KeyRelease) {
2661 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2663 QWindowSystemInterface::handleCloseEvent(window);
2664 }
else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2665 platform_theme->showPlatformMenuBar();
2669 e->eventAccepted = ev.isAccepted();
2672void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2676 if (e->enter.data()->d_func()->blockedByModalWindow) {
2681 currentMouseWindow = e->enter;
2684 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2691 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2692 auto epd = devPriv->queryPointById(event.points().first().id());
2694 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2696 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2699void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2703 if (e->leave.data()->d_func()->blockedByModalWindow) {
2708 currentMouseWindow =
nullptr;
2710 QEvent event(QEvent::Leave);
2711 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2714void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2716 QWindow *previous = QGuiApplicationPrivate::focus_window;
2717 QWindow *newFocus = e->focused.data();
2719 if (previous == newFocus)
2722 bool activatedPopup =
false;
2724 if (QPlatformWindow *platformWindow = newFocus->handle())
2725 if (platformWindow->isAlertState())
2726 platformWindow->setAlertState(
false);
2727 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2729 activatePopup(newFocus);
2732 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2735 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2736 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2739 QGuiApplicationPrivate::focus_window = newFocus;
2744 Qt::FocusReason r = e->reason;
2745 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2746 r = Qt::PopupFocusReason;
2747 QFocusEvent focusOut(QEvent::FocusOut, r);
2748 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2749 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2750 qApp, SLOT(_q_updateFocusObject(QObject*)));
2751 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2752 setApplicationState(Qt::ApplicationActive);
2755 if (QGuiApplicationPrivate::focus_window) {
2756 Qt::FocusReason r = e->reason;
2757 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2758 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2759 r = Qt::PopupFocusReason;
2760 QFocusEvent focusIn(QEvent::FocusIn, r);
2761 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2762 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2763 qApp, SLOT(_q_updateFocusObject(QObject*)));
2764 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2765 setApplicationState(Qt::ApplicationInactive);
2768 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2769 guiAppPrivate->notifyActiveWindowChange(previous);
2771 if (previousFocusObject !=
qApp->focusObject() ||
2777 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2778 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2782 emit
qApp->focusWindowChanged(newFocus);
2784 emit previous->activeChanged();
2786 emit newFocus->activeChanged();
2789void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2791 if (QWindow *window = wse->window.data()) {
2792 QWindowPrivate *windowPrivate = qt_window_private(window);
2793 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2795 windowPrivate->windowState = wse->newState;
2796 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2797 if (newEffectiveState != originalEffectiveState)
2798 emit window->windowStateChanged(newEffectiveState);
2800 windowPrivate->updateVisibility();
2802 QWindowStateChangeEvent e(wse->oldState);
2803 QGuiApplication::sendSpontaneousEvent(window, &e);
2807void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2809 QWindow *window = wse->window.data();
2813 QScreen *screen = wse->screen.data();
2814 if (window->screen() == screen)
2817 auto *windowPrivate = QWindowPrivate::get(window);
2818 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2819 if (window == topLevelWindow) {
2821 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2823 topLevelWindow->setScreen(
nullptr);
2824 }
else if (screen) {
2829 windowPrivate->emitScreenChangedRecursion(screen);
2833void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2835 if (wde->window.isNull())
2837 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2840void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2842 if (wse->window.isNull())
2845 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2847 QEvent event(QEvent::SafeAreaMarginsChange);
2848 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2851void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2858 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2859 guiAppPrivate->handleThemeChanged();
2861 QIconPrivate::clearIconCache();
2863 QEvent themeChangeEvent(QEvent::ThemeChange);
2864 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2867void QGuiApplicationPrivate::handleThemeChanged()
2869 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2872 QIconLoader::instance()->updateSystemTheme();
2873 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2875 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2876 const auto locker = qt_scoped_lock(applicationFontMutex);
2877 clearFontUnlocked();
2883void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2885 if (e->window.isNull())
2888 QWindow *window = e->window.data();
2892 const QRect lastReportedGeometry = window->d_func()->geometry;
2893 const QRect requestedGeometry = e->requestedGeometry;
2894 const QRect actualGeometry = e->newGeometry;
2904 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2905 || requestedGeometry.size() != actualGeometry.size();
2906 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2907 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2909 window->d_func()->geometry = actualGeometry;
2911 if (isResize || window->d_func()->resizeEventPending) {
2912 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2913 QGuiApplication::sendSpontaneousEvent(window, &e);
2915 window->d_func()->resizeEventPending =
false;
2917 if (actualGeometry.width() != lastReportedGeometry.width())
2918 emit window->widthChanged(actualGeometry.width());
2919 if (actualGeometry.height() != lastReportedGeometry.height())
2920 emit window->heightChanged(actualGeometry.height());
2925 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2926 QGuiApplication::sendSpontaneousEvent(window, &e);
2928 if (actualGeometry.x() != lastReportedGeometry.x())
2929 emit window->xChanged(actualGeometry.x());
2930 if (actualGeometry.y() != lastReportedGeometry.y())
2931 emit window->yChanged(actualGeometry.y());
2935void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2937 if (e->window.isNull())
2939 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2942 e->eventAccepted =
false;
2947 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2949 e->eventAccepted = event.isAccepted();
2952void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2954 if (e->url.isEmpty())
2957 QFileOpenEvent event(e->url);
2958 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2961QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2963 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2964 TabletPointData &pointData = tabletDevicePoints[i];
2965 if (pointData.deviceId == deviceId)
2969 tabletDevicePoints.append(TabletPointData(deviceId));
2970 return tabletDevicePoints.last();
2973void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2975#if QT_CONFIG(tabletevent)
2976 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2977 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2979 QEvent::Type type = QEvent::TabletMove;
2980 if (e->buttons != pointData.state)
2981 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2983 QWindow *window = e->window.data();
2984 modifier_buttons = e->modifiers;
2986 bool localValid =
true;
2990 if (type == QEvent::TabletPress) {
2991 if (e->nullWindow()) {
2992 window = QGuiApplication::topLevelAt(e->global.toPoint());
2997 active_popup_on_press = activePopupWindow();
2998 pointData.target = window;
3000 if (e->nullWindow()) {
3001 window = pointData.target;
3004 if (type == QEvent::TabletRelease)
3005 pointData.target =
nullptr;
3009 QPointF local = e->local;
3011 QPointF delta = e->global - e->global.toPoint();
3012 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3016 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3017 Qt::MouseButton button = Qt::NoButton;
3018 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3019 if (check & stateChange) {
3020 button = Qt::MouseButton(check);
3025 const auto *activePopup = activePopupWindow();
3026 if (window->d_func()->blockedByModalWindow && !activePopup) {
3031 QTabletEvent tabletEvent(type, device, local, e->global,
3032 e->pressure, e->xTilt, e->yTilt,
3033 e->tangentialPressure, e->rotation, e->z,
3034 e->modifiers, button, e->buttons);
3035 tabletEvent.setAccepted(
false);
3036 tabletEvent.setTimestamp(e->timestamp);
3038 if (activePopup && activePopup != window) {
3040 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3044 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3045 pointData.state = e->buttons;
3046 if (!tabletEvent.isAccepted()
3047 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3048 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3050 const QEvent::Type mouseType = [&]() {
3052 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3053 case QEvent::TabletMove:
return QEvent::MouseMove;
3054 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3055 default: Q_UNREACHABLE();
3058 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3059 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3060 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3061 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3062 << e->local << button << e->buttons << e->modifiers;
3063 processMouseEvent(&mouseEvent);
3070void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3072#if QT_CONFIG(tabletevent)
3073 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3074 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3075 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3076 tabletDevicePoint(dev->uniqueId().numericId()).state);
3077 ev.setTimestamp(e->timestamp);
3078 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3084void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3086#if QT_CONFIG(tabletevent)
3087 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3088 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3089 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3090 tabletDevicePoint(dev->uniqueId().numericId()).state);
3091 ev.setTimestamp(e->timestamp);
3092 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3098#ifndef QT_NO_GESTURES
3099void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3101 if (e->window.isNull())
3104 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3105 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3106 e->delta, e->sequenceId);
3107 ev.setTimestamp(e->timestamp);
3108 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3112void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3117 if (e->window->d_func()->blockedByModalWindow) {
3122 QEvent ev(QEvent::PlatformPanel);
3123 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3126#ifndef QT_NO_CONTEXTMENU
3127void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3131 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3134 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3135 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3136 e->eventAccepted = ev.isAccepted();
3140void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3142 if (!QInputDevicePrivate::isRegistered(e->device))
3145 modifier_buttons = e->modifiers;
3146 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3147 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3149 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3151 if (e->touchType == QEvent::TouchCancel) {
3154 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3155 touchEvent.setTimestamp(e->timestamp);
3156 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3157 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3159 for (
auto &epd : devPriv->activePoints.values()) {
3160 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3161 windowsNeedingCancel.insert(w);
3164 for (QWindow *w : windowsNeedingCancel)
3165 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3167 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3168 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3169 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3170 if (!synthIt->window)
3172 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3179 QEvent::MouseButtonRelease,
3180 Qt::MouseEventNotSynthesized,
3183 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3184 processMouseEvent(&fake);
3186 guiAppPrivate->synthesizedMousePoints.clear();
3188 guiAppPrivate->lastTouchType = e->touchType;
3193 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3196 guiAppPrivate->lastTouchType = e->touchType;
3198 QPointer<QWindow> window = e->window;
3199 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3205 for (
auto &tempPt : e->points) {
3207 auto epd = devPriv->pointById(tempPt.id());
3208 auto &ep = epd->eventPoint;
3209 epd->eventPoint.setAccepted(
false);
3210 switch (tempPt.state()) {
3211 case QEventPoint::State::Pressed:
3213 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3214 window = devPriv->firstActiveWindow();
3217 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3218 QMutableEventPoint::setWindow(ep, window);
3219 active_popup_on_press = activePopupWindow();
3222 case QEventPoint::State::Released:
3223 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3224 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3225 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3226 window = QMutableEventPoint::window(ep);
3230 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3231 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3232 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3233 window = QMutableEventPoint::window(ep);
3237 if (Q_UNLIKELY(!window)) {
3238 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3241 QMutableEventPoint::update(tempPt, ep);
3243 Q_ASSERT(window.data() !=
nullptr);
3246 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3249 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3252 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3256 for (QMutableTouchEvent &ev : touchEvents) {
3257 if (ev.target() == window.data()) {
3264 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3265 mte.setTimestamp(e->timestamp);
3266 mte.setTarget(window.data());
3267 touchEvents.append(mte);
3271 if (touchEvents.isEmpty())
3274 for (QMutableTouchEvent &touchEvent : touchEvents) {
3275 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3277 QEvent::Type eventType;
3278 switch (touchEvent.touchPointStates()) {
3279 case QEventPoint::State::Pressed:
3280 eventType = QEvent::TouchBegin;
3282 case QEventPoint::State::Released:
3283 eventType = QEvent::TouchEnd;
3286 eventType = QEvent::TouchUpdate;
3290 const auto *activePopup = activePopupWindow();
3291 if (window->d_func()->blockedByModalWindow && !activePopup) {
3295 if (touchEvent.type() == QEvent::TouchEnd) {
3298 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3299 touchEvent.setTimestamp(e->timestamp);
3300 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3305 if (activePopup && activePopup != window) {
3307 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3314 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3316 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3318 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3320 QEvent::Type mouseEventType = QEvent::MouseMove;
3321 Qt::MouseButton button = Qt::NoButton;
3322 Qt::MouseButtons buttons = Qt::LeftButton;
3323 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3324 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3325 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3327 if (m_fakeMouseSourcePointId >= 0) {
3328 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3330 switch (touchPoint->state()) {
3331 case QEventPoint::State::Pressed:
3332 mouseEventType = QEvent::MouseButtonPress;
3333 button = Qt::LeftButton;
3335 case QEventPoint::State::Released:
3336 mouseEventType = QEvent::MouseButtonRelease;
3337 button = Qt::LeftButton;
3338 buttons = Qt::NoButton;
3339 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3340 m_fakeMouseSourcePointId = -1;
3345 if (touchPoint->state() != QEventPoint::State::Released) {
3346 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3347 touchPoint->position(), touchPoint->globalPosition(), window));
3353 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3354 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3355 touchPoint->globalPosition(),
3360 Qt::MouseEventSynthesizedByQt,
3364 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3365 processMouseEvent(&fake);
3368 if (eventType == QEvent::TouchEnd)
3369 guiAppPrivate->synthesizedMousePoints.clear();
3376 for (
const QEventPoint &touchPoint : e->points) {
3377 if (touchPoint.state() == QEventPoint::State::Released)
3378 devPriv->removePointById(touchPoint.id());
3382void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3385 if (QCoreApplication::startingUp())
3391 QScreen *s = e->screen.data();
3392 s->d_func()->orientation = e->orientation;
3394 emit s->orientationChanged(s->orientation());
3396 QScreenOrientationChangeEvent event(s, s->orientation());
3397 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3400void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3403 if (QCoreApplication::startingUp())
3410 QScreen *s = e->screen.data();
3411 QScreenPrivate::UpdateEmitter updateEmitter(s);
3415 s->d_func()->geometry = e->geometry;
3416 s->d_func()->availableGeometry = e->availableGeometry;
3418 s->d_func()->updatePrimaryOrientation();
3421 resetCachedDevicePixelRatio();
3424void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3427 if (QCoreApplication::startingUp())
3430 QHighDpiScaling::updateHighDpiScaling();
3436 QScreen *s = e->screen.data();
3437 QScreenPrivate::UpdateEmitter updateEmitter(s);
3438 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3439 s->d_func()->updateGeometry();
3442 for (QWindow *window : QGuiApplication::allWindows())
3443 if (window->screen() == e->screen)
3444 QWindowPrivate::get(window)->updateDevicePixelRatio();
3446 resetCachedDevicePixelRatio();
3449void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3452 if (QCoreApplication::startingUp())
3458 QScreen *s = e->screen.data();
3459 qreal rate = e->rate;
3463 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3464 s->d_func()->refreshRate = rate;
3465 emit s->refreshRateChanged(s->refreshRate());
3469void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3474 QWindow *window = e->window.data();
3477 QWindowPrivate *p = qt_window_private(window);
3484 p->positionAutomatic =
false;
3485 p->resizeAutomatic =
false;
3488 if (!p->receivedExpose) {
3489 if (p->resizeEventPending) {
3492 QResizeEvent e(window->geometry().size(), p->geometry.size());
3493 QGuiApplication::sendSpontaneousEvent(window, &e);
3495 p->resizeEventPending =
false;
3504 p->receivedExpose =
true;
3508 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3510 const bool wasExposed = p->exposed;
3511 p->exposed = e->isExposed && window->screen();
3516 if (e->isExposed && !e->region.isEmpty()) {
3517 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3519 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3520 <<
"Please file a QTBUG which explains how to reproduce.";
3524 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3525 QPaintEvent paintEvent(e->region);
3526 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3527 if (paintEvent.isAccepted())
3535 QExposeEvent exposeEvent(e->region);
3536 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3537 e->eventAccepted = exposeEvent.isAccepted();
3544 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3545 QPaintEvent paintEvent(e->region);
3546 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3550void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3552 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3553 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3558 QPaintEvent paintEvent(e->region);
3559 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3563 e->eventAccepted = paintEvent.isAccepted();
3566#if QT_CONFIG(draganddrop)
3569
3570
3571
3572
3573static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3575 QGuiApplicationPrivate::mouse_buttons = buttons;
3576 QGuiApplicationPrivate::modifier_buttons = modifiers;
3579QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3580 const QPoint &p, Qt::DropActions supportedActions,
3581 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3583 updateMouseAndModifierButtonState(buttons, modifiers);
3585 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3586 QPlatformDrag *platformDrag = platformIntegration()->drag();
3587 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3588 lastAcceptedDropAction = Qt::IgnoreAction;
3589 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3593 currentDragWindow =
nullptr;
3595 QGuiApplication::sendEvent(w, &e);
3596 lastAcceptedDropAction = Qt::IgnoreAction;
3597 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3599 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3601 if (w != currentDragWindow) {
3602 lastAcceptedDropAction = Qt::IgnoreAction;
3603 if (currentDragWindow) {
3605 QGuiApplication::sendEvent(currentDragWindow, &e);
3607 currentDragWindow = w;
3608 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3609 QGuiApplication::sendEvent(w, &e);
3610 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3611 lastAcceptedDropAction = e.dropAction();
3615 if (lastAcceptedDropAction != Qt::IgnoreAction
3616 && (supportedActions & lastAcceptedDropAction)) {
3617 me.setDropAction(lastAcceptedDropAction);
3620 QGuiApplication::sendEvent(w, &me);
3621 lastAcceptedDropAction = me.isAccepted() ?
3622 me.dropAction() : Qt::IgnoreAction;
3623 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3626QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3627 const QPoint &p, Qt::DropActions supportedActions,
3628 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3630 updateMouseAndModifierButtonState(buttons, modifiers);
3632 currentDragWindow =
nullptr;
3634 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3635 QGuiApplication::sendEvent(w, &de);
3637 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3638 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3644#ifndef QT_NO_CLIPBOARD
3646
3647
3648QClipboard * QGuiApplication::clipboard()
3650 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3652 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3655 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3657 return QGuiApplicationPrivate::qt_clipboard;
3662
3663
3664
3665
3666
3667
3668
3669
3670
3673
3674
3675
3676
3677
3678
3680QPalette QGuiApplication::palette()
3682 if (!QGuiApplicationPrivate::app_pal)
3683 QGuiApplicationPrivate::updatePalette();
3685 return *QGuiApplicationPrivate::app_pal;