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
810
811qint64 QGuiApplication::badgeNumber()
const
813 Q_D(
const QGuiApplication);
814 return d->badgeNumber;
817void QGuiApplication::setBadgeNumber(qint64 number)
819 Q_D(QGuiApplication);
823 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
824 if (d->badgeNumber == number)
826 d->badgeNumber = number;
827 emit badgeNumberChanged(number);
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846void QGuiApplication::setDesktopFileName(
const QString &name)
848 if (!QGuiApplicationPrivate::desktopFileName)
849 QGuiApplicationPrivate::desktopFileName =
new QString;
850 *QGuiApplicationPrivate::desktopFileName = name;
851 if (name.endsWith(QLatin1String(
".desktop"))) {
852 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
853 if (!filePath.isEmpty()) {
854 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
855 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
856 "be removed. Please specify a desktop file name without .desktop suffix");
857 (*QGuiApplicationPrivate::desktopFileName).chop(8);
862QString QGuiApplication::desktopFileName()
864 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
868
869
870
871
872
873
874
875
876
877
878
879
880
881QWindow *QGuiApplication::modalWindow()
884 const auto &modalWindows = QGuiApplicationPrivate::instance()->modalWindowList;
885 if (modalWindows.isEmpty())
887 return modalWindows.constFirst();
892 QWindowPrivate *p = qt_window_private(window);
893 if (p->blockedByModalWindow != shouldBeBlocked) {
894 p->blockedByModalWindow = shouldBeBlocked;
895 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
896 QGuiApplication::sendEvent(window, &e);
897 for (QObject *c : window->children()) {
898 if (c->isWindowType())
899 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
904void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
906 bool shouldBeBlocked =
false;
907 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
908 if (!popupType && !QGuiApplicationPrivate::instance()->modalWindowList.isEmpty())
909 shouldBeBlocked = QGuiApplicationPrivate::instance()->isWindowBlocked(window);
910 updateBlockedStatusRecursion(window, shouldBeBlocked);
918 return w->isTopLevel();
921void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
923 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
924 guiAppPrivate->modalWindowList.prepend(modal);
927 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
928 bool shouldBeBlocked = guiAppPrivate->isWindowBlocked(currentMouseWindow);
929 if (shouldBeBlocked) {
931 guiAppPrivate->modalWindowList.removeFirst();
932 QEvent e(QEvent::Leave);
933 QGuiApplication::sendEvent(currentMouseWindow, &e);
934 currentMouseWindow =
nullptr;
935 guiAppPrivate->modalWindowList.prepend(modal);
939 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
940 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
941 updateBlockedStatus(window);
944 updateBlockedStatus(modal);
947void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
949 QGuiApplicationPrivate::instance()->modalWindowList.removeAll(window);
951 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
952 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
953 updateBlockedStatus(window);
957Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
962bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
969
970
971
972
973bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
975 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
977 QWindow *unused =
nullptr;
979 blockingWindow = &unused;
980 *blockingWindow =
nullptr;
982 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
985 for (
int i = 0; i < modalWindowList.size(); ++i) {
986 QWindow *modalWindow = modalWindowList.at(i);
990 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
993 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
994 : modalWindow->modality()) {
995 case Qt::ApplicationModal:
996 *blockingWindow = modalWindow;
998 case Qt::WindowModal: {
1001 auto *current = window;
1003 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
1004 *blockingWindow = modalWindow;
1007 current = current->parent(QWindow::IncludeTransients);
1012 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
1019QWindow *QGuiApplicationPrivate::activePopupWindow()
1022 return QGuiApplicationPrivate::popup_list.isEmpty() ?
1023 nullptr : QGuiApplicationPrivate::popup_list.constLast();
1026void QGuiApplicationPrivate::activatePopup(QWindow *popup)
1028 if (!popup->isVisible())
1030 popup_list.removeOne(popup);
1031 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1032 popup_list.append(popup);
1035bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1037 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1038 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1043
1044
1045bool QGuiApplicationPrivate::closeAllPopups()
1051 while ((popup = activePopupWindow()) && maxiter--)
1053 return QGuiApplicationPrivate::popup_list.isEmpty();
1057
1058
1059
1060
1061
1062QWindow *QGuiApplication::focusWindow()
1064 return QGuiApplicationPrivate::focus_window;
1068
1069
1070
1071
1072
1073
1074
1077
1078
1079
1080
1081
1082
1083
1086
1087
1088
1089QObject *QGuiApplication::focusObject()
1092 return focusWindow()->focusObject();
1097
1098
1099
1100
1101
1102
1103
1104
1105QWindowList QGuiApplication::allWindows()
1107 return QGuiApplicationPrivate::window_list;
1111
1112
1113
1114
1115
1116
1117QWindowList QGuiApplication::topLevelWindows()
1119 const QWindowList &list = QGuiApplicationPrivate::window_list;
1120 QWindowList topLevelWindows;
1121 for (
int i = 0; i < list.size(); ++i) {
1122 QWindow *window = list.at(i);
1123 if (!window->isTopLevel())
1128 if (window->handle() && window->handle()->isEmbedded())
1131 topLevelWindows.prepend(window);
1134 return topLevelWindows;
1137QScreen *QGuiApplication::primaryScreen()
1139 if (QGuiApplicationPrivate::screen_list.isEmpty())
1141 return QGuiApplicationPrivate::screen_list.at(0);
1145
1146
1147
1148QList<QScreen *> QGuiApplication::screens()
1150 return QGuiApplicationPrivate::screen_list;
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164QScreen *QGuiApplication::screenAt(
const QPoint &point)
1166 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1167 for (
const QScreen *screen : QGuiApplication::screens()) {
1168 if (visitedScreens.contains(screen))
1172 for (QScreen *sibling : screen->virtualSiblings()) {
1173 if (sibling->geometry().contains(point))
1176 visitedScreens.append(sibling);
1184
1185
1186
1187
1188
1189
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226qreal QGuiApplication::devicePixelRatio()
const
1228 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1229 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1231 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1232 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1233 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1235 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1238void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1240 m_maxDevicePixelRatio = 0.0;
1243void QGuiApplicationPrivate::_q_updatePrimaryScreenDpis()
1246 const QScreen *screen = QGuiApplication::primaryScreen();
1248 int dpiX = qRound(screen->logicalDotsPerInchX());
1249 int dpiY = qRound(screen->logicalDotsPerInchY());
1250 dpis = (dpiX << 16) | (dpiY & 0xffff);
1251 QObject::connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
1252 q_func(), SLOT(_q_updatePrimaryScreenDpis()), Qt::UniqueConnection);
1254 m_primaryScreenDpis.storeRelaxed(dpis);
1258
1259
1260QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1262 if (QScreen *windowScreen = screenAt(pos)) {
1263 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1264 return windowScreen->handle()->topLevelAt(devicePosition);
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
1304
1306QString QGuiApplication::platformName()
1308 if (!QGuiApplication::instance()) {
1309#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1310 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1315 return QGuiApplicationPrivate::platform_name ?
1316 *QGuiApplicationPrivate::platform_name : QString();
1324static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1326 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1327 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1328 <<
"platformPluginPath" << platformPluginPath
1329 <<
"platformThemeName" << platformThemeName;
1331 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1332 QStringList platformArguments;
1333 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1334 for (
const auto &pluginArgument : std::as_const(plugins)) {
1336 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1337 if (arguments.isEmpty())
1339 const QString name = arguments.takeFirst().toLower();
1340 QString argumentsKey = name;
1343 argumentsKey[0] = argumentsKey.at(0).toUpper();
1344 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1346 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1349 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1350 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1351 if (availablePlugins.contains(name)) {
1352 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1353 qCWarning(lcQpaPluginLoading).nospace().noquote()
1354 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1356 qCInfo(lcQpaPluginLoading).nospace().noquote()
1357 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1358 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1360 qCWarning(lcQpaPluginLoading).nospace().noquote()
1361 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1362 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1365 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1366 QGuiApplicationPrivate::platform_name =
new QString(name);
1367 platformArguments = arguments;
1372 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1373 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1374 "Reinstalling the application may fix this problem.\n");
1376 if (!availablePlugins.isEmpty())
1377 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1379#if defined(Q_OS_WIN)
1382 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1383 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1385 qFatal(
"%s", qPrintable(fatalMessage));
1393 QStringList themeNames;
1394 if (!platformThemeName.isEmpty()) {
1395 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment";
1396 themeNames.append(platformThemeName);
1399#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1401 if (checkNeedPortalSupport()) {
1402 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1403 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1408 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1409 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1410 themeNames.append(platformIntegrationThemeNames);
1413 for (
const QString &themeName : std::as_const(themeNames)) {
1414 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1415 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1416 if (QGuiApplicationPrivate::platform_theme) {
1417 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1420 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1421 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1422 if (QGuiApplicationPrivate::platform_theme) {
1423 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName <<
"via createPlatformTheme";
1429 if (!QGuiApplicationPrivate::platform_theme) {
1430 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1431 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1436 if (!platformArguments.isEmpty()) {
1437 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1438 for (
const QString &argument : std::as_const(platformArguments)) {
1439 const qsizetype equalsPos = argument.indexOf(u'=');
1440 const QByteArray name =
1441 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1443 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1444 nativeInterface->setProperty(name.constData(), std::move(value));
1449 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
1450 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1451 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1452 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1454 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1455 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1456 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1462 for (
int i = 0; i < pluginList.size(); ++i) {
1463 QByteArray pluginSpec = pluginList.at(i);
1464 qsizetype colonPos = pluginSpec.indexOf(
':');
1467 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1469 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1470 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1472 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1474 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1478#if QT_CONFIG(commandlineparser)
1479void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1481 QCoreApplicationPrivate::addQtOptions(options);
1483#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1484 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1485 const bool x11 = sessionType ==
"x11";
1488 const bool x11 =
false;
1491 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1492 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1493 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1494 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1495 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1496 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1497 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1498 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1499 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1500 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1501 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1502 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1503 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1504 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1505 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1506 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1507 options->append(QCommandLineOption(QStringLiteral(
"session"),
1508 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1511 options->append(QCommandLineOption(QStringLiteral(
"display"),
1512 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1513 options->append(QCommandLineOption(QStringLiteral(
"name"),
1514 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1515 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1516 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1517 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1518 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1519 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1520 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1522 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1523 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1524 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1525 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1526 options->append(QCommandLineOption(QStringLiteral(
"title"),
1527 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1532void QGuiApplicationPrivate::createPlatformIntegration()
1534 QHighDpiScaling::initHighDpiScaling();
1537 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1540 QByteArray platformName;
1541#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1542 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1544#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1545 QList<QByteArray> platformArguments = platformName.split(
':');
1546 QByteArray platformPluginBase = platformArguments.first();
1548 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1549 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1551 QVector<QByteArray> preferredPlatformOrder;
1552 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1553 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1554 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1555 preferredPlatformOrder << xcbPlatformName;
1557 platformName.clear();
1560 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1561 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1562 if (hasWaylandDisplay || isWaylandSessionType) {
1563 preferredPlatformOrder.prepend(waylandPlatformName);
1565 if (defaultIsWayland)
1566 platformName.clear();
1569 if (!platformName.isEmpty())
1570 preferredPlatformOrder.append(platformName);
1572 platformName = preferredPlatformOrder.join(
';');
1575 bool platformExplicitlySelected =
false;
1576 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1577 if (!platformNameEnv.isEmpty()) {
1578 platformName = platformNameEnv;
1579 platformExplicitlySelected =
true;
1582 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1588 int j = argc ? 1 : 0;
1589 for (
int i=1; i<argc; i++) {
1592 if (*argv[i] !=
'-') {
1593 argv[j++] = argv[i];
1596 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1597 const char *arg = argv[i];
1600 if (strcmp(arg,
"-platformpluginpath") == 0) {
1602 platformPluginPath = QFile::decodeName(argv[i]);
1603 }
else if (strcmp(arg,
"-platform") == 0) {
1605 platformExplicitlySelected =
true;
1606 platformName = argv[i];
1608 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1610 platformThemeName = QString::fromLocal8Bit(argv[i]);
1611 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1613 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1614 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1616 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1617 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1619 icon = QFile::decodeName(argv[i]);
1622 argv[j++] = argv[i];
1631 Q_UNUSED(platformExplicitlySelected);
1633 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1634 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
1636 if (!icon.isEmpty())
1637 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1641
1642
1643
1644
1645
1646void QGuiApplicationPrivate::createEventDispatcher()
1648 Q_ASSERT(!eventDispatcher);
1650 if (platform_integration ==
nullptr)
1651 createPlatformIntegration();
1654 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1655 "Creating the platform integration resulted in creating an event dispatcher");
1658 Q_ASSERT(!eventDispatcher);
1660 eventDispatcher = platform_integration->createEventDispatcher();
1663void QGuiApplicationPrivate::eventDispatcherReady()
1665 if (platform_integration ==
nullptr)
1666 createPlatformIntegration();
1668 platform_integration->initialize();
1671void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1673 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1675#if defined(Q_OS_MACOS)
1676 QMacAutoReleasePool pool;
1679 QObject::connect(q_func(), SIGNAL(screenAdded(QScreen*)),
1680 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1681 QObject::connect(q_func(), SIGNAL(primaryScreenChanged(QScreen *)),
1682 q_func(), SLOT(_q_updatePrimaryScreenDpis()));
1684 QCoreApplicationPrivate::init();
1686 QCoreApplicationPrivate::is_app_running =
false;
1688 bool loadTestability =
false;
1689 QList<QByteArray> pluginList;
1691#ifndef QT_NO_SESSIONMANAGER
1693 QString session_key;
1694# if defined(Q_OS_WIN)
1695 wchar_t guidstr[40];
1697 CoCreateGuid(&guid);
1698 StringFromGUID2(guid, guidstr, 40);
1699 session_id = QString::fromWCharArray(guidstr);
1700 CoCreateGuid(&guid);
1701 StringFromGUID2(guid, guidstr, 40);
1702 session_key = QString::fromWCharArray(guidstr);
1706 int j = argc ? 1 : 0;
1707 for (
int i=1; i<argc; i++) {
1710 if (*argv[i] !=
'-') {
1711 argv[j++] = argv[i];
1714 const char *arg = argv[i];
1717 if (strcmp(arg,
"-plugin") == 0) {
1719 pluginList << argv[i];
1720 }
else if (strcmp(arg,
"-reverse") == 0) {
1721 force_reverse =
true;
1723 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1726 if (QDir::currentPath() ==
"/"_L1) {
1727 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1728 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1729 kCFURLPOSIXPathStyle));
1730 if (qbundlePath.endsWith(
".app"_L1))
1731 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1734#ifndef QT_NO_SESSIONMANAGER
1735 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1737 if (argv[i] && *argv[i]) {
1738 session_id = QString::fromLatin1(argv[i]);
1739 qsizetype p = session_id.indexOf(u'_');
1741 session_key = session_id.mid(p +1);
1742 session_id = session_id.left(p);
1744 is_session_restored =
true;
1747 }
else if (strcmp(arg,
"-testability") == 0) {
1748 loadTestability =
true;
1749 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1750 s = QString::fromLocal8Bit(arg + 7);
1751 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1752 s = QString::fromLocal8Bit(argv[++i]);
1754 argv[j++] = argv[i];
1767 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1768 if (!envPlugins.isEmpty())
1769 pluginList += envPlugins.split(
',');
1771 if (platform_integration ==
nullptr)
1772 createPlatformIntegration();
1775 QFont::initialize();
1779 QCursorData::initialize();
1783 qRegisterGuiVariant();
1785#if QT_CONFIG(animation)
1787 qRegisterGuiGetInterpolator();
1790 QWindowSystemInterfacePrivate::eventTime.start();
1792#if QT_CONFIG(accessibility)
1793 QAccessible::installFactory([](
const QString &classname, QObject *object)
1794 -> QAccessibleInterface * {
1795 if (classname ==
"QForeignWindow"_L1)
1796 return new QAccessibleWindow(
static_cast<QWindow *>(object));
1801 is_app_running =
true;
1802 init_plugins(pluginList);
1803 QWindowSystemInterface::flushWindowSystemEvents();
1805 Q_Q(QGuiApplication);
1806#ifndef QT_NO_SESSIONMANAGER
1808 session_manager =
new QSessionManager(q, session_id, session_key);
1811#if QT_CONFIG(library)
1812 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1813 loadTestability =
true;
1815 if (loadTestability) {
1816 QLibrary testLib(QStringLiteral(
"qttestability"));
1817 if (Q_UNLIKELY(!testLib.load())) {
1818 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1820 typedef void (*TasInitialize)(
void);
1821 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1822 if (Q_UNLIKELY(!initFunction)) {
1823 qCritical(
"Library qttestability resolve failed!");
1830 Q_UNUSED(loadTestability);
1834 QGuiApplication::setLayoutDirection(layout_direction);
1836 if (!QGuiApplicationPrivate::displayName)
1837 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1838 q, &QGuiApplication::applicationDisplayNameChanged);
1841extern void qt_cleanupFontDatabase();
1843QGuiApplicationPrivate::~QGuiApplicationPrivate()
1845#if defined(Q_OS_MACOS)
1846 QMacAutoReleasePool pool;
1849 is_app_closing =
true;
1850 is_app_running =
false;
1852 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1853 delete generic_plugin_list.at(i);
1854 generic_plugin_list.clear();
1856 clearFontUnlocked();
1861 QCursorData::cleanup();
1864 layout_direction = Qt::LayoutDirectionAuto;
1866 cleanupThreadData();
1868 delete QGuiApplicationPrivate::styleHints;
1869 QGuiApplicationPrivate::styleHints =
nullptr;
1872 qt_cleanupFontDatabase();
1874 QPixmapCache::clear();
1877 if (ownGlobalShareContext) {
1878 delete qt_gl_global_share_context();
1879 qt_gl_set_global_share_context(
nullptr);
1883#if QT_CONFIG(vulkan)
1884 QVulkanDefaultInstance::cleanup();
1887 platform_integration->destroy();
1889 delete platform_theme;
1890 platform_theme =
nullptr;
1891 delete platform_integration;
1892 platform_integration =
nullptr;
1894 window_list.clear();
1896 screen_list.clear();
1899 QT_IGNORE_DEPRECATIONS(QGuiApplicationPrivate::self =
nullptr;)
1904QCursor *overrideCursor();
1905void setOverrideCursor(
const QCursor &);
1906void changeOverrideCursor(
const QCursor &);
1907void restoreOverrideCursor();
1911static QFont font(
const QWidget*);
1912static QFont font(
const char *className);
1913static void setFont(
const QFont &,
const char *className =
nullptr);
1914static QFontMetrics fontMetrics();
1916#ifndef QT_NO_CLIPBOARD
1917static QClipboard *clipboard();
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1936 return QGuiApplicationPrivate::modifier_buttons;
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1958 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1959 return pi->keyMapper()->queryKeyboardModifiers();
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975Qt::MouseButtons QGuiApplication::mouseButtons()
1977 return QGuiApplicationPrivate::mouse_buttons;
1981
1982
1983
1984
1985QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1987 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1988 return pi ? pi->nativeInterface() :
nullptr;
1992
1993
1994
1995QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1997 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1999 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
2003 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030int QGuiApplication::exec()
2032#if QT_CONFIG(accessibility)
2033 QAccessible::setRootObject(qApp);
2035 return QCoreApplication::exec();
2038void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
2040 if (e->spontaneous()) {
2048 switch (e->type()) {
2049 case QEvent::MouseButtonPress: {
2050 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2051 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2052 QGuiApplicationPrivate::mouse_buttons |= me->button();
2055 case QEvent::MouseButtonDblClick: {
2056 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2057 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2058 QGuiApplicationPrivate::mouse_buttons |= me->button();
2061 case QEvent::MouseButtonRelease: {
2062 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2063 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2064 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2067 case QEvent::KeyPress:
2068 case QEvent::KeyRelease:
2069 case QEvent::MouseMove:
2070#if QT_CONFIG(wheelevent)
2073 case QEvent::TouchBegin:
2074 case QEvent::TouchUpdate:
2075 case QEvent::TouchEnd:
2076#if QT_CONFIG(tabletevent)
2077 case QEvent::TabletMove:
2078 case QEvent::TabletPress:
2079 case QEvent::TabletRelease:
2082 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2083 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2093
2094bool QGuiApplication::notify(QObject *object, QEvent *event)
2096 Q_D(QGuiApplication);
2097 if (object->isWindowType()) {
2098 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2102 switch (event->type()) {
2103 case QEvent::ApplicationDeactivate:
2104 case QEvent::OrientationChange:
2110 d->closeAllPopups();
2116 QGuiApplicationPrivate::captureGlobalModifierState(event);
2118 return QCoreApplication::notify(object, event);
2122
2123bool QGuiApplication::event(QEvent *e)
2125 switch (e->type()) {
2126 case QEvent::LanguageChange:
2128 if (layout_direction == Qt::LayoutDirectionAuto)
2129 setLayoutDirection(layout_direction);
2130 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2131 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2133 case QEvent::ApplicationFontChange:
2134 case QEvent::ApplicationPaletteChange:
2135 postEvent(QGuiApplication::styleHints(), e->clone());
2136 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows())
2137 postEvent(topLevelWindow,
new QEvent(e->type()));
2139 case QEvent::ThemeChange:
2140 forwardEvent(QGuiApplication::styleHints(), e);
2141 for (
auto *w : QGuiApplication::allWindows())
2147 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2149 if (!topLevelWindow->handle())
2151 if (!topLevelWindow->close()) {
2160 return QCoreApplication::event(e);
2163#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2165
2166
2167bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2169 QT_IGNORE_DEPRECATIONS(
2170 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2175bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2179 QPlatformWindow *platformWindow = window->handle();
2180 if (!platformWindow)
2183 if (event->spontaneous())
2186 return platformWindow->windowEvent(event);
2189bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2191 return window->nativeEvent(eventType, message, result);
2194bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2196 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArrayView(
"qtvirtualkeyboard");
2197 return usingVirtualKeyboard;
2201bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2203 if (!isUsingVirtualKeyboard()) {
2204 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2208 static QPointer<QWindow> virtualKeyboard;
2209 const QEvent::Type type = e->type();
2210 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2211 const auto me =
static_cast<QMouseEvent *>(e);
2212 const QPointF posF = me->globalPosition();
2213 const QPoint pos = posF.toPoint();
2216 if (!virtualKeyboard) {
2217 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2218 win->inherits(
"QtVirtualKeyboard::InputView")) {
2219 virtualKeyboard = win;
2221 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2226 Q_ASSERT(virtualKeyboard);
2227 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2228 && virtualKeyboard->geometry().contains(pos);
2230 if (!virtualKeyboardUnderMouse) {
2231 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2232 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2236 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2237 me->button(), me->buttons(), me->modifiers(),
2238 me->pointingDevice());
2240 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2241 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2247void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2249 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2250 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2252 const bool haveGuiApplication = QGuiApplication::instance() && QGuiApplicationPrivate::instance();
2253 Q_ASSERT_X(haveGuiApplication,
"QGuiApplication",
"Asked to process QPA event without a QGuiApplication");
2254 if (!haveGuiApplication) {
2255 qWarning(
"QGuiApplication was asked to process QPA event without a QGuiApplication instance");
2256 e->eventAccepted =
false;
2261 case QWindowSystemInterfacePrivate::Mouse:
2262 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2264 case QWindowSystemInterfacePrivate::Wheel:
2265 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2267 case QWindowSystemInterfacePrivate::Key:
2268 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2270 case QWindowSystemInterfacePrivate::Touch:
2271 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2273 case QWindowSystemInterfacePrivate::GeometryChange:
2274 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2276 case QWindowSystemInterfacePrivate::Enter:
2277 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2279 case QWindowSystemInterfacePrivate::Leave:
2280 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2282 case QWindowSystemInterfacePrivate::FocusWindow:
2283 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2285 case QWindowSystemInterfacePrivate::WindowStateChanged:
2286 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2288 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2289 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2291 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2292 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2294 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2295 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2297 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2298 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2299 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2301 case QWindowSystemInterfacePrivate::ApplicationTermination:
2302 QGuiApplicationPrivate::processApplicationTermination(e);
2304 case QWindowSystemInterfacePrivate::FlushEvents: {
2305 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2306 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2308 case QWindowSystemInterfacePrivate::Close:
2309 QGuiApplicationPrivate::processCloseEvent(
2310 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2312 case QWindowSystemInterfacePrivate::ScreenOrientation:
2313 QGuiApplicationPrivate::processScreenOrientationChange(
2314 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2316 case QWindowSystemInterfacePrivate::ScreenGeometry:
2317 QGuiApplicationPrivate::processScreenGeometryChange(
2318 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2320 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2321 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2322 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2324 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2325 QGuiApplicationPrivate::processScreenRefreshRateChange(
2326 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2328 case QWindowSystemInterfacePrivate::ThemeChange:
2329 QGuiApplicationPrivate::processThemeChanged(
2330 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2332 case QWindowSystemInterfacePrivate::Expose:
2333 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2335 case QWindowSystemInterfacePrivate::Paint:
2336 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2338 case QWindowSystemInterfacePrivate::Tablet:
2339 QGuiApplicationPrivate::processTabletEvent(
2340 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2342 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2343 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2344 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2346 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2347 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2348 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2350#ifndef QT_NO_GESTURES
2351 case QWindowSystemInterfacePrivate::Gesture:
2352 QGuiApplicationPrivate::processGestureEvent(
2353 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2356 case QWindowSystemInterfacePrivate::PlatformPanel:
2357 QGuiApplicationPrivate::processPlatformPanelEvent(
2358 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2360 case QWindowSystemInterfacePrivate::FileOpen:
2361 QGuiApplicationPrivate::processFileOpenEvent(
2362 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2364#ifndef QT_NO_CONTEXTMENU
2365 case QWindowSystemInterfacePrivate::ContextMenu:
2366 QGuiApplicationPrivate::processContextMenuEvent(
2367 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2370 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2371 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2374 qWarning() <<
"Unknown user input event type:" << e->type;
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2393 QEvent::Type type = QEvent::None;
2394 Qt::MouseButton button = Qt::NoButton;
2395 QWindow *window = e->window.data();
2396 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2398 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2399 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2400 bool mouseMove =
false;
2401 bool mousePress =
false;
2402 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2403 QPointF globalPoint = e->globalPos;
2405 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2406 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2410 type = e->buttonType;
2413 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2415 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2418 if (!mouseMove && positionChanged) {
2419 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2420 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2421 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2422 e->source, e->nonClientArea, device, e->eventPointId);
2424 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2425 processMouseEvent(&moveEvent);
2426 processMouseEvent(e);
2429 if (type == QEvent::MouseMove && !positionChanged) {
2437 modifier_buttons = e->modifiers;
2438 QPointF localPoint = e->localPos;
2439 bool doubleClick =
false;
2440 auto persistentEPD = devPriv->pointById(0);
2442 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2443 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2446 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2447 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2448 mouseDoubleClickDistance : touchDoubleTapDistance);
2449 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2450 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2451 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2452 mousePressButton = Qt::NoButton;
2454 static unsigned long lastPressTimestamp = 0;
2455 static QPointer<QWindow> lastPressWindow =
nullptr;
2456 mouse_buttons = e->buttons;
2458 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2459 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2460 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval
2461 && button == mousePressButton && lastPressWindow == e->window;
2462 mousePressButton = button;
2463 lastPressTimestamp = e ->timestamp;
2464 lastPressWindow = e->window;
2468 if (e->nullWindow()) {
2469 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2473 if (e->buttons != Qt::NoButton) {
2474 if (!currentMousePressWindow)
2475 currentMousePressWindow = window;
2477 window = currentMousePressWindow;
2478 }
else if (currentMousePressWindow) {
2479 window = currentMousePressWindow;
2480 currentMousePressWindow =
nullptr;
2482 localPoint = window->mapFromGlobal(globalPoint);
2490 if (!e->synthetic()) {
2491 if (
const QScreen *screen = window->screen())
2492 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2493 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2494 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2495 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2496 button, e->buttons, e->modifiers, e->source, device);
2500 ev.QInputEvent::setTimestamp(e->timestamp);
2501 cursor->pointerEvent(ev);
2506 const auto *activePopup = activePopupWindow();
2507 if (type == QEvent::MouseButtonPress)
2508 active_popup_on_press = activePopup;
2509 if (window->d_func()->blockedByModalWindow && !activePopup) {
2514 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2515 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2518 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2519 persistentEPD =
nullptr;
2521 ev.setTimestamp(e->timestamp);
2523 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2525 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2526 if (handlingPopup) {
2527 if (type == QEvent::MouseButtonPress)
2528 active_popup_on_press = handlingPopup;
2533 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2535 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2538 QGuiApplication::sendSpontaneousEvent(window, &ev);
2539 e->eventAccepted = ev.isAccepted();
2540 if (!e->synthetic() && !ev.isAccepted()
2541 && !e->nonClientArea
2542 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2543 QList<QWindowSystemInterface::TouchPoint> points;
2544 QWindowSystemInterface::TouchPoint point;
2546 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2551 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2552 point.state = QEventPoint::State::Pressed;
2553 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2554 point.state = QEventPoint::State::Released;
2555 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2556 point.state = QEventPoint::State::Updated;
2564 const QList<QEventPoint> &touchPoints =
2565 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2567 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2568 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2569 processTouchEvent(&fake);
2572 mousePressButton = Qt::NoButton;
2573 if (!e->window.isNull() || e->nullWindow()) {
2574 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2575 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2576 button, e->buttons, e->modifiers, e->source, device);
2577 dblClickEvent.setTimestamp(e->timestamp);
2578 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2581 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2582 popup_closed_on_press =
false;
2583 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2584 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2585 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2590void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2592#if QT_CONFIG(wheelevent)
2593 QWindow *window = e->window.data();
2594 QPointF globalPoint = e->globalPos;
2595 QPointF localPoint = e->localPos;
2597 if (e->nullWindow()) {
2598 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2600 localPoint = window->mapFromGlobal(globalPoint);
2606 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2607 modifier_buttons = e->modifiers;
2609 if (window->d_func()->blockedByModalWindow) {
2614 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2615 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2616 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2617 ev.setTimestamp(e->timestamp);
2618 QGuiApplication::sendSpontaneousEvent(window, &ev);
2619 e->eventAccepted = ev.isAccepted();
2625void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2627 QWindow *window = e->window.data();
2628 modifier_buttons = e->modifiers;
2629 if (e->nullWindow())
2630 window = QGuiApplication::focusWindow();
2633 e->eventAccepted =
false;
2637#if !defined(Q_OS_MACOS)
2640 if (e->keyType == QEvent::KeyPress) {
2641 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2642 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2648 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2649 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2650 e->unicode, e->repeat, e->repeatCount);
2651 ev.setTimestamp(e->timestamp);
2653 const auto *activePopup = activePopupWindow();
2654 if (activePopup && activePopup != window) {
2656 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2662 if (!window->d_func()->blockedByModalWindow)
2663 QGuiApplication::sendSpontaneousEvent(window, &ev);
2666 ev.setAccepted(
false);
2668 e->eventAccepted = ev.isAccepted();
2671void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2675 if (e->enter.data()->d_func()->blockedByModalWindow) {
2680 currentMouseWindow = e->enter;
2683 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2690 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2691 auto epd = devPriv->queryPointById(event.points().first().id());
2693 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2695 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2698void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2702 if (e->leave.data()->d_func()->blockedByModalWindow) {
2707 currentMouseWindow =
nullptr;
2709 QEvent event(QEvent::Leave);
2710 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2713void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2715 QWindow *previous = QGuiApplicationPrivate::focus_window;
2716 QWindow *newFocus = e->focused.data();
2718 if (previous == newFocus)
2721 bool activatedPopup =
false;
2723 if (QPlatformWindow *platformWindow = newFocus->handle())
2724 if (platformWindow->isAlertState())
2725 platformWindow->setAlertState(
false);
2726 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2728 activatePopup(newFocus);
2731 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2734 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2735 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2738 QGuiApplicationPrivate::focus_window = newFocus;
2743 Qt::FocusReason r = e->reason;
2744 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2745 r = Qt::PopupFocusReason;
2746 QFocusEvent focusOut(QEvent::FocusOut, r);
2747 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2748 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2749 qApp, SLOT(_q_updateFocusObject(QObject*)));
2750 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2751 setApplicationState(Qt::ApplicationActive);
2754 if (QGuiApplicationPrivate::focus_window) {
2755 Qt::FocusReason r = e->reason;
2756 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2757 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2758 r = Qt::PopupFocusReason;
2759 QFocusEvent focusIn(QEvent::FocusIn, r);
2760 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2761 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2762 qApp, SLOT(_q_updateFocusObject(QObject*)));
2763 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2764 setApplicationState(Qt::ApplicationInactive);
2767 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance()) {
2768 guiAppPrivate->notifyActiveWindowChange(previous);
2770 if (previousFocusObject !=
qApp->focusObject() ||
2776 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2777 guiAppPrivate->_q_updateFocusObject(
qApp->focusObject());
2781 emit
qApp->focusWindowChanged(newFocus);
2783 emit previous->activeChanged();
2785 emit newFocus->activeChanged();
2788void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2790 if (QWindow *window = wse->window.data()) {
2791 QWindowPrivate *windowPrivate = qt_window_private(window);
2792 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2794 windowPrivate->windowState = wse->newState;
2795 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2796 if (newEffectiveState != originalEffectiveState)
2797 emit window->windowStateChanged(newEffectiveState);
2799 windowPrivate->updateVisibility();
2801 QWindowStateChangeEvent e(wse->oldState);
2802 QGuiApplication::sendSpontaneousEvent(window, &e);
2806void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2808 QWindow *window = wse->window.data();
2812 QScreen *screen = wse->screen.data();
2813 if (window->screen() == screen)
2816 auto *windowPrivate = QWindowPrivate::get(window);
2817 QWindow *topLevelWindow = windowPrivate->topLevelWindow(QWindow::ExcludeTransients);
2818 if (window == topLevelWindow) {
2820 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2822 topLevelWindow->setScreen(
nullptr);
2823 }
else if (screen) {
2828 windowPrivate->emitScreenChangedRecursion(screen);
2832void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2834 if (wde->window.isNull())
2836 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2839void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2841 if (wse->window.isNull())
2844 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2846 QEvent event(QEvent::SafeAreaMarginsChange);
2847 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2850void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *)
2857 if (
auto *guiAppPrivate = QGuiApplicationPrivate::instance())
2858 guiAppPrivate->handleThemeChanged();
2860 QIconPrivate::clearIconCache();
2862 QEvent themeChangeEvent(QEvent::ThemeChange);
2863 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2866void QGuiApplicationPrivate::handleThemeChanged()
2868 QStyleHintsPrivate::get(QGuiApplication::styleHints())->update(platformTheme());
2871 QIconLoader::instance()->updateSystemTheme();
2872 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2874 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2875 const auto locker = qt_scoped_lock(applicationFontMutex);
2876 clearFontUnlocked();
2882void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2884 if (e->window.isNull())
2887 QWindow *window = e->window.data();
2891 const QRect lastReportedGeometry = window->d_func()->geometry;
2892 const QRect requestedGeometry = e->requestedGeometry;
2893 const QRect actualGeometry = e->newGeometry;
2903 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2904 || requestedGeometry.size() != actualGeometry.size();
2905 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2906 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2908 window->d_func()->geometry = actualGeometry;
2910 if (isResize || window->d_func()->resizeEventPending) {
2911 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2912 QGuiApplication::sendSpontaneousEvent(window, &e);
2914 window->d_func()->resizeEventPending =
false;
2916 if (actualGeometry.width() != lastReportedGeometry.width())
2917 emit window->widthChanged(actualGeometry.width());
2918 if (actualGeometry.height() != lastReportedGeometry.height())
2919 emit window->heightChanged(actualGeometry.height());
2924 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2925 QGuiApplication::sendSpontaneousEvent(window, &e);
2927 if (actualGeometry.x() != lastReportedGeometry.x())
2928 emit window->xChanged(actualGeometry.x());
2929 if (actualGeometry.y() != lastReportedGeometry.y())
2930 emit window->yChanged(actualGeometry.y());
2934void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2936 if (e->window.isNull())
2938 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2941 e->eventAccepted =
false;
2946 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2948 e->eventAccepted = event.isAccepted();
2951void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2953 if (e->url.isEmpty())
2956 QFileOpenEvent event(e->url);
2957 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2960QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2962 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2963 TabletPointData &pointData = tabletDevicePoints[i];
2964 if (pointData.deviceId == deviceId)
2968 tabletDevicePoints.append(TabletPointData(deviceId));
2969 return tabletDevicePoints.last();
2972void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2974#if QT_CONFIG(tabletevent)
2975 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2976 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2978 QEvent::Type type = QEvent::TabletMove;
2979 if (e->buttons != pointData.state)
2980 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2982 QWindow *window = e->window.data();
2983 modifier_buttons = e->modifiers;
2985 bool localValid =
true;
2989 if (type == QEvent::TabletPress) {
2990 if (e->nullWindow()) {
2991 window = QGuiApplication::topLevelAt(e->global.toPoint());
2996 active_popup_on_press = activePopupWindow();
2997 pointData.target = window;
2999 if (e->nullWindow()) {
3000 window = pointData.target;
3003 if (type == QEvent::TabletRelease)
3004 pointData.target =
nullptr;
3008 QPointF local = e->local;
3010 QPointF delta = e->global - e->global.toPoint();
3011 local = window->mapFromGlobal(e->global.toPoint()) + delta;
3015 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
3016 Qt::MouseButton button = Qt::NoButton;
3017 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
3018 if (check & stateChange) {
3019 button = Qt::MouseButton(check);
3024 const auto *activePopup = activePopupWindow();
3025 if (window->d_func()->blockedByModalWindow && !activePopup) {
3030 QTabletEvent tabletEvent(type, device, local, e->global,
3031 e->pressure, e->xTilt, e->yTilt,
3032 e->tangentialPressure, e->rotation, e->z,
3033 e->modifiers, button, e->buttons);
3034 tabletEvent.setAccepted(
false);
3035 tabletEvent.setTimestamp(e->timestamp);
3037 if (activePopup && activePopup != window) {
3039 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3043 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3044 pointData.state = e->buttons;
3045 if (!tabletEvent.isAccepted()
3046 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3047 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3049 const QEvent::Type mouseType = [&]() {
3051 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3052 case QEvent::TabletMove:
return QEvent::MouseMove;
3053 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3054 default: Q_UNREACHABLE();
3057 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3058 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3059 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3060 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3061 << e->local << button << e->buttons << e->modifiers;
3062 processMouseEvent(&mouseEvent);
3069void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3071#if QT_CONFIG(tabletevent)
3072 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3073 QTabletEvent ev(QEvent::TabletEnterProximity, dev, e->local, e->global,
3074 e->pressure, e->xTilt, e->yTilt,
3075 e->tangentialPressure, e->rotation, e->z,
3076 e->modifiers, Qt::NoButton,
3077 tabletDevicePoint(dev->uniqueId().numericId()).state);
3078 ev.setTimestamp(e->timestamp);
3079 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3085void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3087#if QT_CONFIG(tabletevent)
3088 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3089 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, e->local, e->global,
3090 e->pressure, e->xTilt, e->yTilt,
3091 e->tangentialPressure, e->rotation, e->z,
3092 e->modifiers, Qt::NoButton,
3093 tabletDevicePoint(dev->uniqueId().numericId()).state);
3094 ev.setTimestamp(e->timestamp);
3095 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3101#ifndef QT_NO_GESTURES
3102void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3104 if (e->window.isNull())
3107 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3108 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3109 e->delta, e->sequenceId);
3110 ev.setTimestamp(e->timestamp);
3111 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3115void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3120 if (e->window->d_func()->blockedByModalWindow) {
3125 QEvent ev(QEvent::PlatformPanel);
3126 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3129#ifndef QT_NO_CONTEXTMENU
3130void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3134 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3137 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3138 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3139 e->eventAccepted = ev.isAccepted();
3143void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3150 e->eventAccepted =
false;
3152 if (!QInputDevicePrivate::isRegistered(e->device))
3155 modifier_buttons = e->modifiers;
3156 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3157 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3159 auto *guiAppPrivate = QGuiApplicationPrivate::instance();
3161 if (e->touchType == QEvent::TouchCancel) {
3164 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3165 touchEvent.setTimestamp(e->timestamp);
3166 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3167 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3169 for (
auto &epd : devPriv->activePoints.values()) {
3170 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3171 windowsNeedingCancel.insert(w);
3174 for (QWindow *w : windowsNeedingCancel) {
3175 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3176 e->eventAccepted |= touchEvent.isAccepted();
3179 if (!guiAppPrivate->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3180 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = guiAppPrivate->synthesizedMousePoints.constBegin(),
3181 synthItEnd = guiAppPrivate->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3182 if (!synthIt->window)
3184 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3191 QEvent::MouseButtonRelease,
3192 Qt::MouseEventNotSynthesized,
3195 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3196 processMouseEvent(&fake);
3198 guiAppPrivate->synthesizedMousePoints.clear();
3201 guiAppPrivate->lastTouchType = e->touchType;
3202 devPriv->activePoints.clear();
3207 if (guiAppPrivate->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3210 guiAppPrivate->lastTouchType = e->touchType;
3212 QPointer<QWindow> window = e->window;
3213 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3219 for (
auto &tempPt : e->points) {
3221 auto epd = devPriv->pointById(tempPt.id());
3222 auto &ep = epd->eventPoint;
3223 epd->eventPoint.setAccepted(
false);
3224 switch (tempPt.state()) {
3225 case QEventPoint::State::Pressed:
3227 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3228 window = devPriv->firstActiveWindow();
3231 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3232 QMutableEventPoint::setWindow(ep, window);
3233 active_popup_on_press = activePopupWindow();
3236 case QEventPoint::State::Released:
3237 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3238 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3239 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3240 window = QMutableEventPoint::window(ep);
3244 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3245 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3246 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3247 window = QMutableEventPoint::window(ep);
3251 if (Q_UNLIKELY(!window)) {
3252 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3255 QMutableEventPoint::update(tempPt, ep);
3257 Q_ASSERT(window.data() !=
nullptr);
3260 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3263 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3266 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3270 for (QMutableTouchEvent &ev : touchEvents) {
3271 if (ev.target() == window.data()) {
3278 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3279 mte.setTimestamp(e->timestamp);
3280 mte.setTarget(window.data());
3281 touchEvents.append(mte);
3285 if (touchEvents.isEmpty())
3288 for (QMutableTouchEvent &touchEvent : touchEvents) {
3289 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3291 QEvent::Type eventType;
3292 switch (touchEvent.touchPointStates()) {
3293 case QEventPoint::State::Pressed:
3294 eventType = QEvent::TouchBegin;
3296 case QEventPoint::State::Released:
3297 eventType = QEvent::TouchEnd;
3300 eventType = QEvent::TouchUpdate;
3304 const auto *activePopup = activePopupWindow();
3305 if (window->d_func()->blockedByModalWindow && !activePopup) {
3309 if (touchEvent.type() == QEvent::TouchEnd) {
3312 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3313 touchEvent.setTimestamp(e->timestamp);
3314 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3319 if (activePopup && activePopup != window) {
3321 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3328 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3329 e->eventAccepted |= touchEvent.isAccepted();
3331 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3333 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3335 QEvent::Type mouseEventType = QEvent::MouseMove;
3336 Qt::MouseButton button = Qt::NoButton;
3337 Qt::MouseButtons buttons = Qt::LeftButton;
3338 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3339 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3340 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3342 if (m_fakeMouseSourcePointId >= 0) {
3343 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3345 switch (touchPoint->state()) {
3346 case QEventPoint::State::Pressed:
3347 mouseEventType = QEvent::MouseButtonPress;
3348 button = Qt::LeftButton;
3350 case QEventPoint::State::Released:
3351 mouseEventType = QEvent::MouseButtonRelease;
3352 button = Qt::LeftButton;
3353 buttons = Qt::NoButton;
3354 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3355 m_fakeMouseSourcePointId = -1;
3360 if (touchPoint->state() != QEventPoint::State::Released) {
3361 guiAppPrivate->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3362 touchPoint->position(), touchPoint->globalPosition(), window));
3368 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3369 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3370 touchPoint->globalPosition(),
3375 Qt::MouseEventSynthesizedByQt,
3379 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3380 processMouseEvent(&fake);
3381 e->eventAccepted |= fake.eventAccepted;
3384 if (eventType == QEvent::TouchEnd)
3385 guiAppPrivate->synthesizedMousePoints.clear();
3392 for (
const QEventPoint &touchPoint : e->points) {
3393 if (touchPoint.state() == QEventPoint::State::Released)
3394 devPriv->removePointById(touchPoint.id());
3398void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3401 if (QCoreApplication::startingUp())
3407 QScreen *s = e->screen.data();
3408 s->d_func()->orientation = e->orientation;
3410 emit s->orientationChanged(s->orientation());
3412 QScreenOrientationChangeEvent event(s, s->orientation());
3413 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3416void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3419 if (QCoreApplication::startingUp())
3426 QScreen *s = e->screen.data();
3427 QScreenPrivate::UpdateEmitter updateEmitter(s);
3431 s->d_func()->geometry = e->geometry;
3432 s->d_func()->availableGeometry = e->availableGeometry;
3434 s->d_func()->updatePrimaryOrientation();
3437 resetCachedDevicePixelRatio();
3440void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3443 if (QCoreApplication::startingUp())
3446 QHighDpiScaling::updateHighDpiScaling();
3452 QScreen *s = e->screen.data();
3453 QScreenPrivate::UpdateEmitter updateEmitter(s);
3454 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3455 s->d_func()->updateGeometry();
3458 for (QWindow *window : QGuiApplication::allWindows())
3459 if (window->screen() == e->screen)
3460 QWindowPrivate::get(window)->updateDevicePixelRatio();
3462 resetCachedDevicePixelRatio();
3465void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3468 if (QCoreApplication::startingUp())
3474 QScreen *s = e->screen.data();
3475 qreal rate = e->rate;
3479 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3480 s->d_func()->refreshRate = rate;
3481 emit s->refreshRateChanged(s->refreshRate());
3485void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3490 QWindow *window = e->window.data();
3493 QWindowPrivate *p = qt_window_private(window);
3500 p->positionAutomatic =
false;
3501 p->resizeAutomatic =
false;
3504 if (!p->receivedExpose) {
3505 if (p->resizeEventPending) {
3508 QResizeEvent e(window->geometry().size(), p->geometry.size());
3509 QGuiApplication::sendSpontaneousEvent(window, &e);
3511 p->resizeEventPending =
false;
3520 p->receivedExpose =
true;
3524 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3526 const bool wasExposed = p->exposed;
3527 p->exposed = e->isExposed && window->screen();
3532 if (e->isExposed && !e->region.isEmpty()) {
3533 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3535 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3536 <<
"Please file a QTBUG which explains how to reproduce.";
3540 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3541 QPaintEvent paintEvent(e->region);
3542 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3543 if (paintEvent.isAccepted())
3551 QExposeEvent exposeEvent(e->region);
3552 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3553 e->eventAccepted = exposeEvent.isAccepted();
3560 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3561 QPaintEvent paintEvent(e->region);
3562 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3566void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3568 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3569 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3574 QPaintEvent paintEvent(e->region);
3575 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3579 e->eventAccepted = paintEvent.isAccepted();
3582#if QT_CONFIG(draganddrop)
3585
3586
3587
3588
3589static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3591 QGuiApplicationPrivate::mouse_buttons = buttons;
3592 QGuiApplicationPrivate::modifier_buttons = modifiers;
3595QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3596 const QPoint &p, Qt::DropActions supportedActions,
3597 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3599 updateMouseAndModifierButtonState(buttons, modifiers);
3601 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3602 QPlatformDrag *platformDrag = platformIntegration()->drag();
3603 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3604 lastAcceptedDropAction = Qt::IgnoreAction;
3605 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3609 currentDragWindow =
nullptr;
3611 QGuiApplication::sendEvent(w, &e);
3612 lastAcceptedDropAction = Qt::IgnoreAction;
3613 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3615 QDragMoveEvent me(QPointF(p), supportedActions, dropData, buttons, modifiers);
3617 if (w != currentDragWindow) {
3618 lastAcceptedDropAction = Qt::IgnoreAction;
3619 if (currentDragWindow) {
3621 QGuiApplication::sendEvent(currentDragWindow, &e);
3623 currentDragWindow = w;
3624 QDragEnterEvent e(QPointF(p), supportedActions, dropData, buttons, modifiers);
3625 QGuiApplication::sendEvent(w, &e);
3626 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3627 lastAcceptedDropAction = e.dropAction();
3631 if (lastAcceptedDropAction != Qt::IgnoreAction
3632 && (supportedActions & lastAcceptedDropAction)) {
3633 me.setDropAction(lastAcceptedDropAction);
3636 QGuiApplication::sendEvent(w, &me);
3637 lastAcceptedDropAction = me.isAccepted() ?
3638 me.dropAction() : Qt::IgnoreAction;
3639 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3642QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3643 const QPoint &p, Qt::DropActions supportedActions,
3644 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3646 updateMouseAndModifierButtonState(buttons, modifiers);
3648 currentDragWindow =
nullptr;
3650 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3651 QGuiApplication::sendEvent(w, &de);
3653 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3654 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3660#ifndef QT_NO_CLIPBOARD
3662
3663
3664QClipboard * QGuiApplication::clipboard()
3666 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3668 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3671 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3673 return QGuiApplicationPrivate::qt_clipboard;
3678
3679
3680
3681
3682
3683
3684
3685
3686
3689
3690
3691
3692
3693
3694
3696QPalette QGuiApplication::palette()
3698 if (!QGuiApplicationPrivate::app_pal)
3699 QGuiApplicationPrivate::updatePalette();
3701 return *QGuiApplicationPrivate::app_pal;