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 QGuiApplicationPrivate::destroyEventDispatcher();
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
809
810qint64 QGuiApplication::badgeNumber()
const
812 Q_D(
const QGuiApplication);
813 return d->badgeNumber;
816void QGuiApplication::setBadgeNumber(qint64 number)
818 Q_D(QGuiApplication);
822 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
823 if (d->badgeNumber == number)
825 d->badgeNumber = number;
826 emit badgeNumberChanged(number);
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845void QGuiApplication::setDesktopFileName(
const QString &name)
847 if (!QGuiApplicationPrivate::desktopFileName)
848 QGuiApplicationPrivate::desktopFileName =
new QString;
849 *QGuiApplicationPrivate::desktopFileName = name;
850 if (name.endsWith(QLatin1String(
".desktop"))) {
851 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
852 if (!filePath.isEmpty()) {
853 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
854 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
855 "be removed. Please specify a desktop file name without .desktop suffix");
856 (*QGuiApplicationPrivate::desktopFileName).chop(8);
861QString QGuiApplication::desktopFileName()
863 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
867
868
869
870
871
872
873
874
875
876
877
878
879
880QWindow *QGuiApplication::modalWindow()
883 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
884 if (modalWindows.isEmpty())
886 return modalWindows.constFirst();
891 QWindowPrivate *p = qt_window_private(window);
892 if (p->blockedByModalWindow != shouldBeBlocked) {
893 p->blockedByModalWindow = shouldBeBlocked;
894 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
895 QGuiApplication::sendEvent(window, &e);
896 for (QObject *c : window->children()) {
897 if (c->isWindowType())
898 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
903void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
905 bool shouldBeBlocked =
false;
906 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
907 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
908 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
909 updateBlockedStatusRecursion(window, shouldBeBlocked);
917 return w->isTopLevel();
920void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
922 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
923 guiAppPrivate->modalWindowList.prepend(modal);
926 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
927 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
928 if (shouldBeBlocked) {
930 guiAppPrivate->modalWindowList.removeFirst();
931 QEvent e(QEvent::Leave);
932 QGuiApplication::sendEvent(currentMouseWindow, &e);
933 currentMouseWindow =
nullptr;
934 guiAppPrivate->modalWindowList.prepend(modal);
938 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
939 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
940 updateBlockedStatus(window);
943 updateBlockedStatus(modal);
946void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
948 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
950 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
951 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
952 updateBlockedStatus(window);
956Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
961bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
968
969
970
971
972bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
974 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
976 QWindow *unused =
nullptr;
978 blockingWindow = &unused;
979 *blockingWindow =
nullptr;
981 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
984 for (
int i = 0; i < modalWindowList.size(); ++i) {
985 QWindow *modalWindow = modalWindowList.at(i);
989 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
992 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
993 : modalWindow->modality()) {
994 case Qt::ApplicationModal:
995 *blockingWindow = modalWindow;
997 case Qt::WindowModal: {
1000 auto *current = window;
1002 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
1003 *blockingWindow = modalWindow;
1006 current = current->parent(QWindow::IncludeTransients);
1011 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1018QWindow *QGuiApplicationPrivate::activePopupWindow()
1021 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1022 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1025void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1027 if (!popup->isVisible())
1029 popup_list.removeOne(popup);
1030 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1031 popup_list.append(popup);
1034bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1036 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1037 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1042
1043
1044bool QGuiApplicationPrivate::closeAllPopups()
1050 while ((popup = activePopupWindow()) && maxiter--)
1052 return QGuiApplicationPrivate::popup_list.isEmpty();
1056
1057
1058
1059
1060
1061QWindow *QGuiApplication::focusWindow()
1063 return QGuiApplicationPrivate::focus_window;
1067
1068
1069
1070
1071
1072
1073
1076
1077
1078
1079
1080
1081
1082
1085
1086
1087
1088QObject *QGuiApplication::focusObject()
1091 return focusWindow()->focusObject();
1096
1097
1098
1099
1100
1101
1102
1103
1104QWindowList QGuiApplication::allWindows()
1106 return QGuiApplicationPrivate::window_list;
1110
1111
1112
1113
1114
1115
1116QWindowList QGuiApplication::topLevelWindows()
1118 const QWindowList &list = QGuiApplicationPrivate::window_list;
1119 QWindowList topLevelWindows;
1120 for (
int i = 0; i < list.size(); ++i) {
1121 QWindow *window = list.at(i);
1122 if (!window->isTopLevel())
1127 if (window->handle() && window->handle()->isEmbedded())
1130 topLevelWindows.prepend(window);
1133 return topLevelWindows;
1136QScreen *QGuiApplication::primaryScreen()
1138 if (QGuiApplicationPrivate::screen_list.isEmpty())
1140 return QGuiApplicationPrivate::screen_list.at(0);
1144
1145
1146
1147QList<QScreen *> QGuiApplication::screens()
1149 return QGuiApplicationPrivate::screen_list;
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163QScreen *QGuiApplication::screenAt(
const QPoint &point)
1165 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1166 for (
const QScreen *screen : QGuiApplication::screens()) {
1167 if (visitedScreens.contains(screen))
1171 for (QScreen *sibling : screen->virtualSiblings()) {
1172 if (sibling->geometry().contains(point))
1175 visitedScreens.append(sibling);
1183
1184
1185
1186
1187
1188
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225qreal QGuiApplication::devicePixelRatio()
const
1227 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1228 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1230 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1231 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1232 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1234 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1237void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1239 m_maxDevicePixelRatio = 0.0;
1242void QGuiApplicationPrivate::_q_updatePrimaryScreenDpis()
1245 const QScreen *screen = QGuiApplication::primaryScreen();
1247 int dpiX = qRound(screen->logicalDotsPerInchX());
1248 int dpiY = qRound(screen->logicalDotsPerInchY());
1249 dpis = (dpiX << 16) | (dpiY & 0xffff);
1250 QObject::connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
1251 q_func(), SLOT(_q_updatePrimaryScreenDpis()), Qt::UniqueConnection);
1253 m_primaryScreenDpis.storeRelaxed(dpis);
1257
1258
1259QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1261 if (QScreen *windowScreen = screenAt(pos)) {
1262 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1263 return windowScreen->handle()->topLevelAt(devicePosition);
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1305QString QGuiApplication::platformName()
1307 if (!QGuiApplication::instance()) {
1308#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1309 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1314 return QGuiApplicationPrivate::platform_name ?
1315 *QGuiApplicationPrivate::platform_name : QString();
1323static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1325 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1326 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1327 <<
"platformPluginPath" << platformPluginPath
1328 <<
"platformThemeName" << platformThemeName;
1330 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1331 QStringList platformArguments;
1332 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1333 for (
const auto &pluginArgument : std::as_const(plugins)) {
1335 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1336 if (arguments.isEmpty())
1338 const QString name = arguments.takeFirst().toLower();
1339 QString argumentsKey = name;
1342 argumentsKey[0] = argumentsKey.at(0).toUpper();
1343 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1345 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1348 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1349 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1350 if (availablePlugins.contains(name)) {
1351 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1352 qCWarning(lcQpaPluginLoading).nospace().noquote()
1353 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1355 qCInfo(lcQpaPluginLoading).nospace().noquote()
1356 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1357 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1359 qCWarning(lcQpaPluginLoading).nospace().noquote()
1360 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1361 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1364 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1365 QGuiApplicationPrivate::platform_name =
new QString(name);
1366 platformArguments = arguments;
1371 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1372 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1373 "Reinstalling the application may fix this problem.\n");
1375 if (!availablePlugins.isEmpty())
1376 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1378#if defined(Q_OS_WIN)
1381 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1382 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1384 qFatal(
"%s", qPrintable(fatalMessage));
1392 QStringList themeNames;
1393 if (!platformThemeName.isEmpty()) {
1394 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1395 themeNames.append(platformThemeName);
1398#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1400 if (checkNeedPortalSupport()) {
1401 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1402 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1407 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1408 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1409 themeNames.append(platformIntegrationThemeNames);
1412 for (
const QString &themeName : std::as_const(themeNames)) {
1413 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1414 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1415 if (QGuiApplicationPrivate::platform_theme) {
1416 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1419 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1420 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1421 if (QGuiApplicationPrivate::platform_theme) {
1422 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1428 if (!QGuiApplicationPrivate::platform_theme) {
1429 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1430 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1435 if (!platformArguments.isEmpty()) {
1436 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1437 for (
const QString &argument : std::as_const(platformArguments)) {
1438 const qsizetype equalsPos = argument.indexOf(u'=');
1439 const QByteArray name =
1440 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1442 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1443 nativeInterface->setProperty(name.constData(), std::move(value));
1448 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1449 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1450 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1451 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1453 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1454 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1455 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1461 for (
int i = 0; i < pluginList.size(); ++i) {
1462 QByteArray pluginSpec = pluginList.at(i);
1463 qsizetype colonPos = pluginSpec.indexOf(
':');
1466 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1468 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1469 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1471 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1473 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1477#if QT_CONFIG(commandlineparser)
1478void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1480 QCoreApplicationPrivate::addQtOptions(options);
1482#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1483 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1484 const bool x11 = sessionType ==
"x11";
1487 const bool x11 =
false;
1490 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1491 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1492 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1493 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1494 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1495 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1496 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1497 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1498 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1499 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1500 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1501 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1502 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1503 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1504 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1505 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1506 options->append(QCommandLineOption(QStringLiteral(
"session"),
1507 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1510 options->append(QCommandLineOption(QStringLiteral(
"display"),
1511 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1512 options->append(QCommandLineOption(QStringLiteral(
"name"),
1513 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1514 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1515 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1516 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1517 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1518 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1519 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1521 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1522 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1523 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1524 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1525 options->append(QCommandLineOption(QStringLiteral(
"title"),
1526 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1531void QGuiApplicationPrivate::createPlatformIntegration()
1533 QHighDpiScaling::initHighDpiScaling();
1536 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1539 QByteArray platformName;
1540#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1541 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1543#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1544 QList<QByteArray> platformArguments = platformName.split(
':');
1545 QByteArray platformPluginBase = platformArguments.first();
1547 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1548 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1550 QVector<QByteArray> preferredPlatformOrder;
1551 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1552 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1553 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1554 preferredPlatformOrder << xcbPlatformName;
1556 platformName.clear();
1559 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1560 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1561 if (hasWaylandDisplay || isWaylandSessionType) {
1562 preferredPlatformOrder.prepend(waylandPlatformName);
1564 if (defaultIsWayland)
1565 platformName.clear();
1568 if (!platformName.isEmpty())
1569 preferredPlatformOrder.append(platformName);
1571 platformName = preferredPlatformOrder.join(
';');
1574 bool platformExplicitlySelected =
false;
1575 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1576 if (!platformNameEnv.isEmpty()) {
1577 platformName = platformNameEnv;
1578 platformExplicitlySelected =
true;
1581 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1587 int j = argc ? 1 : 0;
1588 for (
int i=1; i<argc; i++) {
1591 if (*argv[i] !=
'-') {
1592 argv[j++] = argv[i];
1595 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1596 const char *arg = argv[i];
1599 if (strcmp(arg,
"-platformpluginpath") == 0) {
1601 platformPluginPath = QFile::decodeName(argv[i]);
1602 }
else if (strcmp(arg,
"-platform") == 0) {
1604 platformExplicitlySelected =
true;
1605 platformName = argv[i];
1607 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1609 platformThemeName = QString::fromLocal8Bit(argv[i]);
1610 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1612 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1613 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1615 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1616 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1618 icon = QFile::decodeName(argv[i]);
1621 argv[j++] = argv[i];
1630 Q_UNUSED(platformExplicitlySelected);
1632 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1633 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1635 if (!icon.isEmpty())
1636 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1640
1641
1642
1643
1644
1645void QGuiApplicationPrivate::createEventDispatcher()
1647 Q_ASSERT(!eventDispatcher);
1649 if (platform_integration ==
nullptr)
1650 createPlatformIntegration();
1653 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1654 "Creating the platform integration resulted in creating an event dispatcher");
1657 Q_ASSERT(!eventDispatcher);
1659 eventDispatcher = platform_integration->createEventDispatcher();
1662void QGuiApplicationPrivate::eventDispatcherReady()
1664 if (platform_integration ==
nullptr)
1665 createPlatformIntegration();
1667 platform_integration->initialize();
1670void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1672 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1674#if defined(Q_OS_MACOS)
1675 QMacAutoReleasePool pool;
1678 QObject::connect(q_func(), SIGNAL(screenAdded(QScreen*)),
1679 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1680 QObject::connect(q_func(), SIGNAL(primaryScreenChanged(QScreen *)),
1681 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1683 QCoreApplicationPrivate::init();
1685 QCoreApplicationPrivate::is_app_running =
false;
1687 bool loadTestability =
false;
1688 QList<QByteArray> pluginList;
1690#ifndef QT_NO_SESSIONMANAGER
1692 QString session_key;
1693# if defined(Q_OS_WIN)
1694 wchar_t guidstr[40];
1696 CoCreateGuid(&guid);
1697 StringFromGUID2(guid, guidstr, 40);
1698 session_id = QString::fromWCharArray(guidstr);
1699 CoCreateGuid(&guid);
1700 StringFromGUID2(guid, guidstr, 40);
1701 session_key = QString::fromWCharArray(guidstr);
1705 int j = argc ? 1 : 0;
1706 for (
int i=1; i<argc; i++) {
1709 if (*argv[i] !=
'-') {
1710 argv[j++] = argv[i];
1713 const char *arg = argv[i];
1716 if (strcmp(arg,
"-plugin") == 0) {
1718 pluginList << argv[i];
1719 }
else if (strcmp(arg,
"-reverse") == 0) {
1720 force_reverse =
true;
1722 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1725 if (QDir::currentPath() ==
"/"_L1) {
1726 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1727 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1728 kCFURLPOSIXPathStyle));
1729 if (qbundlePath.endsWith(
".app"_L1))
1730 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1733#ifndef QT_NO_SESSIONMANAGER
1734 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1736 if (argv[i] && *argv[i]) {
1737 session_id = QString::fromLatin1(argv[i]);
1738 qsizetype p = session_id.indexOf(u'_');
1740 session_key = session_id.mid(p +1);
1741 session_id = session_id.left(p);
1743 is_session_restored =
true;
1746 }
else if (strcmp(arg,
"-testability") == 0) {
1747 loadTestability =
true;
1748 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1749 s = QString::fromLocal8Bit(arg + 7);
1750 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1751 s = QString::fromLocal8Bit(argv[++i]);
1753 argv[j++] = argv[i];
1766 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1767 if (!envPlugins.isEmpty())
1768 pluginList += envPlugins.split(
',');
1770 if (platform_integration ==
nullptr)
1771 createPlatformIntegration();
1774 QFont::initialize();
1778 QCursorData::initialize();
1782 qRegisterGuiVariant();
1784#if QT_CONFIG(animation)
1786 qRegisterGuiGetInterpolator();
1789 QWindowSystemInterfacePrivate::eventTime.start();
1791#if QT_CONFIG(accessibility)
1792 QAccessible::installFactory([](
const QString &classname, QObject *object)
1793 -> QAccessibleInterface * {
1794 if (classname ==
"QForeignWindow"_L1)
1795 return new QAccessibleWindow(
static_cast<QWindow *>(object));
1800 is_app_running =
true;
1801 init_plugins(pluginList);
1802 QWindowSystemInterface::flushWindowSystemEvents();
1804 Q_Q(QGuiApplication);
1805#ifndef QT_NO_SESSIONMANAGER
1807 session_manager =
new QSessionManager(q, session_id, session_key);
1810#if QT_CONFIG(library)
1811 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1812 loadTestability =
true;
1814 if (loadTestability) {
1815 QLibrary testLib(QStringLiteral(
"qttestability"));
1816 if (Q_UNLIKELY(!testLib.load())) {
1817 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1819 typedef void (*TasInitialize)(
void);
1820 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1821 if (Q_UNLIKELY(!initFunction)) {
1822 qCritical(
"Library qttestability resolve failed!");
1829 Q_UNUSED(loadTestability);
1833 QGuiApplication::setLayoutDirection(layout_direction);
1835 if (!QGuiApplicationPrivate::displayName)
1836 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1837 q, &QGuiApplication::applicationDisplayNameChanged);
1840extern void qt_cleanupFontDatabase();
1842QGuiApplicationPrivate::~QGuiApplicationPrivate()
1844#if defined(Q_OS_MACOS)
1845 QMacAutoReleasePool pool;
1848 is_app_closing =
true;
1849 is_app_running =
false;
1851 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1852 delete generic_plugin_list.at(i);
1853 generic_plugin_list.clear();
1855 clearFontUnlocked();
1860 QCursorData::cleanup();
1863 layout_direction = Qt::LayoutDirectionAuto;
1865 cleanupThreadData();
1867 delete QGuiApplicationPrivate::styleHints;
1868 QGuiApplicationPrivate::styleHints =
nullptr;
1871 qt_cleanupFontDatabase();
1873 QPixmapCache::clear();
1876 if (ownGlobalShareContext) {
1877 delete qt_gl_global_share_context();
1878 qt_gl_set_global_share_context(
nullptr);
1882#if QT_CONFIG(vulkan)
1883 QVulkanDefaultInstance::cleanup();
1886 platform_integration->destroy();
1888 delete platform_theme;
1889 platform_theme =
nullptr;
1890 delete platform_integration;
1891 platform_integration =
nullptr;
1893 window_list.clear();
1895 screen_list.clear();
1898 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1903QCursor *overrideCursor();
1904void setOverrideCursor(
const QCursor &);
1905void changeOverrideCursor(
const QCursor &);
1906void restoreOverrideCursor();
1910static QFont font(
const QWidget*);
1911static QFont font(
const char *className);
1912static void setFont(
const QFont &,
const char *className =
nullptr);
1913static QFontMetrics fontMetrics();
1915#ifndef QT_NO_CLIPBOARD
1916static QClipboard *clipboard();
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1935 return QGuiApplicationPrivate::modifier_buttons;
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1957 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1958 return pi->keyMapper()->queryKeyboardModifiers();
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974Qt::MouseButtons QGuiApplication::mouseButtons()
1976 return QGuiApplicationPrivate::mouse_buttons;
1980
1981
1982
1983
1984QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1986 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1987 return pi ? pi->nativeInterface() :
nullptr;
1991
1992
1993
1994QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1996 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1998 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
2002 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029int QGuiApplication::exec()
2031#if QT_CONFIG(accessibility)
2032 QAccessible::setRootObject(qApp);
2034 return QCoreApplication::exec();
2037void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
2039 if (e->spontaneous()) {
2047 switch (e->type()) {
2048 case QEvent::MouseButtonPress: {
2049 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2050 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2051 QGuiApplicationPrivate::mouse_buttons |= me->button();
2054 case QEvent::MouseButtonDblClick: {
2055 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2056 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2057 QGuiApplicationPrivate::mouse_buttons |= me->button();
2060 case QEvent::MouseButtonRelease: {
2061 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2062 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2063 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2066 case QEvent::KeyPress:
2067 case QEvent::KeyRelease:
2068 case QEvent::MouseMove:
2069#if QT_CONFIG(wheelevent)
2072 case QEvent::TouchBegin:
2073 case QEvent::TouchUpdate:
2074 case QEvent::TouchEnd:
2075#if QT_CONFIG(tabletevent)
2076 case QEvent::TabletMove:
2077 case QEvent::TabletPress:
2078 case QEvent::TabletRelease:
2081 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2082 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2092
2093bool QGuiApplication::notify(QObject *object, QEvent *event)
2095 Q_D(QGuiApplication);
2096 if (object->isWindowType()) {
2097 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2101 switch (event->type()) {
2102 case QEvent::ApplicationDeactivate:
2103 case QEvent::OrientationChange:
2109 d->closeAllPopups();
2115 QGuiApplicationPrivate::captureGlobalModifierState(event);
2117 return QCoreApplication::notify(object, event);
2121
2122bool QGuiApplication::event(QEvent *e)
2124 switch (e->type()) {
2125 case QEvent::LanguageChange:
2127 if (layout_direction == Qt::LayoutDirectionAuto)
2128 setLayoutDirection(layout_direction);
2129 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2130 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2132 case QEvent::ApplicationFontChange:
2133 case QEvent::ApplicationPaletteChange:
2134 postEvent(QGuiApplication::styleHints(), e->clone());
2135 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2136 postEvent(topLevelWindow,
new QEvent(e->type()));
2138 case QEvent::ThemeChange:
2139 forwardEvent(QGuiApplication::styleHints(), e);
2140 for (
auto *w : QGuiApplication::allWindows())
2146 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2148 if (!topLevelWindow->handle())
2150 if (!topLevelWindow->close()) {
2159 return QCoreApplication::event(e);
2162#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2164
2165
2166bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2168 QT_IGNORE_DEPRECATIONS(
2169 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2174bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2178 QPlatformWindow *platformWindow = window->handle();
2179 if (!platformWindow)
2182 if (event->spontaneous())
2185 return platformWindow->windowEvent(event);
2188bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2190 return window->nativeEvent(eventType, message, result);
2193bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2195 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArrayView(
"qtvirtualkeyboard");
2196 return usingVirtualKeyboard;
2200bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2202 if (!isUsingVirtualKeyboard()) {
2203 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2207 static QPointer<QWindow> virtualKeyboard;
2208 const QEvent::Type type = e->type();
2209 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2210 const auto me =
static_cast<QMouseEvent *>(e);
2211 const QPointF posF = me->globalPosition();
2212 const QPoint pos = posF.toPoint();
2215 if (!virtualKeyboard) {
2216 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2217 win->inherits(
"QtVirtualKeyboard::InputView")) {
2218 virtualKeyboard = win;
2220 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2225 Q_ASSERT(virtualKeyboard);
2226 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2227 && virtualKeyboard->geometry().contains(pos);
2229 if (!virtualKeyboardUnderMouse) {
2230 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2231 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2235 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2236 me->button(), me->buttons(), me->modifiers(),
2237 me->pointingDevice());
2239 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2240 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2246void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2248 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2249 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2251 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2252 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2253 if (!haveGuiApplication) {
2254 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2255 e->eventAccepted =
false;
2260 case QWindowSystemInterfacePrivate::Mouse:
2261 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2263 case QWindowSystemInterfacePrivate::Wheel:
2264 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2266 case QWindowSystemInterfacePrivate::Key:
2267 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2269 case QWindowSystemInterfacePrivate::Touch:
2270 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2272 case QWindowSystemInterfacePrivate::GeometryChange:
2273 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2275 case QWindowSystemInterfacePrivate::Enter:
2276 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2278 case QWindowSystemInterfacePrivate::Leave:
2279 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2281 case QWindowSystemInterfacePrivate::FocusWindow:
2282 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2284 case QWindowSystemInterfacePrivate::WindowStateChanged:
2285 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2287 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2288 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2290 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2291 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2293 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2294 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2296 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2297 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2298 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2300 case QWindowSystemInterfacePrivate::ApplicationTermination:
2301 QGuiApplicationPrivate::processApplicationTermination(e);
2303 case QWindowSystemInterfacePrivate::FlushEvents: {
2304 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2305 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2307 case QWindowSystemInterfacePrivate::Close:
2308 QGuiApplicationPrivate::processCloseEvent(
2309 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2311 case QWindowSystemInterfacePrivate::ScreenOrientation:
2312 QGuiApplicationPrivate::processScreenOrientationChange(
2313 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2315 case QWindowSystemInterfacePrivate::ScreenGeometry:
2316 QGuiApplicationPrivate::processScreenGeometryChange(
2317 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2319 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2320 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2321 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2323 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2324 QGuiApplicationPrivate::processScreenRefreshRateChange(
2325 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2327 case QWindowSystemInterfacePrivate::ThemeChange:
2328 QGuiApplicationPrivate::processThemeChanged(
2329 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2331 case QWindowSystemInterfacePrivate::Expose:
2332 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2334 case QWindowSystemInterfacePrivate::Paint:
2335 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2337 case QWindowSystemInterfacePrivate::Tablet:
2338 QGuiApplicationPrivate::processTabletEvent(
2339 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2341 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2342 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2343 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2345 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2346 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2347 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2349#ifndef QT_NO_GESTURES
2350 case QWindowSystemInterfacePrivate::Gesture:
2351 QGuiApplicationPrivate::processGestureEvent(
2352 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2355 case QWindowSystemInterfacePrivate::PlatformPanel:
2356 QGuiApplicationPrivate::processPlatformPanelEvent(
2357 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2359 case QWindowSystemInterfacePrivate::FileOpen:
2360 QGuiApplicationPrivate::processFileOpenEvent(
2361 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2363#ifndef QT_NO_CONTEXTMENU
2364 case QWindowSystemInterfacePrivate::ContextMenu:
2365 QGuiApplicationPrivate::processContextMenuEvent(
2366 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2369 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2370 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2373 qWarning() <<
"Unknown user input event type:" << e->type;
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2392 QEvent::Type type = QEvent::None;
2393 Qt::MouseButton button = Qt::NoButton;
2394 QWindow *window = e->window.data();
2395 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2397 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2398 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2399 bool mouseMove =
false;
2400 bool mousePress =
false;
2401 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2402 QPointF globalPoint = e->globalPos;
2404 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2405 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2409 type = e->buttonType;
2412 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2414 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2417 if (!mouseMove && positionChanged) {
2418 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2419 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2420 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2421 e->source, e->nonClientArea, device, e->eventPointId);
2423 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2424 processMouseEvent(&moveEvent);
2425 processMouseEvent(e);
2428 if (type == QEvent::MouseMove && !positionChanged) {
2436 modifier_buttons = e->modifiers;
2437 QPointF localPoint = e->localPos;
2438 bool doubleClick =
false;
2439 auto persistentEPD = devPriv->pointById(0);
2441 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2442 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2445 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2446 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2447 mouseDoubleClickDistance : touchDoubleTapDistance);
2448 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2449 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2450 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2451 mousePressButton = Qt::NoButton;
2453 static unsigned long lastPressTimestamp = 0;
2454 static QPointer<QWindow> lastPressWindow =
nullptr;
2455 mouse_buttons = e->buttons;
2457 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2458 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2459 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2460 && button == mousePressButton && lastPressWindow == e->window;
2461 mousePressButton = button;
2462 lastPressTimestamp = e ->timestamp;
2463 lastPressWindow = e->window;
2467 if (e->nullWindow()) {
2468 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2472 if (e->buttons != Qt::NoButton) {
2473 if (!currentMousePressWindow)
2474 currentMousePressWindow = window;
2476 window = currentMousePressWindow;
2477 }
else if (currentMousePressWindow) {
2478 window = currentMousePressWindow;
2479 currentMousePressWindow =
nullptr;
2481 localPoint = window->mapFromGlobal(globalPoint);
2489 if (!e->synthetic()) {
2490 if (
const QScreen *screen = window->screen())
2491 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2492 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2493 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2494 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2495 button, e->buttons, e->modifiers, e->source, device);
2499 ev.QInputEvent::setTimestamp(e->timestamp);
2500 cursor->pointerEvent(ev);
2505 const auto *activePopup = activePopupWindow();
2506 if (type == QEvent::MouseButtonPress)
2507 active_popup_on_press = activePopup;
2508 if (window->d_func()->blockedByModalWindow && !activePopup) {
2513 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2514 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2517 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2518 persistentEPD =
nullptr;
2520 ev.setTimestamp(e->timestamp);
2522 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2524 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2525 if (handlingPopup) {
2526 if (type == QEvent::MouseButtonPress)
2527 active_popup_on_press = handlingPopup;
2532 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2534 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2537 QGuiApplication::sendSpontaneousEvent(window, &ev);
2538 e->eventAccepted = ev.isAccepted();
2539 if (!e->synthetic() && !ev.isAccepted()
2540 && !e->nonClientArea
2541 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2542 QList<QWindowSystemInterface::TouchPoint> points;
2543 QWindowSystemInterface::TouchPoint point;
2545 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2550 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2551 point.state = QEventPoint::State::Pressed;
2552 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2553 point.state = QEventPoint::State::Released;
2554 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2555 point.state = QEventPoint::State::Updated;
2563 const QList<QEventPoint> &touchPoints =
2564 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2566 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2567 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2568 processTouchEvent(&fake);
2571 mousePressButton = Qt::NoButton;
2572 if (!e->window.isNull() || e->nullWindow()) {
2573 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2574 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2575 button, e->buttons, e->modifiers, e->source, device);
2576 dblClickEvent.setTimestamp(e->timestamp);
2577 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2580 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2581 popup_closed_on_press =
false;
2582 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2583 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2584 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2589void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2591#if QT_CONFIG(wheelevent)
2592 QWindow *window = e->window.data();
2593 QPointF globalPoint = e->globalPos;
2594 QPointF localPoint = e->localPos;
2596 if (e->nullWindow()) {
2597 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2599 localPoint = window->mapFromGlobal(globalPoint);
2605 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2606 modifier_buttons = e->modifiers;
2608 if (window->d_func()->blockedByModalWindow) {
2613 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2614 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2615 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2616 ev.setTimestamp(e->timestamp);
2617 QGuiApplication::sendSpontaneousEvent(window, &ev);
2618 e->eventAccepted = ev.isAccepted();
2624void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2626 QWindow *window = e->window.data();
2627 modifier_buttons = e->modifiers;
2628 if (e->nullWindow())
2629 window = QGuiApplication::focusWindow();
2632 e->eventAccepted =
false;
2636#if !defined(Q_OS_MACOS)
2639 if (e->keyType == QEvent::KeyPress) {
2640 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2641 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2647 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2648 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2649 e->unicode, e->repeat, e->repeatCount);
2650 ev.setTimestamp(e->timestamp);
2652 const auto *activePopup = activePopupWindow();
2653 if (activePopup && activePopup != window) {
2655 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2661 if (!window->d_func()->blockedByModalWindow)
2662 QGuiApplication::sendSpontaneousEvent(window, &ev);
2665 ev.setAccepted(
false);
2667 e->eventAccepted = ev.isAccepted();
2670void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2674 if (e->enter.data()->d_func()->blockedByModalWindow) {
2679 currentMouseWindow = e->enter;
2682 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2689 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2690 auto epd = devPriv->queryPointById(event.points().first().id());
2692 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2694 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2697void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2701 if (e->leave.data()->d_func()->blockedByModalWindow) {
2706 currentMouseWindow =
nullptr;
2708 QEvent event(QEvent::Leave);
2709 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2712void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2714 QWindow *previous = QGuiApplicationPrivate::focus_window;
2715 QWindow *newFocus = e->focused.data();
2717 if (previous == newFocus)
2720 bool activatedPopup =
false;
2722 if (QPlatformWindow *platformWindow = newFocus->handle())
2723 if (platformWindow->isAlertState())
2724 platformWindow->setAlertState(
false);
2725 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2727 activatePopup(newFocus);
2730 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2733 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2734 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2737 QGuiApplicationPrivate::focus_window = newFocus;
2742 Qt::FocusReason r = e->reason;
2743 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2744 r = Qt::PopupFocusReason;
2745 QFocusEvent focusOut(QEvent::FocusOut, r);
2746 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2747 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2748 qApp, SLOT(_q_updateFocusObject(QObject*)));
2749 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2750 setApplicationState(Qt::ApplicationActive);
2753 if (QGuiApplicationPrivate::focus_window) {
2754 Qt::FocusReason r = e->reason;
2755 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2756 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2757 r = Qt::PopupFocusReason;
2758 QFocusEvent focusIn(QEvent::FocusIn, r);
2759 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2760 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2761 qApp, SLOT(_q_updateFocusObject(QObject*)));
2762 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2763 setApplicationState(Qt::ApplicationInactive);
2766 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2767 guiAppPrivate->notifyActiveWindowChange(previous);
2769 if (previousFocusObject !=
qApp->focusObject() ||
2775 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2776 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2780 emit
qApp->focusWindowChanged(newFocus);
2782 emit previous->activeChanged();
2784 emit newFocus->activeChanged();
2787void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2789 if (QWindow *window = wse->window.data()) {
2790 QWindowPrivate *windowPrivate = qt_window_private(window);
2791 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2793 windowPrivate->windowState = wse->newState;
2794 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2795 if (newEffectiveState != originalEffectiveState)
2796 emit window->windowStateChanged(newEffectiveState);
2798 windowPrivate->updateVisibility();
2800 QWindowStateChangeEvent e(wse->oldState);
2801 QGuiApplication::sendSpontaneousEvent(window, &e);
2805void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2807 QWindow *window = wse->window.data();
2811 QScreen *screen = wse->screen.data();
2812 if (window->screen() == screen)
2815 auto *windowPrivate = QWindowPrivate::get(window);
2816 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2817 if (window == topLevelWindow) {
2819 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2821 topLevelWindow->setScreen(
nullptr);
2822 }
else if (screen) {
2827 windowPrivate->emitScreenChangedRecursion(screen);
2831void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2833 if (wde->window.isNull())
2835 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2838void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2840 if (wse->window.isNull())
2843 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2845 QEvent event(QEvent::SafeAreaMarginsChange);
2846 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2849void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2856 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2857 guiAppPrivate->handleThemeChanged();
2859 QIconPrivate::clearIconCache();
2861 QEvent themeChangeEvent(QEvent::ThemeChange);
2862 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2865void QGuiApplicationPrivate::handleThemeChanged()
2867 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2870 QIconLoader::instance()->updateSystemTheme();
2871 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2873 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2874 const auto locker = qt_scoped_lock(applicationFontMutex);
2875 clearFontUnlocked();
2881void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2883 if (e->window.isNull())
2886 QWindow *window = e->window.data();
2890 const QRect lastReportedGeometry = window->d_func()->geometry;
2891 const QRect requestedGeometry = e->requestedGeometry;
2892 const QRect actualGeometry = e->newGeometry;
2902 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2903 || requestedGeometry.size() != actualGeometry.size();
2904 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2905 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2907 window->d_func()->geometry = actualGeometry;
2909 if (isResize || window->d_func()->resizeEventPending) {
2910 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2911 QGuiApplication::sendSpontaneousEvent(window, &e);
2913 window->d_func()->resizeEventPending =
false;
2915 if (actualGeometry.width() != lastReportedGeometry.width())
2916 emit window->widthChanged(actualGeometry.width());
2917 if (actualGeometry.height() != lastReportedGeometry.height())
2918 emit window->heightChanged(actualGeometry.height());
2923 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2924 QGuiApplication::sendSpontaneousEvent(window, &e);
2926 if (actualGeometry.x() != lastReportedGeometry.x())
2927 emit window->xChanged(actualGeometry.x());
2928 if (actualGeometry.y() != lastReportedGeometry.y())
2929 emit window->yChanged(actualGeometry.y());
2933void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2935 if (e->window.isNull())
2937 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2940 e->eventAccepted =
false;
2945 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2947 e->eventAccepted = event.isAccepted();
2950void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2952 if (e->url.isEmpty())
2955 QFileOpenEvent event(e->url);
2956 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2959QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2961 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2962 TabletPointData &pointData = tabletDevicePoints[i];
2963 if (pointData.deviceId == deviceId)
2967 tabletDevicePoints.append(TabletPointData(deviceId));
2968 return tabletDevicePoints.last();
2971void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2973#if QT_CONFIG(tabletevent)
2974 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2975 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2977 QEvent::Type type = QEvent::TabletMove;
2978 if (e->buttons != pointData.state)
2979 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2981 QWindow *window = e->window.data();
2982 modifier_buttons = e->modifiers;
2984 bool localValid =
true;
2988 if (type == QEvent::TabletPress) {
2989 if (e->nullWindow()) {
2990 window = QGuiApplication::topLevelAt(e->global.toPoint());
2995 active_popup_on_press = activePopupWindow();
2996 pointData.target = window;
2998 if (e->nullWindow()) {
2999 window = pointData.target;
3002 if (type == QEvent::TabletRelease)
3003 pointData.target =
nullptr;
3007 QPointF local = e->local;
3009 QPointF delta = e->global - e->global.toPoint();
3010 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3014 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3015 Qt::MouseButton button = Qt::NoButton;
3016 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3017 if (check & stateChange) {
3018 button = Qt::MouseButton(check);
3023 const auto *activePopup = activePopupWindow();
3024 if (window->d_func()->blockedByModalWindow && !activePopup) {
3029 QTabletEvent tabletEvent(type, device, local, e->global,
3030 e->pressure, e->xTilt, e->yTilt,
3031 e->tangentialPressure, e->rotation, e->z,
3032 e->modifiers, button, e->buttons);
3033 tabletEvent.setAccepted(
false);
3034 tabletEvent.setTimestamp(e->timestamp);
3036 if (activePopup && activePopup != window) {
3038 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3042 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3043 pointData.state = e->buttons;
3044 if (!tabletEvent.isAccepted()
3045 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3046 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3048 const QEvent::Type mouseType = [&]() {
3050 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3051 case QEvent::TabletMove:
return QEvent::MouseMove;
3052 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3053 default: Q_UNREACHABLE();
3056 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3057 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3058 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3059 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3060 << e->local << button << e->buttons << e->modifiers;
3061 processMouseEvent(&mouseEvent);
3068void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3070#if QT_CONFIG(tabletevent)
3071 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3072 QTabletEvent ev(QEvent::TabletEnterProximity, dev, e->local, e->global,
3073 e->pressure, e->xTilt, e->yTilt,
3074 e->tangentialPressure, e->rotation, e->z,
3075 e->modifiers, Qt::NoButton,
3076 tabletDevicePoint(dev->uniqueId().numericId()).state);
3077 ev.setTimestamp(e->timestamp);
3078 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3084void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3086#if QT_CONFIG(tabletevent)
3087 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3088 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, e->local, e->global,
3089 e->pressure, e->xTilt, e->yTilt,
3090 e->tangentialPressure, e->rotation, e->z,
3091 e->modifiers, Qt::NoButton,
3092 tabletDevicePoint(dev->uniqueId().numericId()).state);
3093 ev.setTimestamp(e->timestamp);
3094 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3100#ifndef QT_NO_GESTURES
3101void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3103 if (e->window.isNull())
3106 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3107 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3108 e->delta, e->sequenceId);
3109 ev.setTimestamp(e->timestamp);
3110 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3114void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3119 if (e->window->d_func()->blockedByModalWindow) {
3124 QEvent ev(QEvent::PlatformPanel);
3125 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3128#ifndef QT_NO_CONTEXTMENU
3129void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3133 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3136 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3137 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3138 e->eventAccepted = ev.isAccepted();
3142void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3149 e->eventAccepted =
false;
3151 if (!QInputDevicePrivate::isRegistered(e->device))
3154 modifier_buttons = e->modifiers;
3155 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3156 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3158 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3160 if (e->touchType == QEvent::TouchCancel) {
3163 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3164 touchEvent.setTimestamp(e->timestamp);
3165 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3166 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3168 for (
auto &epd : devPriv->activePoints.values()) {
3169 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3170 windowsNeedingCancel.insert(w);
3173 for (QWindow *w : windowsNeedingCancel) {
3174 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3175 e->eventAccepted |= touchEvent.isAccepted();
3178 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3179 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3180 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3181 if (!synthIt->window)
3183 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3190 QEvent::MouseButtonRelease,
3191 Qt::MouseEventNotSynthesized,
3194 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3195 processMouseEvent(&fake);
3197 guiAppPrivate->synthesizedMousePoints.clear();
3200 guiAppPrivate->lastTouchType = e->touchType;
3201 devPriv->activePoints.clear();
3206 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3209 guiAppPrivate->lastTouchType = e->touchType;
3211 QPointer<QWindow> window = e->window;
3212 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3218 for (
auto &tempPt : e->points) {
3220 auto epd = devPriv->pointById(tempPt.id());
3221 auto &ep = epd->eventPoint;
3222 epd->eventPoint.setAccepted(
false);
3223 switch (tempPt.state()) {
3224 case QEventPoint::State::Pressed:
3226 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3227 window = devPriv->firstActiveWindow();
3230 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3231 QMutableEventPoint::setWindow(ep, window);
3232 active_popup_on_press = activePopupWindow();
3235 case QEventPoint::State::Released:
3236 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3237 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3238 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3239 window = QMutableEventPoint::window(ep);
3243 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3244 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3245 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3246 window = QMutableEventPoint::window(ep);
3250 if (Q_UNLIKELY(!window)) {
3251 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3254 QMutableEventPoint::update(tempPt, ep);
3256 Q_ASSERT(window.data() !=
nullptr);
3259 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3262 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3265 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3269 for (QMutableTouchEvent &ev : touchEvents) {
3270 if (ev.target() == window.data()) {
3277 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3278 mte.setTimestamp(e->timestamp);
3279 mte.setTarget(window.data());
3280 touchEvents.append(mte);
3284 if (touchEvents.isEmpty())
3287 for (QMutableTouchEvent &touchEvent : touchEvents) {
3288 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3290 QEvent::Type eventType;
3291 switch (touchEvent.touchPointStates()) {
3292 case QEventPoint::State::Pressed:
3293 eventType = QEvent::TouchBegin;
3295 case QEventPoint::State::Released:
3296 eventType = QEvent::TouchEnd;
3299 eventType = QEvent::TouchUpdate;
3303 const auto *activePopup = activePopupWindow();
3304 if (window->d_func()->blockedByModalWindow && !activePopup) {
3308 if (touchEvent.type() == QEvent::TouchEnd) {
3311 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3312 touchEvent.setTimestamp(e->timestamp);
3313 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3318 if (activePopup && activePopup != window) {
3320 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3327 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3328 e->eventAccepted |= touchEvent.isAccepted();
3330 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3332 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3334 QEvent::Type mouseEventType = QEvent::MouseMove;
3335 Qt::MouseButton button = Qt::NoButton;
3336 Qt::MouseButtons buttons = Qt::LeftButton;
3337 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3338 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3339 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3341 if (m_fakeMouseSourcePointId >= 0) {
3342 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3344 switch (touchPoint->state()) {
3345 case QEventPoint::State::Pressed:
3346 mouseEventType = QEvent::MouseButtonPress;
3347 button = Qt::LeftButton;
3349 case QEventPoint::State::Released:
3350 mouseEventType = QEvent::MouseButtonRelease;
3351 button = Qt::LeftButton;
3352 buttons = Qt::NoButton;
3353 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3354 m_fakeMouseSourcePointId = -1;
3359 if (touchPoint->state() != QEventPoint::State::Released) {
3360 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3361 touchPoint->position(), touchPoint->globalPosition(), window));
3367 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3368 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3369 touchPoint->globalPosition(),
3374 Qt::MouseEventSynthesizedByQt,
3378 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3379 processMouseEvent(&fake);
3380 e->eventAccepted |= fake.eventAccepted;
3383 if (eventType == QEvent::TouchEnd)
3384 guiAppPrivate->synthesizedMousePoints.clear();
3391 for (
const QEventPoint &touchPoint : e->points) {
3392 if (touchPoint.state() == QEventPoint::State::Released)
3393 devPriv->removePointById(touchPoint.id());
3397void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3400 if (QCoreApplication::startingUp())
3406 QScreen *s = e->screen.data();
3407 s->d_func()->orientation = e->orientation;
3409 emit s->orientationChanged(s->orientation());
3411 QScreenOrientationChangeEvent event(s, s->orientation());
3412 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3415void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3418 if (QCoreApplication::startingUp())
3425 QScreen *s = e->screen.data();
3426 QScreenPrivate::UpdateEmitter updateEmitter(s);
3430 s->d_func()->geometry = e->geometry;
3431 s->d_func()->availableGeometry = e->availableGeometry;
3433 s->d_func()->updatePrimaryOrientation();
3436 resetCachedDevicePixelRatio();
3439void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3442 if (QCoreApplication::startingUp())
3445 QHighDpiScaling::updateHighDpiScaling();
3451 QScreen *s = e->screen.data();
3452 QScreenPrivate::UpdateEmitter updateEmitter(s);
3453 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3454 s->d_func()->updateGeometry();
3457 for (QWindow *window : QGuiApplication::allWindows())
3458 if (window->screen() == e->screen)
3459 QWindowPrivate::get(window)->updateDevicePixelRatio();
3461 resetCachedDevicePixelRatio();
3464void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3467 if (QCoreApplication::startingUp())
3473 QScreen *s = e->screen.data();
3474 qreal rate = e->rate;
3478 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3479 s->d_func()->refreshRate = rate;
3480 emit s->refreshRateChanged(s->refreshRate());
3484void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3489 QWindow *window = e->window.data();
3492 QWindowPrivate *p = qt_window_private(window);
3499 p->positionAutomatic =
false;
3500 p->resizeAutomatic =
false;
3503 if (!p->receivedExpose) {
3504 if (p->resizeEventPending) {
3507 QResizeEvent e(window->geometry().size(), p->geometry.size());
3508 QGuiApplication::sendSpontaneousEvent(window, &e);
3510 p->resizeEventPending =
false;
3519 p->receivedExpose =
true;
3523 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3525 const bool wasExposed = p->exposed;
3526 p->exposed = e->isExposed && window->screen();
3531 if (e->isExposed && !e->region.isEmpty()) {
3532 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3534 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3535 <<
"Please file a QTBUG which explains how to reproduce.";
3539 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3540 QPaintEvent paintEvent(e->region);
3541 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3542 if (paintEvent.isAccepted())
3550 QExposeEvent exposeEvent(e->region);
3551 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3552 e->eventAccepted = exposeEvent.isAccepted();
3559 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3560 QPaintEvent paintEvent(e->region);
3561 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3565void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3567 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3568 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3573 QPaintEvent paintEvent(e->region);
3574 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3578 e->eventAccepted = paintEvent.isAccepted();
3581#if QT_CONFIG(draganddrop)
3584
3585
3586
3587
3588static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3590 QGuiApplicationPrivate::mouse_buttons = buttons;
3591 QGuiApplicationPrivate::modifier_buttons = modifiers;
3594QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3595 const QPoint &p, Qt::DropActions supportedActions,
3596 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3598 updateMouseAndModifierButtonState(buttons, modifiers);
3600 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3601 QPlatformDrag *platformDrag = platformIntegration()->drag();
3602 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3603 lastAcceptedDropAction = Qt::IgnoreAction;
3604 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3608 currentDragWindow =
nullptr;
3610 QGuiApplication::sendEvent(w, &e);
3611 lastAcceptedDropAction = Qt::IgnoreAction;
3612 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3614 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3616 if (w != currentDragWindow) {
3617 lastAcceptedDropAction = Qt::IgnoreAction;
3618 if (currentDragWindow) {
3620 QGuiApplication::sendEvent(currentDragWindow, &e);
3622 currentDragWindow = w;
3623 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3624 QGuiApplication::sendEvent(w, &e);
3625 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3626 lastAcceptedDropAction = e.dropAction();
3630 if (lastAcceptedDropAction != Qt::IgnoreAction
3631 && (supportedActions & lastAcceptedDropAction)) {
3632 me.setDropAction(lastAcceptedDropAction);
3635 QGuiApplication::sendEvent(w, &me);
3636 lastAcceptedDropAction = me.isAccepted() ?
3637 me.dropAction() : Qt::IgnoreAction;
3638 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3641QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3642 const QPoint &p, Qt::DropActions supportedActions,
3643 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3645 updateMouseAndModifierButtonState(buttons, modifiers);
3647 currentDragWindow =
nullptr;
3649 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3650 QGuiApplication::sendEvent(w, &de);
3652 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3653 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3659#ifndef QT_NO_CLIPBOARD
3661
3662
3663QClipboard * QGuiApplication::clipboard()
3665 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3667 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3670 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3672 return QGuiApplicationPrivate::qt_clipboard;
3677
3678
3679
3680
3681
3682
3683
3684
3685
3688
3689
3690
3691
3692
3693
3695QPalette QGuiApplication::palette()
3697 if (!QGuiApplicationPrivate::app_pal)
3698 QGuiApplicationPrivate::updatePalette();
3700 return *QGuiApplicationPrivate::app_pal;