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;
2604 if (e->nullWindow())
2605 window = QGuiApplication::focusWindow();
2608 e->eventAccepted =
false;
2612#if !defined(Q_OS_MACOS)
2615 if (e->keyType == QEvent::KeyPress) {
2616 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2617 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2623 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2624 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2625 e->unicode, e->repeat, e->repeatCount);
2626 ev.setTimestamp(e->timestamp);
2628 const auto *activePopup = activePopupWindow();
2629 if (activePopup && activePopup != window) {
2631 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2637 if (!window->d_func()->blockedByModalWindow)
2638 QGuiApplication::sendSpontaneousEvent(window, &ev);
2641 ev.setAccepted(
false);
2643 e->eventAccepted = ev.isAccepted();
2646void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2650 if (e->enter.data()->d_func()->blockedByModalWindow) {
2655 currentMouseWindow = e->enter;
2658 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2665 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2666 auto epd = devPriv->queryPointById(event.points().first().id());
2668 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2670 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2673void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2677 if (e->leave.data()->d_func()->blockedByModalWindow) {
2682 currentMouseWindow =
nullptr;
2684 QEvent event(QEvent::Leave);
2685 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2688void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2690 QWindow *previous = QGuiApplicationPrivate::focus_window;
2691 QWindow *newFocus = e->focused.data();
2693 if (previous == newFocus)
2696 bool activatedPopup =
false;
2698 if (QPlatformWindow *platformWindow = newFocus->handle())
2699 if (platformWindow->isAlertState())
2700 platformWindow->setAlertState(
false);
2701 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2703 activatePopup(newFocus);
2706 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2709 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2710 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2713 QGuiApplicationPrivate::focus_window = newFocus;
2718 Qt::FocusReason r = e->reason;
2719 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2720 r = Qt::PopupFocusReason;
2721 QFocusEvent focusOut(QEvent::FocusOut, r);
2722 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2723 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2724 qApp, SLOT(_q_updateFocusObject(QObject*)));
2725 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2726 setApplicationState(Qt::ApplicationActive);
2729 if (QGuiApplicationPrivate::focus_window) {
2730 Qt::FocusReason r = e->reason;
2731 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2732 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2733 r = Qt::PopupFocusReason;
2734 QFocusEvent focusIn(QEvent::FocusIn, r);
2735 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2736 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2737 qApp, SLOT(_q_updateFocusObject(QObject*)));
2738 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2739 setApplicationState(Qt::ApplicationInactive);
2742 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2743 guiAppPrivate->notifyActiveWindowChange(previous);
2745 if (previousFocusObject !=
qApp->focusObject() ||
2751 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2752 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2756 emit
qApp->focusWindowChanged(newFocus);
2758 emit previous->activeChanged();
2760 emit newFocus->activeChanged();
2763void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2765 if (QWindow *window = wse->window.data()) {
2766 QWindowPrivate *windowPrivate = qt_window_private(window);
2767 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2769 windowPrivate->windowState = wse->newState;
2770 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2771 if (newEffectiveState != originalEffectiveState)
2772 emit window->windowStateChanged(newEffectiveState);
2774 windowPrivate->updateVisibility();
2776 QWindowStateChangeEvent e(wse->oldState);
2777 QGuiApplication::sendSpontaneousEvent(window, &e);
2781void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2783 QWindow *window = wse->window.data();
2787 QScreen *screen = wse->screen.data();
2788 if (window->screen() == screen)
2791 auto *windowPrivate = QWindowPrivate::get(window);
2792 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2793 if (window == topLevelWindow) {
2795 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2797 topLevelWindow->setScreen(
nullptr);
2798 }
else if (screen) {
2803 windowPrivate->emitScreenChangedRecursion(screen);
2807void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2809 if (wde->window.isNull())
2811 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2814void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2816 if (wse->window.isNull())
2819 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2821 QEvent event(QEvent::SafeAreaMarginsChange);
2822 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2825void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2832 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2833 guiAppPrivate->handleThemeChanged();
2835 QIconPrivate::clearIconCache();
2837 QEvent themeChangeEvent(QEvent::ThemeChange);
2838 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2841void QGuiApplicationPrivate::handleThemeChanged()
2843 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2846 QIconLoader::instance()->updateSystemTheme();
2847 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2849 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2850 const auto locker = qt_scoped_lock(applicationFontMutex);
2851 clearFontUnlocked();
2857void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2859 if (e->window.isNull())
2862 QWindow *window = e->window.data();
2866 const QRect lastReportedGeometry = window->d_func()->geometry;
2867 const QRect requestedGeometry = e->requestedGeometry;
2868 const QRect actualGeometry = e->newGeometry;
2878 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2879 || requestedGeometry.size() != actualGeometry.size();
2880 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2881 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2883 window->d_func()->geometry = actualGeometry;
2885 if (isResize || window->d_func()->resizeEventPending) {
2886 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2887 QGuiApplication::sendSpontaneousEvent(window, &e);
2889 window->d_func()->resizeEventPending =
false;
2891 if (actualGeometry.width() != lastReportedGeometry.width())
2892 emit window->widthChanged(actualGeometry.width());
2893 if (actualGeometry.height() != lastReportedGeometry.height())
2894 emit window->heightChanged(actualGeometry.height());
2899 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2900 QGuiApplication::sendSpontaneousEvent(window, &e);
2902 if (actualGeometry.x() != lastReportedGeometry.x())
2903 emit window->xChanged(actualGeometry.x());
2904 if (actualGeometry.y() != lastReportedGeometry.y())
2905 emit window->yChanged(actualGeometry.y());
2909void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2911 if (e->window.isNull())
2913 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2916 e->eventAccepted =
false;
2921 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2923 e->eventAccepted = event.isAccepted();
2926void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2928 if (e->url.isEmpty())
2931 QFileOpenEvent event(e->url);
2932 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2935QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2937 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2938 TabletPointData &pointData = tabletDevicePoints[i];
2939 if (pointData.deviceId == deviceId)
2943 tabletDevicePoints.append(TabletPointData(deviceId));
2944 return tabletDevicePoints.last();
2947void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2949#if QT_CONFIG(tabletevent)
2950 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2951 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2953 QEvent::Type type = QEvent::TabletMove;
2954 if (e->buttons != pointData.state)
2955 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2957 QWindow *window = e->window.data();
2958 modifier_buttons = e->modifiers;
2960 bool localValid =
true;
2964 if (type == QEvent::TabletPress) {
2965 if (e->nullWindow()) {
2966 window = QGuiApplication::topLevelAt(e->global.toPoint());
2971 active_popup_on_press = activePopupWindow();
2972 pointData.target = window;
2974 if (e->nullWindow()) {
2975 window = pointData.target;
2978 if (type == QEvent::TabletRelease)
2979 pointData.target =
nullptr;
2983 QPointF local = e->local;
2985 QPointF delta = e->global - e->global.toPoint();
2986 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2990 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2991 Qt::MouseButton button = Qt::NoButton;
2992 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
2993 if (check & stateChange) {
2994 button = Qt::MouseButton(check);
2999 const auto *activePopup = activePopupWindow();
3000 if (window->d_func()->blockedByModalWindow && !activePopup) {
3005 QTabletEvent tabletEvent(type, device, local, e->global,
3006 e->pressure, e->xTilt, e->yTilt,
3007 e->tangentialPressure, e->rotation, e->z,
3008 e->modifiers, button, e->buttons);
3009 tabletEvent.setAccepted(
false);
3010 tabletEvent.setTimestamp(e->timestamp);
3012 if (activePopup && activePopup != window) {
3014 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3018 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3019 pointData.state = e->buttons;
3020 if (!tabletEvent.isAccepted()
3021 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3022 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3024 const QEvent::Type mouseType = [&]() {
3026 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3027 case QEvent::TabletMove:
return QEvent::MouseMove;
3028 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3029 default: Q_UNREACHABLE();
3032 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3033 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3034 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3035 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3036 << e->local << button << e->buttons << e->modifiers;
3037 processMouseEvent(&mouseEvent);
3044void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3046#if QT_CONFIG(tabletevent)
3047 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3048 QTabletEvent ev(QEvent::TabletEnterProximity, dev, e->local, e->global,
3049 e->pressure, e->xTilt, e->yTilt,
3050 e->tangentialPressure, e->rotation, e->z,
3051 e->modifiers, Qt::NoButton,
3052 tabletDevicePoint(dev->uniqueId().numericId()).state);
3053 ev.setTimestamp(e->timestamp);
3054 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3060void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3062#if QT_CONFIG(tabletevent)
3063 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3064 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, e->local, e->global,
3065 e->pressure, e->xTilt, e->yTilt,
3066 e->tangentialPressure, e->rotation, e->z,
3067 e->modifiers, Qt::NoButton,
3068 tabletDevicePoint(dev->uniqueId().numericId()).state);
3069 ev.setTimestamp(e->timestamp);
3070 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3076#ifndef QT_NO_GESTURES
3077void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3079 if (e->window.isNull())
3082 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3083 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3084 e->delta, e->sequenceId);
3085 ev.setTimestamp(e->timestamp);
3086 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3090void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3095 if (e->window->d_func()->blockedByModalWindow) {
3100 QEvent ev(QEvent::PlatformPanel);
3101 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3104#ifndef QT_NO_CONTEXTMENU
3105void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3109 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3112 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3113 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3114 e->eventAccepted = ev.isAccepted();
3118void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3120 if (!QInputDevicePrivate::isRegistered(e->device))
3123 modifier_buttons = e->modifiers;
3124 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3125 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3127 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3129 if (e->touchType == QEvent::TouchCancel) {
3132 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3133 touchEvent.setTimestamp(e->timestamp);
3134 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3135 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3137 for (
auto &epd : devPriv->activePoints.values()) {
3138 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3139 windowsNeedingCancel.insert(w);
3142 for (QWindow *w : windowsNeedingCancel)
3143 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3145 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3146 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3147 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3148 if (!synthIt->window)
3150 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3157 QEvent::MouseButtonRelease,
3158 Qt::MouseEventNotSynthesized,
3161 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3162 processMouseEvent(&fake);
3164 guiAppPrivate->synthesizedMousePoints.clear();
3166 guiAppPrivate->lastTouchType = e->touchType;
3171 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3174 guiAppPrivate->lastTouchType = e->touchType;
3176 QPointer<QWindow> window = e->window;
3177 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3183 for (
auto &tempPt : e->points) {
3185 auto epd = devPriv->pointById(tempPt.id());
3186 auto &ep = epd->eventPoint;
3187 epd->eventPoint.setAccepted(
false);
3188 switch (tempPt.state()) {
3189 case QEventPoint::State::Pressed:
3191 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3192 window = devPriv->firstActiveWindow();
3195 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3196 QMutableEventPoint::setWindow(ep, window);
3197 active_popup_on_press = activePopupWindow();
3200 case QEventPoint::State::Released:
3201 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3202 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3203 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3204 window = QMutableEventPoint::window(ep);
3208 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3209 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3210 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3211 window = QMutableEventPoint::window(ep);
3215 if (Q_UNLIKELY(!window)) {
3216 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3219 QMutableEventPoint::update(tempPt, ep);
3221 Q_ASSERT(window.data() !=
nullptr);
3224 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3227 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3230 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3234 for (QMutableTouchEvent &ev : touchEvents) {
3235 if (ev.target() == window.data()) {
3242 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3243 mte.setTimestamp(e->timestamp);
3244 mte.setTarget(window.data());
3245 touchEvents.append(mte);
3249 if (touchEvents.isEmpty())
3252 for (QMutableTouchEvent &touchEvent : touchEvents) {
3253 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3255 QEvent::Type eventType;
3256 switch (touchEvent.touchPointStates()) {
3257 case QEventPoint::State::Pressed:
3258 eventType = QEvent::TouchBegin;
3260 case QEventPoint::State::Released:
3261 eventType = QEvent::TouchEnd;
3264 eventType = QEvent::TouchUpdate;
3268 const auto *activePopup = activePopupWindow();
3269 if (window->d_func()->blockedByModalWindow && !activePopup) {
3273 if (touchEvent.type() == QEvent::TouchEnd) {
3276 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3277 touchEvent.setTimestamp(e->timestamp);
3278 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3283 if (activePopup && activePopup != window) {
3285 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3292 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3294 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3296 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3298 QEvent::Type mouseEventType = QEvent::MouseMove;
3299 Qt::MouseButton button = Qt::NoButton;
3300 Qt::MouseButtons buttons = Qt::LeftButton;
3301 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3302 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3303 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3305 if (m_fakeMouseSourcePointId >= 0) {
3306 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3308 switch (touchPoint->state()) {
3309 case QEventPoint::State::Pressed:
3310 mouseEventType = QEvent::MouseButtonPress;
3311 button = Qt::LeftButton;
3313 case QEventPoint::State::Released:
3314 mouseEventType = QEvent::MouseButtonRelease;
3315 button = Qt::LeftButton;
3316 buttons = Qt::NoButton;
3317 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3318 m_fakeMouseSourcePointId = -1;
3323 if (touchPoint->state() != QEventPoint::State::Released) {
3324 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3325 touchPoint->position(), touchPoint->globalPosition(), window));
3331 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3332 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3333 touchPoint->globalPosition(),
3338 Qt::MouseEventSynthesizedByQt,
3342 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3343 processMouseEvent(&fake);
3346 if (eventType == QEvent::TouchEnd)
3347 guiAppPrivate->synthesizedMousePoints.clear();
3354 for (
const QEventPoint &touchPoint : e->points) {
3355 if (touchPoint.state() == QEventPoint::State::Released)
3356 devPriv->removePointById(touchPoint.id());
3360void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3363 if (QCoreApplication::startingUp())
3369 QScreen *s = e->screen.data();
3370 s->d_func()->orientation = e->orientation;
3372 emit s->orientationChanged(s->orientation());
3374 QScreenOrientationChangeEvent event(s, s->orientation());
3375 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3378void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3381 if (QCoreApplication::startingUp())
3388 QScreen *s = e->screen.data();
3389 QScreenPrivate::UpdateEmitter updateEmitter(s);
3393 s->d_func()->geometry = e->geometry;
3394 s->d_func()->availableGeometry = e->availableGeometry;
3396 s->d_func()->updatePrimaryOrientation();
3399 resetCachedDevicePixelRatio();
3402void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3405 if (QCoreApplication::startingUp())
3408 QHighDpiScaling::updateHighDpiScaling();
3414 QScreen *s = e->screen.data();
3415 QScreenPrivate::UpdateEmitter updateEmitter(s);
3416 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3417 s->d_func()->updateGeometry();
3420 for (QWindow *window : QGuiApplication::allWindows())
3421 if (window->screen() == e->screen)
3422 QWindowPrivate::get(window)->updateDevicePixelRatio();
3424 resetCachedDevicePixelRatio();
3427void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3430 if (QCoreApplication::startingUp())
3436 QScreen *s = e->screen.data();
3437 qreal rate = e->rate;
3441 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3442 s->d_func()->refreshRate = rate;
3443 emit s->refreshRateChanged(s->refreshRate());
3447void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3452 QWindow *window = e->window.data();
3455 QWindowPrivate *p = qt_window_private(window);
3462 p->positionAutomatic =
false;
3463 p->resizeAutomatic =
false;
3466 if (!p->receivedExpose) {
3467 if (p->resizeEventPending) {
3470 QResizeEvent e(window->geometry().size(), p->geometry.size());
3471 QGuiApplication::sendSpontaneousEvent(window, &e);
3473 p->resizeEventPending =
false;
3482 p->receivedExpose =
true;
3486 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3488 const bool wasExposed = p->exposed;
3489 p->exposed = e->isExposed && window->screen();
3494 if (e->isExposed && !e->region.isEmpty()) {
3495 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3497 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3498 <<
"Please file a QTBUG which explains how to reproduce.";
3502 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3503 QPaintEvent paintEvent(e->region);
3504 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3505 if (paintEvent.isAccepted())
3513 QExposeEvent exposeEvent(e->region);
3514 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3515 e->eventAccepted = exposeEvent.isAccepted();
3522 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3523 QPaintEvent paintEvent(e->region);
3524 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3528void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3530 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3531 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3536 QPaintEvent paintEvent(e->region);
3537 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3541 e->eventAccepted = paintEvent.isAccepted();
3544#if QT_CONFIG(draganddrop)
3547
3548
3549
3550
3551static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3553 QGuiApplicationPrivate::mouse_buttons = buttons;
3554 QGuiApplicationPrivate::modifier_buttons = modifiers;
3557QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3558 const QPoint &p, Qt::DropActions supportedActions,
3559 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3561 updateMouseAndModifierButtonState(buttons, modifiers);
3563 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3564 QPlatformDrag *platformDrag = platformIntegration()->drag();
3565 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3566 lastAcceptedDropAction = Qt::IgnoreAction;
3567 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3571 currentDragWindow =
nullptr;
3573 QGuiApplication::sendEvent(w, &e);
3574 lastAcceptedDropAction = Qt::IgnoreAction;
3575 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3577 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3579 if (w != currentDragWindow) {
3580 lastAcceptedDropAction = Qt::IgnoreAction;
3581 if (currentDragWindow) {
3583 QGuiApplication::sendEvent(currentDragWindow, &e);
3585 currentDragWindow = w;
3586 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3587 QGuiApplication::sendEvent(w, &e);
3588 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3589 lastAcceptedDropAction = e.dropAction();
3593 if (lastAcceptedDropAction != Qt::IgnoreAction
3594 && (supportedActions & lastAcceptedDropAction)) {
3595 me.setDropAction(lastAcceptedDropAction);
3598 QGuiApplication::sendEvent(w, &me);
3599 lastAcceptedDropAction = me.isAccepted() ?
3600 me.dropAction() : Qt::IgnoreAction;
3601 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3604QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3605 const QPoint &p, Qt::DropActions supportedActions,
3606 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3608 updateMouseAndModifierButtonState(buttons, modifiers);
3610 currentDragWindow =
nullptr;
3612 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3613 QGuiApplication::sendEvent(w, &de);
3615 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3616 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3622#ifndef QT_NO_CLIPBOARD
3624
3625
3626QClipboard * QGuiApplication::clipboard()
3628 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3630 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3633 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3635 return QGuiApplicationPrivate::qt_clipboard;
3640
3641
3642
3643
3644
3645
3646
3647
3648
3651
3652
3653
3654
3655
3656
3658QPalette QGuiApplication::palette()
3660 if (!QGuiApplicationPrivate::app_pal)
3661 QGuiApplicationPrivate::updatePalette();
3663 return *QGuiApplicationPrivate::app_pal;