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 if (window->screen() == wse->screen.data())
2816 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2817 if (QScreen *screen = wse->screen.data())
2818 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2820 topLevelWindow->setScreen(
nullptr);
2824void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2826 if (wde->window.isNull())
2828 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2831void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2833 if (wse->window.isNull())
2836 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2838 QEvent event(QEvent::SafeAreaMarginsChange);
2839 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2842void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2849 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2850 guiAppPrivate->handleThemeChanged();
2852 QIconPrivate::clearIconCache();
2854 QEvent themeChangeEvent(QEvent::ThemeChange);
2855 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2858void QGuiApplicationPrivate::handleThemeChanged()
2860 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2863 QIconLoader::instance()->updateSystemTheme();
2864 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2866 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2867 const auto locker = qt_scoped_lock(applicationFontMutex);
2868 clearFontUnlocked();
2874void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2876 if (e->window.isNull())
2879 QWindow *window = e->window.data();
2883 const QRect lastReportedGeometry = window->d_func()->geometry;
2884 const QRect requestedGeometry = e->requestedGeometry;
2885 const QRect actualGeometry = e->newGeometry;
2895 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2896 || requestedGeometry.size() != actualGeometry.size();
2897 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2898 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2900 window->d_func()->geometry = actualGeometry;
2902 if (isResize || window->d_func()->resizeEventPending) {
2903 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2904 QGuiApplication::sendSpontaneousEvent(window, &e);
2906 window->d_func()->resizeEventPending =
false;
2908 if (actualGeometry.width() != lastReportedGeometry.width())
2909 emit window->widthChanged(actualGeometry.width());
2910 if (actualGeometry.height() != lastReportedGeometry.height())
2911 emit window->heightChanged(actualGeometry.height());
2916 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2917 QGuiApplication::sendSpontaneousEvent(window, &e);
2919 if (actualGeometry.x() != lastReportedGeometry.x())
2920 emit window->xChanged(actualGeometry.x());
2921 if (actualGeometry.y() != lastReportedGeometry.y())
2922 emit window->yChanged(actualGeometry.y());
2926void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2928 if (e->window.isNull())
2930 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2933 e->eventAccepted =
false;
2938 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2940 e->eventAccepted = event.isAccepted();
2943void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2945 if (e->url.isEmpty())
2948 QFileOpenEvent event(e->url);
2949 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2952QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2954 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2955 TabletPointData &pointData = tabletDevicePoints[i];
2956 if (pointData.deviceId == deviceId)
2960 tabletDevicePoints.append(TabletPointData(deviceId));
2961 return tabletDevicePoints.last();
2964void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2966#if QT_CONFIG(tabletevent)
2967 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2968 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2970 QEvent::Type type = QEvent::TabletMove;
2971 if (e->buttons != pointData.state)
2972 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2974 QWindow *window = e->window.data();
2975 modifier_buttons = e->modifiers;
2977 bool localValid =
true;
2981 if (type == QEvent::TabletPress) {
2982 if (e->nullWindow()) {
2983 window = QGuiApplication::topLevelAt(e->global.toPoint());
2988 active_popup_on_press = activePopupWindow();
2989 pointData.target = window;
2991 if (e->nullWindow()) {
2992 window = pointData.target;
2995 if (type == QEvent::TabletRelease)
2996 pointData.target =
nullptr;
3000 QPointF local = e->local;
3002 QPointF delta = e->global - e->global.toPoint();
3003 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3007 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3008 Qt::MouseButton button = Qt::NoButton;
3009 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3010 if (check & stateChange) {
3011 button = Qt::MouseButton(check);
3016 const auto *activePopup = activePopupWindow();
3017 if (window->d_func()->blockedByModalWindow && !activePopup) {
3022 QTabletEvent tabletEvent(type, device, local, e->global,
3023 e->pressure, e->xTilt, e->yTilt,
3024 e->tangentialPressure, e->rotation, e->z,
3025 e->modifiers, button, e->buttons);
3026 tabletEvent.setAccepted(
false);
3027 tabletEvent.setTimestamp(e->timestamp);
3029 if (activePopup && activePopup != window) {
3031 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3035 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3036 pointData.state = e->buttons;
3037 if (!tabletEvent.isAccepted()
3038 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3039 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3041 const QEvent::Type mouseType = [&]() {
3043 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3044 case QEvent::TabletMove:
return QEvent::MouseMove;
3045 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3046 default: Q_UNREACHABLE();
3049 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3050 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3051 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3052 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3053 << e->local << button << e->buttons << e->modifiers;
3054 processMouseEvent(&mouseEvent);
3061void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3063#if QT_CONFIG(tabletevent)
3064 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3065 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3066 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3067 tabletDevicePoint(dev->uniqueId().numericId()).state);
3068 ev.setTimestamp(e->timestamp);
3069 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3075void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3077#if QT_CONFIG(tabletevent)
3078 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3079 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3080 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3081 tabletDevicePoint(dev->uniqueId().numericId()).state);
3082 ev.setTimestamp(e->timestamp);
3083 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3089#ifndef QT_NO_GESTURES
3090void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3092 if (e->window.isNull())
3095 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3096 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3097 e->delta, e->sequenceId);
3098 ev.setTimestamp(e->timestamp);
3099 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3103void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3108 if (e->window->d_func()->blockedByModalWindow) {
3113 QEvent ev(QEvent::PlatformPanel);
3114 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3117#ifndef QT_NO_CONTEXTMENU
3118void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3122 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3125 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3126 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3127 e->eventAccepted = ev.isAccepted();
3131void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3133 if (!QInputDevicePrivate::isRegistered(e->device))
3136 modifier_buttons = e->modifiers;
3137 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3138 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3140 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3142 if (e->touchType == QEvent::TouchCancel) {
3145 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3146 touchEvent.setTimestamp(e->timestamp);
3147 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3148 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3150 for (
auto &epd : devPriv->activePoints.values()) {
3151 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3152 windowsNeedingCancel.insert(w);
3155 for (QWindow *w : windowsNeedingCancel)
3156 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3158 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3159 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3160 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3161 if (!synthIt->window)
3163 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3170 QEvent::MouseButtonRelease,
3171 Qt::MouseEventNotSynthesized,
3174 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3175 processMouseEvent(&fake);
3177 guiAppPrivate->synthesizedMousePoints.clear();
3179 guiAppPrivate->lastTouchType = e->touchType;
3184 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3187 guiAppPrivate->lastTouchType = e->touchType;
3189 QPointer<QWindow> window = e->window;
3190 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3196 for (
auto &tempPt : e->points) {
3198 auto epd = devPriv->pointById(tempPt.id());
3199 auto &ep = epd->eventPoint;
3200 epd->eventPoint.setAccepted(
false);
3201 switch (tempPt.state()) {
3202 case QEventPoint::State::Pressed:
3204 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3205 window = devPriv->firstActiveWindow();
3208 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3209 QMutableEventPoint::setWindow(ep, window);
3210 active_popup_on_press = activePopupWindow();
3213 case QEventPoint::State::Released:
3214 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3215 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3216 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3217 window = QMutableEventPoint::window(ep);
3221 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3222 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3223 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3224 window = QMutableEventPoint::window(ep);
3228 if (Q_UNLIKELY(!window)) {
3229 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3232 QMutableEventPoint::update(tempPt, ep);
3234 Q_ASSERT(window.data() !=
nullptr);
3237 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3240 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3243 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3247 for (QMutableTouchEvent &ev : touchEvents) {
3248 if (ev.target() == window.data()) {
3255 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3256 mte.setTimestamp(e->timestamp);
3257 mte.setTarget(window.data());
3258 touchEvents.append(mte);
3262 if (touchEvents.isEmpty())
3265 for (QMutableTouchEvent &touchEvent : touchEvents) {
3266 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3268 QEvent::Type eventType;
3269 switch (touchEvent.touchPointStates()) {
3270 case QEventPoint::State::Pressed:
3271 eventType = QEvent::TouchBegin;
3273 case QEventPoint::State::Released:
3274 eventType = QEvent::TouchEnd;
3277 eventType = QEvent::TouchUpdate;
3281 const auto *activePopup = activePopupWindow();
3282 if (window->d_func()->blockedByModalWindow && !activePopup) {
3286 if (touchEvent.type() == QEvent::TouchEnd) {
3289 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3290 touchEvent.setTimestamp(e->timestamp);
3291 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3296 if (activePopup && activePopup != window) {
3298 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3305 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3307 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3309 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3311 QEvent::Type mouseEventType = QEvent::MouseMove;
3312 Qt::MouseButton button = Qt::NoButton;
3313 Qt::MouseButtons buttons = Qt::LeftButton;
3314 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3315 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3316 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3318 if (m_fakeMouseSourcePointId >= 0) {
3319 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3321 switch (touchPoint->state()) {
3322 case QEventPoint::State::Pressed:
3323 mouseEventType = QEvent::MouseButtonPress;
3324 button = Qt::LeftButton;
3326 case QEventPoint::State::Released:
3327 mouseEventType = QEvent::MouseButtonRelease;
3328 button = Qt::LeftButton;
3329 buttons = Qt::NoButton;
3330 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3331 m_fakeMouseSourcePointId = -1;
3336 if (touchPoint->state() != QEventPoint::State::Released) {
3337 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3338 touchPoint->position(), touchPoint->globalPosition(), window));
3344 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3345 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3346 touchPoint->globalPosition(),
3351 Qt::MouseEventSynthesizedByQt,
3355 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3356 processMouseEvent(&fake);
3359 if (eventType == QEvent::TouchEnd)
3360 guiAppPrivate->synthesizedMousePoints.clear();
3367 for (
const QEventPoint &touchPoint : e->points) {
3368 if (touchPoint.state() == QEventPoint::State::Released)
3369 devPriv->removePointById(touchPoint.id());
3373void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3376 if (QCoreApplication::startingUp())
3382 QScreen *s = e->screen.data();
3383 s->d_func()->orientation = e->orientation;
3385 emit s->orientationChanged(s->orientation());
3387 QScreenOrientationChangeEvent event(s, s->orientation());
3388 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3391void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3394 if (QCoreApplication::startingUp())
3401 QScreen *s = e->screen.data();
3402 QScreenPrivate::UpdateEmitter updateEmitter(s);
3406 s->d_func()->geometry = e->geometry;
3407 s->d_func()->availableGeometry = e->availableGeometry;
3409 s->d_func()->updatePrimaryOrientation();
3412 resetCachedDevicePixelRatio();
3415void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3418 if (QCoreApplication::startingUp())
3421 QHighDpiScaling::updateHighDpiScaling();
3427 QScreen *s = e->screen.data();
3428 QScreenPrivate::UpdateEmitter updateEmitter(s);
3429 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3430 s->d_func()->updateGeometry();
3433 for (QWindow *window : QGuiApplication::allWindows())
3434 if (window->screen() == e->screen)
3435 QWindowPrivate::get(window)->updateDevicePixelRatio();
3437 resetCachedDevicePixelRatio();
3440void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3443 if (QCoreApplication::startingUp())
3449 QScreen *s = e->screen.data();
3450 qreal rate = e->rate;
3454 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3455 s->d_func()->refreshRate = rate;
3456 emit s->refreshRateChanged(s->refreshRate());
3460void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3465 QWindow *window = e->window.data();
3468 QWindowPrivate *p = qt_window_private(window);
3475 p->positionAutomatic =
false;
3476 p->resizeAutomatic =
false;
3479 if (!p->receivedExpose) {
3480 if (p->resizeEventPending) {
3483 QResizeEvent e(window->geometry().size(), p->geometry.size());
3484 QGuiApplication::sendSpontaneousEvent(window, &e);
3486 p->resizeEventPending =
false;
3495 p->receivedExpose =
true;
3499 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3501 const bool wasExposed = p->exposed;
3502 p->exposed = e->isExposed && window->screen();
3507 if (e->isExposed && !e->region.isEmpty()) {
3508 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3510 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3511 <<
"Please file a QTBUG which explains how to reproduce.";
3515 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3516 QPaintEvent paintEvent(e->region);
3517 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3518 if (paintEvent.isAccepted())
3526 QExposeEvent exposeEvent(e->region);
3527 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3528 e->eventAccepted = exposeEvent.isAccepted();
3535 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3536 QPaintEvent paintEvent(e->region);
3537 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3541void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3543 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3544 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3549 QPaintEvent paintEvent(e->region);
3550 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3554 e->eventAccepted = paintEvent.isAccepted();
3557#if QT_CONFIG(draganddrop)
3560
3561
3562
3563
3564static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3566 QGuiApplicationPrivate::mouse_buttons = buttons;
3567 QGuiApplicationPrivate::modifier_buttons = modifiers;
3570QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3571 const QPoint &p, Qt::DropActions supportedActions,
3572 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3574 updateMouseAndModifierButtonState(buttons, modifiers);
3576 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3577 QPlatformDrag *platformDrag = platformIntegration()->drag();
3578 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3579 lastAcceptedDropAction = Qt::IgnoreAction;
3580 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3584 currentDragWindow =
nullptr;
3586 QGuiApplication::sendEvent(w, &e);
3587 lastAcceptedDropAction = Qt::IgnoreAction;
3588 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3590 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3592 if (w != currentDragWindow) {
3593 lastAcceptedDropAction = Qt::IgnoreAction;
3594 if (currentDragWindow) {
3596 QGuiApplication::sendEvent(currentDragWindow, &e);
3598 currentDragWindow = w;
3599 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3600 QGuiApplication::sendEvent(w, &e);
3601 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3602 lastAcceptedDropAction = e.dropAction();
3606 if (lastAcceptedDropAction != Qt::IgnoreAction
3607 && (supportedActions & lastAcceptedDropAction)) {
3608 me.setDropAction(lastAcceptedDropAction);
3611 QGuiApplication::sendEvent(w, &me);
3612 lastAcceptedDropAction = me.isAccepted() ?
3613 me.dropAction() : Qt::IgnoreAction;
3614 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3617QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3618 const QPoint &p, Qt::DropActions supportedActions,
3619 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3621 updateMouseAndModifierButtonState(buttons, modifiers);
3623 currentDragWindow =
nullptr;
3625 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3626 QGuiApplication::sendEvent(w, &de);
3628 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3629 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3635#ifndef QT_NO_CLIPBOARD
3637
3638
3639QClipboard * QGuiApplication::clipboard()
3641 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3643 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3646 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3648 return QGuiApplicationPrivate::qt_clipboard;
3653
3654
3655
3656
3657
3658
3659
3660
3661
3664
3665
3666
3667
3668
3669
3671QPalette QGuiApplication::palette()
3673 if (!QGuiApplicationPrivate::app_pal)
3674 QGuiApplicationPrivate::updatePalette();
3676 return *QGuiApplicationPrivate::app_pal;