101#include <private/qvulkandefaultinstance_p.h>
105#include <QtCore/QThreadPool>
108#include <qtgui_tracepoints_p.h>
110#include <private/qtools_p.h>
119using namespace Qt::StringLiterals;
120using namespace QtMiscUtils;
123#define CHECK_QAPP_INSTANCE(...)
124 if (Q_LIKELY(QCoreApplication::instance())) {
126 qWarning("Must construct a QGuiApplication first.");
133Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
134Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
136Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
142Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
144Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
145 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
147Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
149Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
154Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
171Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
178Q_CONSTINIT
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
179Q_CONSTINIT
static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
182Q_DECL_DEPRECATED_X(
"Use QGuiApplicationPrivate::instance() instead")
183Q_CONSTINIT QGuiApplicationPrivate *QGuiApplicationPrivate::self =
nullptr;
185Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
187#ifndef QT_NO_CLIPBOARD
191Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
193Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
194Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
195Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
198Q_CONSTINIT
static QBasicMutex applicationFontMutex;
201Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
202Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
206Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
207Q_CONSTINIT QBasicAtomicInt QGuiApplicationPrivate::m_primaryScreenDpis = Q_BASIC_ATOMIC_INITIALIZER(0);
209Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
211Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
214#if QT_CONFIG(animation)
215extern void qRegisterGuiGetInterpolator();
220 return force_reverse ^
221 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
222 "Translate this string to the string 'LTR' in left-to-right"
223 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
224 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
229 if (!QGuiApplicationPrivate::app_font) {
230 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
231 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
232 QGuiApplicationPrivate::app_font =
new QFont(*font);
234 if (!QGuiApplicationPrivate::app_font)
235 QGuiApplicationPrivate::app_font =
236 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
241 delete QGuiApplicationPrivate::app_font;
242 QGuiApplicationPrivate::app_font =
nullptr;
247 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
248 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
251#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
252static bool checkNeedPortalSupport()
255 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
263#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
283 const qsizetype size = a.size();
288 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
290 else if (isAsciiDigit(*op))
295 const int numberPos = pos;
296 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
299 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
300 return ok ? result : -1;
307 for (
int i = 0; i < 4; ++i) {
309 const int value = nextGeometryToken(a, pos, &op);
321 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
325 result.corner = Qt::TopRightCorner;
334 QRect windowGeometry = window->frameGeometry();
335 QSize size = windowGeometry.size();
337 const QSize windowMinimumSize = window->minimumSize();
338 const QSize windowMaximumSize = window->maximumSize();
340 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
342 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
343 window->resize(size);
346 const QRect availableGeometry = window->screen()->virtualGeometry();
347 QPoint topLeft = windowGeometry.topLeft();
349 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
351 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
354 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
356 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
358 window->setFramePosition(topLeft);
365
366
367
368
369
370
371
372
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
495
498
499
500
501
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
656
658QGuiApplication::QGuiApplication(
int &argc,
char **argv)
660QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
662 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
666 QCoreApplicationPrivate::eventDispatcher->startingUp();
670
671
672QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
673 : QCoreApplication(p)
678
679
680QGuiApplication::~QGuiApplication()
682 Q_D(QGuiApplication);
684 qt_call_post_routines();
686 d->eventDispatcher->closingDown();
687 d->eventDispatcher =
nullptr;
689#ifndef QT_NO_CLIPBOARD
690 delete QGuiApplicationPrivate::qt_clipboard;
691 QGuiApplicationPrivate::qt_clipboard =
nullptr;
694#ifndef QT_NO_SESSIONMANAGER
695 delete d->session_manager;
696 d->session_manager =
nullptr;
699 QGuiApplicationPrivate::clearPalette();
700 QFontDatabase::removeAllApplicationFonts();
703 d->cursor_list.clear();
706#if QT_CONFIG(qtgui_threadpool)
708 QThreadPool *guiThreadPool =
nullptr;
710 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
715 guiThreadPool->waitForDone();
716 delete guiThreadPool;
720 delete QGuiApplicationPrivate::app_icon;
721 QGuiApplicationPrivate::app_icon =
nullptr;
722 delete QGuiApplicationPrivate::platform_name;
723 QGuiApplicationPrivate::platform_name =
nullptr;
724 delete QGuiApplicationPrivate::displayName;
725 QGuiApplicationPrivate::displayName =
nullptr;
726 delete QGuiApplicationPrivate::m_inputDeviceManager;
727 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
728 delete QGuiApplicationPrivate::desktopFileName;
729 QGuiApplicationPrivate::desktopFileName =
nullptr;
730 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
731 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
732 QGuiApplicationPrivate::lastCursorPosition.reset();
733 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
734 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
735 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
736 QGuiApplicationPrivate::currentDragWindow =
nullptr;
737 QGuiApplicationPrivate::tabletDevicePoints.clear();
738 QGuiApplicationPrivate::m_primaryScreenDpis.storeRelaxed(0);
741QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
742 : QCoreApplicationPrivate(argc, argv),
743 inputMethod(
nullptr),
744 lastTouchType(QEvent::TouchEnd)
747 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
this;)
749 application_type = QCoreApplicationPrivate::Gui;
750#ifndef QT_NO_SESSIONMANAGER
751 is_session_restored =
false;
752 is_saving_session =
false;
757
758
759
760
761
762
763
764
765
766
767
768void QGuiApplication::setApplicationDisplayName(
const QString &name)
770 if (!QGuiApplicationPrivate::displayName) {
771 QGuiApplicationPrivate::displayName =
new QString(name);
773 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
774 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
776 if (*QGuiApplicationPrivate::displayName != applicationName())
777 emit
qGuiApp->applicationDisplayNameChanged();
779 }
else if (name != *QGuiApplicationPrivate::displayName) {
780 *QGuiApplicationPrivate::displayName = name;
782 emit
qGuiApp->applicationDisplayNameChanged();
786QString QGuiApplication::applicationDisplayName()
788 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810void QGuiApplication::setBadgeNumber(qint64 number)
812 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831void QGuiApplication::setDesktopFileName(
const QString &name)
833 if (!QGuiApplicationPrivate::desktopFileName)
834 QGuiApplicationPrivate::desktopFileName =
new QString;
835 *QGuiApplicationPrivate::desktopFileName = name;
836 if (name.endsWith(QLatin1String(
".desktop"))) {
837 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
838 if (!filePath.isEmpty()) {
839 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
840 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
841 "be removed. Please specify a desktop file name without .desktop suffix");
842 (*QGuiApplicationPrivate::desktopFileName).chop(8);
847QString QGuiApplication::desktopFileName()
849 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
853
854
855
856
857
858
859
860
861
862
863
864
865
866QWindow *QGuiApplication::modalWindow()
869 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
870 if (modalWindows.isEmpty())
872 return modalWindows.constFirst();
877 QWindowPrivate *p = qt_window_private(window);
878 if (p->blockedByModalWindow != shouldBeBlocked) {
879 p->blockedByModalWindow = shouldBeBlocked;
880 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
881 QGuiApplication::sendEvent(window, &e);
882 for (QObject *c : window->children()) {
883 if (c->isWindowType())
884 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
889void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
891 bool shouldBeBlocked =
false;
892 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
893 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
894 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
895 updateBlockedStatusRecursion(window, shouldBeBlocked);
903 return w->isTopLevel();
906void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
908 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
909 guiAppPrivate->modalWindowList.prepend(modal);
912 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
913 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
914 if (shouldBeBlocked) {
916 guiAppPrivate->modalWindowList.removeFirst();
917 QEvent e(QEvent::Leave);
918 QGuiApplication::sendEvent(currentMouseWindow, &e);
919 currentMouseWindow =
nullptr;
920 guiAppPrivate->modalWindowList.prepend(modal);
924 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
925 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
926 updateBlockedStatus(window);
929 updateBlockedStatus(modal);
932void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
934 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
936 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
937 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
938 updateBlockedStatus(window);
942Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
947bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
954
955
956
957
958bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
960 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
962 QWindow *unused =
nullptr;
964 blockingWindow = &unused;
965 *blockingWindow =
nullptr;
967 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
970 for (
int i = 0; i < modalWindowList.size(); ++i) {
971 QWindow *modalWindow = modalWindowList.at(i);
975 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
978 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
979 : modalWindow->modality()) {
980 case Qt::ApplicationModal:
981 *blockingWindow = modalWindow;
983 case Qt::WindowModal: {
986 auto *current = window;
988 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
989 *blockingWindow = modalWindow;
992 current = current->parent(QWindow::IncludeTransients);
997 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1004QWindow *QGuiApplicationPrivate::activePopupWindow()
1007 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1008 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1011void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1013 if (!popup->isVisible())
1015 popup_list.removeOne(popup);
1016 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1017 popup_list.append(popup);
1020bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1022 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1023 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1028
1029
1030bool QGuiApplicationPrivate::closeAllPopups()
1036 while ((popup = activePopupWindow()) && maxiter--)
1038 return QGuiApplicationPrivate::popup_list.isEmpty();
1042
1043
1044
1045
1046
1047QWindow *QGuiApplication::focusWindow()
1049 return QGuiApplicationPrivate::focus_window;
1053
1054
1055
1056
1057
1058
1059
1062
1063
1064
1065
1066
1067
1068
1071
1072
1073
1074QObject *QGuiApplication::focusObject()
1077 return focusWindow()->focusObject();
1082
1083
1084
1085
1086
1087
1088
1089
1090QWindowList QGuiApplication::allWindows()
1092 return QGuiApplicationPrivate::window_list;
1096
1097
1098
1099
1100
1101
1102QWindowList QGuiApplication::topLevelWindows()
1104 const QWindowList &list = QGuiApplicationPrivate::window_list;
1105 QWindowList topLevelWindows;
1106 for (
int i = 0; i < list.size(); ++i) {
1107 QWindow *window = list.at(i);
1108 if (!window->isTopLevel())
1113 if (window->handle() && window->handle()->isEmbedded())
1116 topLevelWindows.prepend(window);
1119 return topLevelWindows;
1122QScreen *QGuiApplication::primaryScreen()
1124 if (QGuiApplicationPrivate::screen_list.isEmpty())
1126 return QGuiApplicationPrivate::screen_list.at(0);
1130
1131
1132
1133QList<QScreen *> QGuiApplication::screens()
1135 return QGuiApplicationPrivate::screen_list;
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149QScreen *QGuiApplication::screenAt(
const QPoint &point)
1151 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1152 for (
const QScreen *screen : QGuiApplication::screens()) {
1153 if (visitedScreens.contains(screen))
1157 for (QScreen *sibling : screen->virtualSiblings()) {
1158 if (sibling->geometry().contains(point))
1161 visitedScreens.append(sibling);
1169
1170
1171
1172
1173
1174
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211qreal QGuiApplication::devicePixelRatio()
const
1213 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1214 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1216 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1217 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1218 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1220 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1223void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1225 m_maxDevicePixelRatio = 0.0;
1228void QGuiApplicationPrivate::_q_updatePrimaryScreenDpis()
1231 const QScreen *screen = QGuiApplication::primaryScreen();
1233 int dpiX = qRound(screen->logicalDotsPerInchX());
1234 int dpiY = qRound(screen->logicalDotsPerInchY());
1235 dpis = (dpiX << 16) | (dpiY & 0xffff);
1236 QObject::connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
1237 q_func(), SLOT(_q_updatePrimaryScreenDpis()), Qt::UniqueConnection);
1239 m_primaryScreenDpis.storeRelaxed(dpis);
1243
1244
1245QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1247 if (QScreen *windowScreen = screenAt(pos)) {
1248 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1249 return windowScreen->handle()->topLevelAt(devicePosition);
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
1289
1291QString QGuiApplication::platformName()
1293 if (!QGuiApplication::instance()) {
1294#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1295 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1300 return QGuiApplicationPrivate::platform_name ?
1301 *QGuiApplicationPrivate::platform_name : QString();
1309static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1311 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1312 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1313 <<
"platformPluginPath" << platformPluginPath
1314 <<
"platformThemeName" << platformThemeName;
1316 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1317 QStringList platformArguments;
1318 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1319 for (
const auto &pluginArgument : std::as_const(plugins)) {
1321 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1322 if (arguments.isEmpty())
1324 const QString name = arguments.takeFirst().toLower();
1325 QString argumentsKey = name;
1328 argumentsKey[0] = argumentsKey.at(0).toUpper();
1329 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1331 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1334 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1335 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1336 if (availablePlugins.contains(name)) {
1337 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1338 qCWarning(lcQpaPluginLoading).nospace().noquote()
1339 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1341 qCInfo(lcQpaPluginLoading).nospace().noquote()
1342 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1343 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1345 qCWarning(lcQpaPluginLoading).nospace().noquote()
1346 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1347 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1350 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1351 QGuiApplicationPrivate::platform_name =
new QString(name);
1352 platformArguments = arguments;
1357 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1358 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1359 "Reinstalling the application may fix this problem.\n");
1361 if (!availablePlugins.isEmpty())
1362 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1364#if defined(Q_OS_WIN)
1367 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1368 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1370 qFatal(
"%s", qPrintable(fatalMessage));
1378 QStringList themeNames;
1379 if (!platformThemeName.isEmpty()) {
1380 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1381 themeNames.append(platformThemeName);
1384#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1386 if (checkNeedPortalSupport()) {
1387 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1388 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1393 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1394 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1395 themeNames.append(platformIntegrationThemeNames);
1398 for (
const QString &themeName : std::as_const(themeNames)) {
1399 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1400 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1401 if (QGuiApplicationPrivate::platform_theme) {
1402 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1405 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1406 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1407 if (QGuiApplicationPrivate::platform_theme) {
1408 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1414 if (!QGuiApplicationPrivate::platform_theme) {
1415 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1416 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1421 if (!platformArguments.isEmpty()) {
1422 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1423 for (
const QString &argument : std::as_const(platformArguments)) {
1424 const qsizetype equalsPos = argument.indexOf(u'=');
1425 const QByteArray name =
1426 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1428 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1429 nativeInterface->setProperty(name.constData(), std::move(value));
1434 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1435 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1436 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1437 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1439 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1440 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1441 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1447 for (
int i = 0; i < pluginList.size(); ++i) {
1448 QByteArray pluginSpec = pluginList.at(i);
1449 qsizetype colonPos = pluginSpec.indexOf(
':');
1452 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1454 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1455 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1457 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1459 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1463#if QT_CONFIG(commandlineparser)
1464void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1466 QCoreApplicationPrivate::addQtOptions(options);
1468#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1469 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1470 const bool x11 = sessionType ==
"x11";
1473 const bool x11 =
false;
1476 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1477 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1478 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1479 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1480 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1481 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1482 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1483 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1484 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1485 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1486 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1487 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1488 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1489 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1490 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1491 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1492 options->append(QCommandLineOption(QStringLiteral(
"session"),
1493 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1496 options->append(QCommandLineOption(QStringLiteral(
"display"),
1497 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1498 options->append(QCommandLineOption(QStringLiteral(
"name"),
1499 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1500 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1501 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1502 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1503 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1504 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1505 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1507 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1508 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1509 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1510 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1511 options->append(QCommandLineOption(QStringLiteral(
"title"),
1512 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1517void QGuiApplicationPrivate::createPlatformIntegration()
1519 QHighDpiScaling::initHighDpiScaling();
1522 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1525 QByteArray platformName;
1526#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1527 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1529#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1530 QList<QByteArray> platformArguments = platformName.split(
':');
1531 QByteArray platformPluginBase = platformArguments.first();
1533 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1534 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1536 QVector<QByteArray> preferredPlatformOrder;
1537 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1538 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1539 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1540 preferredPlatformOrder << xcbPlatformName;
1542 platformName.clear();
1545 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1546 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1547 if (hasWaylandDisplay || isWaylandSessionType) {
1548 preferredPlatformOrder.prepend(waylandPlatformName);
1550 if (defaultIsWayland)
1551 platformName.clear();
1554 if (!platformName.isEmpty())
1555 preferredPlatformOrder.append(platformName);
1557 platformName = preferredPlatformOrder.join(
';');
1560 bool platformExplicitlySelected =
false;
1561 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1562 if (!platformNameEnv.isEmpty()) {
1563 platformName = platformNameEnv;
1564 platformExplicitlySelected =
true;
1567 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1573 int j = argc ? 1 : 0;
1574 for (
int i=1; i<argc; i++) {
1577 if (*argv[i] !=
'-') {
1578 argv[j++] = argv[i];
1581 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1582 const char *arg = argv[i];
1585 if (strcmp(arg,
"-platformpluginpath") == 0) {
1587 platformPluginPath = QFile::decodeName(argv[i]);
1588 }
else if (strcmp(arg,
"-platform") == 0) {
1590 platformExplicitlySelected =
true;
1591 platformName = argv[i];
1593 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1595 platformThemeName = QString::fromLocal8Bit(argv[i]);
1596 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1598 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1599 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1601 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1602 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1604 icon = QFile::decodeName(argv[i]);
1607 argv[j++] = argv[i];
1616 Q_UNUSED(platformExplicitlySelected);
1618 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1619 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1621 if (!icon.isEmpty())
1622 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1626
1627
1628
1629
1630
1631void QGuiApplicationPrivate::createEventDispatcher()
1633 Q_ASSERT(!eventDispatcher);
1635 if (platform_integration ==
nullptr)
1636 createPlatformIntegration();
1639 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1640 "Creating the platform integration resulted in creating an event dispatcher");
1643 Q_ASSERT(!eventDispatcher);
1645 eventDispatcher = platform_integration->createEventDispatcher();
1648void QGuiApplicationPrivate::eventDispatcherReady()
1650 if (platform_integration ==
nullptr)
1651 createPlatformIntegration();
1653 platform_integration->initialize();
1656void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1658 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1660#if defined(Q_OS_MACOS)
1661 QMacAutoReleasePool pool;
1664 QObject::connect(q_func(), SIGNAL(screenAdded(QScreen*)),
1665 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1666 QObject::connect(q_func(), SIGNAL(primaryScreenChanged(QScreen *)),
1667 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1669 QCoreApplicationPrivate::init();
1671 QCoreApplicationPrivate::is_app_running =
false;
1673 bool loadTestability =
false;
1674 QList<QByteArray> pluginList;
1676#ifndef QT_NO_SESSIONMANAGER
1678 QString session_key;
1679# if defined(Q_OS_WIN)
1680 wchar_t guidstr[40];
1682 CoCreateGuid(&guid);
1683 StringFromGUID2(guid, guidstr, 40);
1684 session_id = QString::fromWCharArray(guidstr);
1685 CoCreateGuid(&guid);
1686 StringFromGUID2(guid, guidstr, 40);
1687 session_key = QString::fromWCharArray(guidstr);
1691 int j = argc ? 1 : 0;
1692 for (
int i=1; i<argc; i++) {
1695 if (*argv[i] !=
'-') {
1696 argv[j++] = argv[i];
1699 const char *arg = argv[i];
1702 if (strcmp(arg,
"-plugin") == 0) {
1704 pluginList << argv[i];
1705 }
else if (strcmp(arg,
"-reverse") == 0) {
1706 force_reverse =
true;
1708 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1711 if (QDir::currentPath() ==
"/"_L1) {
1712 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1713 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1714 kCFURLPOSIXPathStyle));
1715 if (qbundlePath.endsWith(
".app"_L1))
1716 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1719#ifndef QT_NO_SESSIONMANAGER
1720 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1722 if (argv[i] && *argv[i]) {
1723 session_id = QString::fromLatin1(argv[i]);
1724 qsizetype p = session_id.indexOf(u'_');
1726 session_key = session_id.mid(p +1);
1727 session_id = session_id.left(p);
1729 is_session_restored =
true;
1732 }
else if (strcmp(arg,
"-testability") == 0) {
1733 loadTestability =
true;
1734 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1735 s = QString::fromLocal8Bit(arg + 7);
1736 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1737 s = QString::fromLocal8Bit(argv[++i]);
1739 argv[j++] = argv[i];
1752 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1753 if (!envPlugins.isEmpty())
1754 pluginList += envPlugins.split(
',');
1756 if (platform_integration ==
nullptr)
1757 createPlatformIntegration();
1760 QFont::initialize();
1764 QCursorData::initialize();
1768 qRegisterGuiVariant();
1770#if QT_CONFIG(animation)
1772 qRegisterGuiGetInterpolator();
1775 QWindowSystemInterfacePrivate::eventTime.start();
1777#if QT_CONFIG(accessibility)
1778 QAccessible::installFactory([](
const QString &classname, QObject *object)
1779 -> QAccessibleInterface * {
1780 if (classname ==
"QForeignWindow"_L1)
1781 return new QAccessibleWindow(
static_cast<QWindow *>(object));
1786 is_app_running =
true;
1787 init_plugins(pluginList);
1788 QWindowSystemInterface::flushWindowSystemEvents();
1790 Q_Q(QGuiApplication);
1791#ifndef QT_NO_SESSIONMANAGER
1793 session_manager =
new QSessionManager(q, session_id, session_key);
1796#if QT_CONFIG(library)
1797 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1798 loadTestability =
true;
1800 if (loadTestability) {
1801 QLibrary testLib(QStringLiteral(
"qttestability"));
1802 if (Q_UNLIKELY(!testLib.load())) {
1803 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1805 typedef void (*TasInitialize)(
void);
1806 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1807 if (Q_UNLIKELY(!initFunction)) {
1808 qCritical(
"Library qttestability resolve failed!");
1815 Q_UNUSED(loadTestability);
1819 QGuiApplication::setLayoutDirection(layout_direction);
1821 if (!QGuiApplicationPrivate::displayName)
1822 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1823 q, &QGuiApplication::applicationDisplayNameChanged);
1826extern void qt_cleanupFontDatabase();
1828QGuiApplicationPrivate::~QGuiApplicationPrivate()
1830#if defined(Q_OS_MACOS)
1831 QMacAutoReleasePool pool;
1834 is_app_closing =
true;
1835 is_app_running =
false;
1837 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1838 delete generic_plugin_list.at(i);
1839 generic_plugin_list.clear();
1841 clearFontUnlocked();
1846 QCursorData::cleanup();
1849 layout_direction = Qt::LayoutDirectionAuto;
1851 cleanupThreadData();
1853 delete QGuiApplicationPrivate::styleHints;
1854 QGuiApplicationPrivate::styleHints =
nullptr;
1857 qt_cleanupFontDatabase();
1859 QPixmapCache::clear();
1862 if (ownGlobalShareContext) {
1863 delete qt_gl_global_share_context();
1864 qt_gl_set_global_share_context(
nullptr);
1868#if QT_CONFIG(vulkan)
1869 QVulkanDefaultInstance::cleanup();
1872 platform_integration->destroy();
1874 delete platform_theme;
1875 platform_theme =
nullptr;
1876 delete platform_integration;
1877 platform_integration =
nullptr;
1879 window_list.clear();
1881 screen_list.clear();
1884 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1889QCursor *overrideCursor();
1890void setOverrideCursor(
const QCursor &);
1891void changeOverrideCursor(
const QCursor &);
1892void restoreOverrideCursor();
1896static QFont font(
const QWidget*);
1897static QFont font(
const char *className);
1898static void setFont(
const QFont &,
const char *className =
nullptr);
1899static QFontMetrics fontMetrics();
1901#ifndef QT_NO_CLIPBOARD
1902static QClipboard *clipboard();
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1921 return QGuiApplicationPrivate::modifier_buttons;
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1943 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1944 return pi->keyMapper()->queryKeyboardModifiers();
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960Qt::MouseButtons QGuiApplication::mouseButtons()
1962 return QGuiApplicationPrivate::mouse_buttons;
1966
1967
1968
1969
1970QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1972 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1973 return pi ? pi->nativeInterface() :
nullptr;
1977
1978
1979
1980QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1982 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1984 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1988 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015int QGuiApplication::exec()
2017#if QT_CONFIG(accessibility)
2018 QAccessible::setRootObject(qApp);
2020 return QCoreApplication::exec();
2023void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
2025 if (e->spontaneous()) {
2033 switch (e->type()) {
2034 case QEvent::MouseButtonPress: {
2035 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2036 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2037 QGuiApplicationPrivate::mouse_buttons |= me->button();
2040 case QEvent::MouseButtonDblClick: {
2041 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2042 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2043 QGuiApplicationPrivate::mouse_buttons |= me->button();
2046 case QEvent::MouseButtonRelease: {
2047 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2048 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2049 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2052 case QEvent::KeyPress:
2053 case QEvent::KeyRelease:
2054 case QEvent::MouseMove:
2055#if QT_CONFIG(wheelevent)
2058 case QEvent::TouchBegin:
2059 case QEvent::TouchUpdate:
2060 case QEvent::TouchEnd:
2061#if QT_CONFIG(tabletevent)
2062 case QEvent::TabletMove:
2063 case QEvent::TabletPress:
2064 case QEvent::TabletRelease:
2067 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2068 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2078
2079bool QGuiApplication::notify(QObject *object, QEvent *event)
2081 Q_D(QGuiApplication);
2082 if (object->isWindowType()) {
2083 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2087 switch (event->type()) {
2088 case QEvent::ApplicationDeactivate:
2089 case QEvent::OrientationChange:
2095 d->closeAllPopups();
2101 QGuiApplicationPrivate::captureGlobalModifierState(event);
2103 return QCoreApplication::notify(object, event);
2107
2108bool QGuiApplication::event(QEvent *e)
2110 switch (e->type()) {
2111 case QEvent::LanguageChange:
2113 if (layout_direction == Qt::LayoutDirectionAuto)
2114 setLayoutDirection(layout_direction);
2115 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2116 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2118 case QEvent::ApplicationFontChange:
2119 case QEvent::ApplicationPaletteChange:
2120 postEvent(QGuiApplication::styleHints(), e->clone());
2121 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2122 postEvent(topLevelWindow,
new QEvent(e->type()));
2124 case QEvent::ThemeChange:
2125 forwardEvent(QGuiApplication::styleHints(), e);
2126 for (
auto *w : QGuiApplication::allWindows())
2132 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2134 if (!topLevelWindow->handle())
2136 if (!topLevelWindow->close()) {
2145 return QCoreApplication::event(e);
2148#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2150
2151
2152bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2154 QT_IGNORE_DEPRECATIONS(
2155 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2160bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2164 QPlatformWindow *platformWindow = window->handle();
2165 if (!platformWindow)
2168 if (event->spontaneous())
2171 return platformWindow->windowEvent(event);
2174bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2176 return window->nativeEvent(eventType, message, result);
2179bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2181 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArrayView(
"qtvirtualkeyboard");
2182 return usingVirtualKeyboard;
2186bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2188 if (!isUsingVirtualKeyboard()) {
2189 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2193 static QPointer<QWindow> virtualKeyboard;
2194 const QEvent::Type type = e->type();
2195 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2196 const auto me =
static_cast<QMouseEvent *>(e);
2197 const QPointF posF = me->globalPosition();
2198 const QPoint pos = posF.toPoint();
2201 if (!virtualKeyboard) {
2202 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2203 win->inherits(
"QtVirtualKeyboard::InputView")) {
2204 virtualKeyboard = win;
2206 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2211 Q_ASSERT(virtualKeyboard);
2212 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2213 && virtualKeyboard->geometry().contains(pos);
2215 if (!virtualKeyboardUnderMouse) {
2216 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2217 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2221 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2222 me->button(), me->buttons(), me->modifiers(),
2223 me->pointingDevice());
2225 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2226 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2232void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2234 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2235 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2237 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2238 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2239 if (!haveGuiApplication) {
2240 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2241 e->eventAccepted =
false;
2246 case QWindowSystemInterfacePrivate::Mouse:
2247 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2249 case QWindowSystemInterfacePrivate::Wheel:
2250 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2252 case QWindowSystemInterfacePrivate::Key:
2253 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2255 case QWindowSystemInterfacePrivate::Touch:
2256 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2258 case QWindowSystemInterfacePrivate::GeometryChange:
2259 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2261 case QWindowSystemInterfacePrivate::Enter:
2262 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2264 case QWindowSystemInterfacePrivate::Leave:
2265 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2267 case QWindowSystemInterfacePrivate::FocusWindow:
2268 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2270 case QWindowSystemInterfacePrivate::WindowStateChanged:
2271 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2273 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2274 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2276 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2277 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2279 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2280 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2282 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2283 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2284 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2286 case QWindowSystemInterfacePrivate::ApplicationTermination:
2287 QGuiApplicationPrivate::processApplicationTermination(e);
2289 case QWindowSystemInterfacePrivate::FlushEvents: {
2290 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2291 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2293 case QWindowSystemInterfacePrivate::Close:
2294 QGuiApplicationPrivate::processCloseEvent(
2295 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2297 case QWindowSystemInterfacePrivate::ScreenOrientation:
2298 QGuiApplicationPrivate::processScreenOrientationChange(
2299 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2301 case QWindowSystemInterfacePrivate::ScreenGeometry:
2302 QGuiApplicationPrivate::processScreenGeometryChange(
2303 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2305 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2306 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2307 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2309 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2310 QGuiApplicationPrivate::processScreenRefreshRateChange(
2311 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2313 case QWindowSystemInterfacePrivate::ThemeChange:
2314 QGuiApplicationPrivate::processThemeChanged(
2315 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2317 case QWindowSystemInterfacePrivate::Expose:
2318 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2320 case QWindowSystemInterfacePrivate::Paint:
2321 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2323 case QWindowSystemInterfacePrivate::Tablet:
2324 QGuiApplicationPrivate::processTabletEvent(
2325 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2327 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2328 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2329 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2331 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2332 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2333 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2335#ifndef QT_NO_GESTURES
2336 case QWindowSystemInterfacePrivate::Gesture:
2337 QGuiApplicationPrivate::processGestureEvent(
2338 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2341 case QWindowSystemInterfacePrivate::PlatformPanel:
2342 QGuiApplicationPrivate::processPlatformPanelEvent(
2343 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2345 case QWindowSystemInterfacePrivate::FileOpen:
2346 QGuiApplicationPrivate::processFileOpenEvent(
2347 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2349#ifndef QT_NO_CONTEXTMENU
2350 case QWindowSystemInterfacePrivate::ContextMenu:
2351 QGuiApplicationPrivate::processContextMenuEvent(
2352 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2355 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2356 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2359 qWarning() <<
"Unknown user input event type:" << e->type;
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2378 QEvent::Type type = QEvent::None;
2379 Qt::MouseButton button = Qt::NoButton;
2380 QWindow *window = e->window.data();
2381 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2383 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2384 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2385 bool mouseMove =
false;
2386 bool mousePress =
false;
2387 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2388 QPointF globalPoint = e->globalPos;
2390 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2391 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2395 type = e->buttonType;
2398 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2400 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2403 if (!mouseMove && positionChanged) {
2404 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2405 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2406 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2407 e->source, e->nonClientArea, device, e->eventPointId);
2409 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2410 processMouseEvent(&moveEvent);
2411 processMouseEvent(e);
2414 if (type == QEvent::MouseMove && !positionChanged) {
2422 modifier_buttons = e->modifiers;
2423 QPointF localPoint = e->localPos;
2424 bool doubleClick =
false;
2425 auto persistentEPD = devPriv->pointById(0);
2427 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2428 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2431 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2432 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2433 mouseDoubleClickDistance : touchDoubleTapDistance);
2434 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2435 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2436 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2437 mousePressButton = Qt::NoButton;
2439 static unsigned long lastPressTimestamp = 0;
2440 static QPointer<QWindow> lastPressWindow =
nullptr;
2441 mouse_buttons = e->buttons;
2443 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2444 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2445 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2446 && button == mousePressButton && lastPressWindow == e->window;
2447 mousePressButton = button;
2448 lastPressTimestamp = e ->timestamp;
2449 lastPressWindow = e->window;
2453 if (e->nullWindow()) {
2454 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2458 if (e->buttons != Qt::NoButton) {
2459 if (!currentMousePressWindow)
2460 currentMousePressWindow = window;
2462 window = currentMousePressWindow;
2463 }
else if (currentMousePressWindow) {
2464 window = currentMousePressWindow;
2465 currentMousePressWindow =
nullptr;
2467 localPoint = window->mapFromGlobal(globalPoint);
2475 if (!e->synthetic()) {
2476 if (
const QScreen *screen = window->screen())
2477 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2478 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2479 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2480 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2481 button, e->buttons, e->modifiers, e->source, device);
2485 ev.QInputEvent::setTimestamp(e->timestamp);
2486 cursor->pointerEvent(ev);
2491 const auto *activePopup = activePopupWindow();
2492 if (type == QEvent::MouseButtonPress)
2493 active_popup_on_press = activePopup;
2494 if (window->d_func()->blockedByModalWindow && !activePopup) {
2499 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2500 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2503 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2504 persistentEPD =
nullptr;
2506 ev.setTimestamp(e->timestamp);
2508 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2510 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2511 if (handlingPopup) {
2512 if (type == QEvent::MouseButtonPress)
2513 active_popup_on_press = handlingPopup;
2518 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2520 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2523 QGuiApplication::sendSpontaneousEvent(window, &ev);
2524 e->eventAccepted = ev.isAccepted();
2525 if (!e->synthetic() && !ev.isAccepted()
2526 && !e->nonClientArea
2527 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2528 QList<QWindowSystemInterface::TouchPoint> points;
2529 QWindowSystemInterface::TouchPoint point;
2531 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2536 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2537 point.state = QEventPoint::State::Pressed;
2538 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2539 point.state = QEventPoint::State::Released;
2540 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2541 point.state = QEventPoint::State::Updated;
2549 const QList<QEventPoint> &touchPoints =
2550 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2552 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2553 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2554 processTouchEvent(&fake);
2557 mousePressButton = Qt::NoButton;
2558 if (!e->window.isNull() || e->nullWindow()) {
2559 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2560 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2561 button, e->buttons, e->modifiers, e->source, device);
2562 dblClickEvent.setTimestamp(e->timestamp);
2563 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2566 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2567 popup_closed_on_press =
false;
2568 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2569 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2570 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2575void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2577#if QT_CONFIG(wheelevent)
2578 QWindow *window = e->window.data();
2579 QPointF globalPoint = e->globalPos;
2580 QPointF localPoint = e->localPos;
2582 if (e->nullWindow()) {
2583 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2585 localPoint = window->mapFromGlobal(globalPoint);
2591 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2592 modifier_buttons = e->modifiers;
2594 if (window->d_func()->blockedByModalWindow) {
2599 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2600 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2601 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2602 ev.setTimestamp(e->timestamp);
2603 QGuiApplication::sendSpontaneousEvent(window, &ev);
2604 e->eventAccepted = ev.isAccepted();
2610void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2612 QWindow *window = e->window.data();
2613 modifier_buttons = e->modifiers;
2614 if (e->nullWindow())
2615 window = QGuiApplication::focusWindow();
2618 e->eventAccepted =
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)) {
2633 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2634 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2635 e->unicode, e->repeat, e->repeatCount);
2636 ev.setTimestamp(e->timestamp);
2638 const auto *activePopup = activePopupWindow();
2639 if (activePopup && activePopup != window) {
2641 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2647 if (!window->d_func()->blockedByModalWindow)
2648 QGuiApplication::sendSpontaneousEvent(window, &ev);
2651 ev.setAccepted(
false);
2653 e->eventAccepted = ev.isAccepted();
2656void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2660 if (e->enter.data()->d_func()->blockedByModalWindow) {
2665 currentMouseWindow = e->enter;
2668 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2675 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2676 auto epd = devPriv->queryPointById(event.points().first().id());
2678 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2680 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2683void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2687 if (e->leave.data()->d_func()->blockedByModalWindow) {
2692 currentMouseWindow =
nullptr;
2694 QEvent event(QEvent::Leave);
2695 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2698void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2700 QWindow *previous = QGuiApplicationPrivate::focus_window;
2701 QWindow *newFocus = e->focused.data();
2703 if (previous == newFocus)
2706 bool activatedPopup =
false;
2708 if (QPlatformWindow *platformWindow = newFocus->handle())
2709 if (platformWindow->isAlertState())
2710 platformWindow->setAlertState(
false);
2711 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2713 activatePopup(newFocus);
2716 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2719 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2720 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2723 QGuiApplicationPrivate::focus_window = newFocus;
2728 Qt::FocusReason r = e->reason;
2729 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2730 r = Qt::PopupFocusReason;
2731 QFocusEvent focusOut(QEvent::FocusOut, r);
2732 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2733 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2734 qApp, SLOT(_q_updateFocusObject(QObject*)));
2735 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2736 setApplicationState(Qt::ApplicationActive);
2739 if (QGuiApplicationPrivate::focus_window) {
2740 Qt::FocusReason r = e->reason;
2741 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2742 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2743 r = Qt::PopupFocusReason;
2744 QFocusEvent focusIn(QEvent::FocusIn, r);
2745 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2746 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2747 qApp, SLOT(_q_updateFocusObject(QObject*)));
2748 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2749 setApplicationState(Qt::ApplicationInactive);
2752 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2753 guiAppPrivate->notifyActiveWindowChange(previous);
2755 if (previousFocusObject !=
qApp->focusObject() ||
2761 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2762 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2766 emit
qApp->focusWindowChanged(newFocus);
2768 emit previous->activeChanged();
2770 emit newFocus->activeChanged();
2773void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2775 if (QWindow *window = wse->window.data()) {
2776 QWindowPrivate *windowPrivate = qt_window_private(window);
2777 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2779 windowPrivate->windowState = wse->newState;
2780 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2781 if (newEffectiveState != originalEffectiveState)
2782 emit window->windowStateChanged(newEffectiveState);
2784 windowPrivate->updateVisibility();
2786 QWindowStateChangeEvent e(wse->oldState);
2787 QGuiApplication::sendSpontaneousEvent(window, &e);
2791void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2793 QWindow *window = wse->window.data();
2797 QScreen *screen = wse->screen.data();
2798 if (window->screen() == screen)
2801 auto *windowPrivate = QWindowPrivate::get(window);
2802 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2803 if (window == topLevelWindow) {
2805 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2807 topLevelWindow->setScreen(
nullptr);
2808 }
else if (screen) {
2813 windowPrivate->emitScreenChangedRecursion(screen);
2817void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2819 if (wde->window.isNull())
2821 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2824void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2826 if (wse->window.isNull())
2829 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2831 QEvent event(QEvent::SafeAreaMarginsChange);
2832 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2835void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2842 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2843 guiAppPrivate->handleThemeChanged();
2845 QIconPrivate::clearIconCache();
2847 QEvent themeChangeEvent(QEvent::ThemeChange);
2848 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2851void QGuiApplicationPrivate::handleThemeChanged()
2853 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2856 QIconLoader::instance()->updateSystemTheme();
2857 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2859 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2860 const auto locker = qt_scoped_lock(applicationFontMutex);
2861 clearFontUnlocked();
2867void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2869 if (e->window.isNull())
2872 QWindow *window = e->window.data();
2876 const QRect lastReportedGeometry = window->d_func()->geometry;
2877 const QRect requestedGeometry = e->requestedGeometry;
2878 const QRect actualGeometry = e->newGeometry;
2888 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2889 || requestedGeometry.size() != actualGeometry.size();
2890 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2891 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2893 window->d_func()->geometry = actualGeometry;
2895 if (isResize || window->d_func()->resizeEventPending) {
2896 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2897 QGuiApplication::sendSpontaneousEvent(window, &e);
2899 window->d_func()->resizeEventPending =
false;
2901 if (actualGeometry.width() != lastReportedGeometry.width())
2902 emit window->widthChanged(actualGeometry.width());
2903 if (actualGeometry.height() != lastReportedGeometry.height())
2904 emit window->heightChanged(actualGeometry.height());
2909 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2910 QGuiApplication::sendSpontaneousEvent(window, &e);
2912 if (actualGeometry.x() != lastReportedGeometry.x())
2913 emit window->xChanged(actualGeometry.x());
2914 if (actualGeometry.y() != lastReportedGeometry.y())
2915 emit window->yChanged(actualGeometry.y());
2919void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2921 if (e->window.isNull())
2923 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2926 e->eventAccepted =
false;
2931 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2933 e->eventAccepted = event.isAccepted();
2936void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2938 if (e->url.isEmpty())
2941 QFileOpenEvent event(e->url);
2942 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2945QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2947 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2948 TabletPointData &pointData = tabletDevicePoints[i];
2949 if (pointData.deviceId == deviceId)
2953 tabletDevicePoints.append(TabletPointData(deviceId));
2954 return tabletDevicePoints.last();
2957void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2959#if QT_CONFIG(tabletevent)
2960 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2961 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2963 QEvent::Type type = QEvent::TabletMove;
2964 if (e->buttons != pointData.state)
2965 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2967 QWindow *window = e->window.data();
2968 modifier_buttons = e->modifiers;
2970 bool localValid =
true;
2974 if (type == QEvent::TabletPress) {
2975 if (e->nullWindow()) {
2976 window = QGuiApplication::topLevelAt(e->global.toPoint());
2981 active_popup_on_press = activePopupWindow();
2982 pointData.target = window;
2984 if (e->nullWindow()) {
2985 window = pointData.target;
2988 if (type == QEvent::TabletRelease)
2989 pointData.target =
nullptr;
2993 QPointF local = e->local;
2995 QPointF delta = e->global - e->global.toPoint();
2996 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3000 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3001 Qt::MouseButton button = Qt::NoButton;
3002 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3003 if (check & stateChange) {
3004 button = Qt::MouseButton(check);
3009 const auto *activePopup = activePopupWindow();
3010 if (window->d_func()->blockedByModalWindow && !activePopup) {
3015 QTabletEvent tabletEvent(type, device, local, e->global,
3016 e->pressure, e->xTilt, e->yTilt,
3017 e->tangentialPressure, e->rotation, e->z,
3018 e->modifiers, button, e->buttons);
3019 tabletEvent.setAccepted(
false);
3020 tabletEvent.setTimestamp(e->timestamp);
3022 if (activePopup && activePopup != window) {
3024 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3028 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3029 pointData.state = e->buttons;
3030 if (!tabletEvent.isAccepted()
3031 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3032 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3034 const QEvent::Type mouseType = [&]() {
3036 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3037 case QEvent::TabletMove:
return QEvent::MouseMove;
3038 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3039 default: Q_UNREACHABLE();
3042 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3043 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3044 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3045 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3046 << e->local << button << e->buttons << e->modifiers;
3047 processMouseEvent(&mouseEvent);
3054void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3056#if QT_CONFIG(tabletevent)
3057 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3058 QTabletEvent ev(QEvent::TabletEnterProximity, dev, e->local, e->global,
3059 e->pressure, e->xTilt, e->yTilt,
3060 e->tangentialPressure, e->rotation, e->z,
3061 e->modifiers, Qt::NoButton,
3062 tabletDevicePoint(dev->uniqueId().numericId()).state);
3063 ev.setTimestamp(e->timestamp);
3064 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3070void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3072#if QT_CONFIG(tabletevent)
3073 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3074 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, e->local, e->global,
3075 e->pressure, e->xTilt, e->yTilt,
3076 e->tangentialPressure, e->rotation, e->z,
3077 e->modifiers, Qt::NoButton,
3078 tabletDevicePoint(dev->uniqueId().numericId()).state);
3079 ev.setTimestamp(e->timestamp);
3080 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3086#ifndef QT_NO_GESTURES
3087void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3089 if (e->window.isNull())
3092 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3093 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3094 e->delta, e->sequenceId);
3095 ev.setTimestamp(e->timestamp);
3096 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3100void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3105 if (e->window->d_func()->blockedByModalWindow) {
3110 QEvent ev(QEvent::PlatformPanel);
3111 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3114#ifndef QT_NO_CONTEXTMENU
3115void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3119 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3122 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3123 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3124 e->eventAccepted = ev.isAccepted();
3128void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3130 if (!QInputDevicePrivate::isRegistered(e->device))
3133 modifier_buttons = e->modifiers;
3134 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3135 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3137 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3139 if (e->touchType == QEvent::TouchCancel) {
3142 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3143 touchEvent.setTimestamp(e->timestamp);
3144 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3145 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3147 for (
auto &epd : devPriv->activePoints.values()) {
3148 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3149 windowsNeedingCancel.insert(w);
3152 for (QWindow *w : windowsNeedingCancel)
3153 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3155 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3156 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3157 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3158 if (!synthIt->window)
3160 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3167 QEvent::MouseButtonRelease,
3168 Qt::MouseEventNotSynthesized,
3171 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3172 processMouseEvent(&fake);
3174 guiAppPrivate->synthesizedMousePoints.clear();
3176 guiAppPrivate->lastTouchType = e->touchType;
3181 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3184 guiAppPrivate->lastTouchType = e->touchType;
3186 QPointer<QWindow> window = e->window;
3187 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3193 for (
auto &tempPt : e->points) {
3195 auto epd = devPriv->pointById(tempPt.id());
3196 auto &ep = epd->eventPoint;
3197 epd->eventPoint.setAccepted(
false);
3198 switch (tempPt.state()) {
3199 case QEventPoint::State::Pressed:
3201 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3202 window = devPriv->firstActiveWindow();
3205 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3206 QMutableEventPoint::setWindow(ep, window);
3207 active_popup_on_press = activePopupWindow();
3210 case QEventPoint::State::Released:
3211 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3212 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3213 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3214 window = QMutableEventPoint::window(ep);
3218 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3219 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3220 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3221 window = QMutableEventPoint::window(ep);
3225 if (Q_UNLIKELY(!window)) {
3226 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3229 QMutableEventPoint::update(tempPt, ep);
3231 Q_ASSERT(window.data() !=
nullptr);
3234 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3237 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3240 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3244 for (QMutableTouchEvent &ev : touchEvents) {
3245 if (ev.target() == window.data()) {
3252 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3253 mte.setTimestamp(e->timestamp);
3254 mte.setTarget(window.data());
3255 touchEvents.append(mte);
3259 if (touchEvents.isEmpty())
3262 for (QMutableTouchEvent &touchEvent : touchEvents) {
3263 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3265 QEvent::Type eventType;
3266 switch (touchEvent.touchPointStates()) {
3267 case QEventPoint::State::Pressed:
3268 eventType = QEvent::TouchBegin;
3270 case QEventPoint::State::Released:
3271 eventType = QEvent::TouchEnd;
3274 eventType = QEvent::TouchUpdate;
3278 const auto *activePopup = activePopupWindow();
3279 if (window->d_func()->blockedByModalWindow && !activePopup) {
3283 if (touchEvent.type() == QEvent::TouchEnd) {
3286 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3287 touchEvent.setTimestamp(e->timestamp);
3288 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3293 if (activePopup && activePopup != window) {
3295 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3302 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3304 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3306 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3308 QEvent::Type mouseEventType = QEvent::MouseMove;
3309 Qt::MouseButton button = Qt::NoButton;
3310 Qt::MouseButtons buttons = Qt::LeftButton;
3311 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3312 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3313 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3315 if (m_fakeMouseSourcePointId >= 0) {
3316 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3318 switch (touchPoint->state()) {
3319 case QEventPoint::State::Pressed:
3320 mouseEventType = QEvent::MouseButtonPress;
3321 button = Qt::LeftButton;
3323 case QEventPoint::State::Released:
3324 mouseEventType = QEvent::MouseButtonRelease;
3325 button = Qt::LeftButton;
3326 buttons = Qt::NoButton;
3327 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3328 m_fakeMouseSourcePointId = -1;
3333 if (touchPoint->state() != QEventPoint::State::Released) {
3334 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3335 touchPoint->position(), touchPoint->globalPosition(), window));
3341 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3342 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3343 touchPoint->globalPosition(),
3348 Qt::MouseEventSynthesizedByQt,
3352 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3353 processMouseEvent(&fake);
3356 if (eventType == QEvent::TouchEnd)
3357 guiAppPrivate->synthesizedMousePoints.clear();
3364 for (
const QEventPoint &touchPoint : e->points) {
3365 if (touchPoint.state() == QEventPoint::State::Released)
3366 devPriv->removePointById(touchPoint.id());
3370void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3373 if (QCoreApplication::startingUp())
3379 QScreen *s = e->screen.data();
3380 s->d_func()->orientation = e->orientation;
3382 emit s->orientationChanged(s->orientation());
3384 QScreenOrientationChangeEvent event(s, s->orientation());
3385 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3388void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3391 if (QCoreApplication::startingUp())
3398 QScreen *s = e->screen.data();
3399 QScreenPrivate::UpdateEmitter updateEmitter(s);
3403 s->d_func()->geometry = e->geometry;
3404 s->d_func()->availableGeometry = e->availableGeometry;
3406 s->d_func()->updatePrimaryOrientation();
3409 resetCachedDevicePixelRatio();
3412void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3415 if (QCoreApplication::startingUp())
3418 QHighDpiScaling::updateHighDpiScaling();
3424 QScreen *s = e->screen.data();
3425 QScreenPrivate::UpdateEmitter updateEmitter(s);
3426 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3427 s->d_func()->updateGeometry();
3430 for (QWindow *window : QGuiApplication::allWindows())
3431 if (window->screen() == e->screen)
3432 QWindowPrivate::get(window)->updateDevicePixelRatio();
3434 resetCachedDevicePixelRatio();
3437void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3440 if (QCoreApplication::startingUp())
3446 QScreen *s = e->screen.data();
3447 qreal rate = e->rate;
3451 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3452 s->d_func()->refreshRate = rate;
3453 emit s->refreshRateChanged(s->refreshRate());
3457void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3462 QWindow *window = e->window.data();
3465 QWindowPrivate *p = qt_window_private(window);
3472 p->positionAutomatic =
false;
3473 p->resizeAutomatic =
false;
3476 if (!p->receivedExpose) {
3477 if (p->resizeEventPending) {
3480 QResizeEvent e(window->geometry().size(), p->geometry.size());
3481 QGuiApplication::sendSpontaneousEvent(window, &e);
3483 p->resizeEventPending =
false;
3492 p->receivedExpose =
true;
3496 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3498 const bool wasExposed = p->exposed;
3499 p->exposed = e->isExposed && window->screen();
3504 if (e->isExposed && !e->region.isEmpty()) {
3505 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3507 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3508 <<
"Please file a QTBUG which explains how to reproduce.";
3512 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3513 QPaintEvent paintEvent(e->region);
3514 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3515 if (paintEvent.isAccepted())
3523 QExposeEvent exposeEvent(e->region);
3524 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3525 e->eventAccepted = exposeEvent.isAccepted();
3532 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3533 QPaintEvent paintEvent(e->region);
3534 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3538void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3540 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3541 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3546 QPaintEvent paintEvent(e->region);
3547 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3551 e->eventAccepted = paintEvent.isAccepted();
3554#if QT_CONFIG(draganddrop)
3557
3558
3559
3560
3561static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3563 QGuiApplicationPrivate::mouse_buttons = buttons;
3564 QGuiApplicationPrivate::modifier_buttons = modifiers;
3567QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3568 const QPoint &p, Qt::DropActions supportedActions,
3569 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3571 updateMouseAndModifierButtonState(buttons, modifiers);
3573 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3574 QPlatformDrag *platformDrag = platformIntegration()->drag();
3575 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3576 lastAcceptedDropAction = Qt::IgnoreAction;
3577 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3581 currentDragWindow =
nullptr;
3583 QGuiApplication::sendEvent(w, &e);
3584 lastAcceptedDropAction = Qt::IgnoreAction;
3585 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3587 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3589 if (w != currentDragWindow) {
3590 lastAcceptedDropAction = Qt::IgnoreAction;
3591 if (currentDragWindow) {
3593 QGuiApplication::sendEvent(currentDragWindow, &e);
3595 currentDragWindow = w;
3596 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3597 QGuiApplication::sendEvent(w, &e);
3598 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3599 lastAcceptedDropAction = e.dropAction();
3603 if (lastAcceptedDropAction != Qt::IgnoreAction
3604 && (supportedActions & lastAcceptedDropAction)) {
3605 me.setDropAction(lastAcceptedDropAction);
3608 QGuiApplication::sendEvent(w, &me);
3609 lastAcceptedDropAction = me.isAccepted() ?
3610 me.dropAction() : Qt::IgnoreAction;
3611 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3614QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3615 const QPoint &p, Qt::DropActions supportedActions,
3616 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3618 updateMouseAndModifierButtonState(buttons, modifiers);
3620 currentDragWindow =
nullptr;
3622 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3623 QGuiApplication::sendEvent(w, &de);
3625 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3626 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3632#ifndef QT_NO_CLIPBOARD
3634
3635
3636QClipboard * QGuiApplication::clipboard()
3638 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3640 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3643 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3645 return QGuiApplicationPrivate::qt_clipboard;
3650
3651
3652
3653
3654
3655
3656
3657
3658
3661
3662
3663
3664
3665
3666
3668QPalette QGuiApplication::palette()
3670 if (!QGuiApplicationPrivate::app_pal)
3671 QGuiApplicationPrivate::updatePalette();
3673 return *QGuiApplicationPrivate::app_pal;