103#include <QtCore/QThreadPool>
106#include <qtgui_tracepoints_p.h>
108#include <private/qtools_p.h>
117using namespace Qt::StringLiterals;
118using namespace QtMiscUtils;
121#define CHECK_QAPP_INSTANCE(...)
122 if (Q_LIKELY(QCoreApplication::instance())) {
124 qWarning("Must construct a QGuiApplication first.");
131Q_CONSTINIT Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
132Q_CONSTINIT Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
134Q_CONSTINIT QGuiApplicationPrivate::QLastCursorPosition QGuiApplicationPrivate::lastCursorPosition;
140Q_CONSTINIT Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
142Q_CONSTINIT Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
143 Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
145Q_CONSTINIT QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
147Q_CONSTINIT QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints;
152Q_CONSTINIT QList<QObject *> QGuiApplicationPrivate::generic_plugin_list;
169Q_CONSTINIT Qt::MouseButton QGuiApplicationPrivate::mousePressButton = Qt::NoButton;
176Q_CONSTINIT
static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
177Q_CONSTINIT
static Qt::LayoutDirection effective_layout_direction = Qt::LeftToRight;
181Q_CONSTINIT
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = -1;
183#ifndef QT_NO_CLIPBOARD
187Q_CONSTINIT QList<QScreen *> QGuiApplicationPrivate::screen_list;
189Q_CONSTINIT QWindowList QGuiApplicationPrivate::window_list;
190Q_CONSTINIT QWindowList QGuiApplicationPrivate::popup_list;
191Q_CONSTINIT
const QWindow *QGuiApplicationPrivate::active_popup_on_press =
nullptr;
194Q_CONSTINIT
static QBasicMutex applicationFontMutex;
197Q_CONSTINIT
bool QGuiApplicationPrivate::obey_desktop_settings =
true;
198Q_CONSTINIT
bool QGuiApplicationPrivate::popup_closed_on_press =
false;
202Q_CONSTINIT qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
204Q_CONSTINIT
static qreal fontSmoothingGamma = 1.7;
206Q_CONSTINIT
bool QGuiApplicationPrivate::quitOnLastWindowClosed =
true;
209#if QT_CONFIG(animation)
210extern void qRegisterGuiGetInterpolator();
215 return force_reverse ^
216 (QGuiApplication::tr(
"QT_LAYOUT_DIRECTION",
217 "Translate this string to the string 'LTR' in left-to-right"
218 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
219 " and Arabic) to get proper widget layout.") ==
"RTL"_L1);
224 if (!QGuiApplicationPrivate::app_font) {
225 if (
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
226 if (
const QFont *font = theme->font(QPlatformTheme::SystemFont))
227 QGuiApplicationPrivate::app_font =
new QFont(*font);
229 if (!QGuiApplicationPrivate::app_font)
230 QGuiApplicationPrivate::app_font =
231 new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
236 delete QGuiApplicationPrivate::app_font;
237 QGuiApplicationPrivate::app_font =
nullptr;
242 mouseDoubleClickDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
243 touchDoubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
249 return QFileInfo::exists(
"/.flatpak-info"_L1) || qEnvironmentVariableIsSet(
"SNAP");
256#define Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER { Qt::TopLeftCorner, -1
, -1
, -1
, -1
}
276 const qsizetype size = a.size();
281 if (*op ==
'+' || *op ==
'-' || *op ==
'x')
283 else if (isAsciiDigit(*op))
288 const int numberPos = pos;
289 for ( ; pos < size && isAsciiDigit(a.at(pos)); ++pos) ;
292 const int result = a.mid(numberPos, pos - numberPos).toInt(&ok);
293 return ok ? result : -1;
300 for (
int i = 0; i < 4; ++i) {
302 const int value = nextGeometryToken(a, pos, &op);
314 result.corner = result.corner == Qt::TopRightCorner ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
318 result.corner = Qt::TopRightCorner;
327 QRect windowGeometry = window->frameGeometry();
328 QSize size = windowGeometry.size();
330 const QSize windowMinimumSize = window->minimumSize();
331 const QSize windowMaximumSize = window->maximumSize();
333 size.setWidth(qBound(windowMinimumSize.width(),
width, windowMaximumSize.width()));
335 size.setHeight(qBound(windowMinimumSize.height(),
height, windowMaximumSize.height()));
336 window->resize(size);
339 const QRect availableGeometry = window->screen()->virtualGeometry();
340 QPoint topLeft = windowGeometry.topLeft();
342 topLeft.setX(corner == Qt::TopLeftCorner || corner == Qt::BottomLeftCorner ?
344 qMax(availableGeometry.right() - size.width() - xOffset, availableGeometry.left()));
347 topLeft.setY(corner == Qt::TopLeftCorner || corner == Qt::TopRightCorner ?
349 qMax(availableGeometry.bottom() - size.height() - yOffset, availableGeometry.top()));
351 window->setFramePosition(topLeft);
358
359
360
361
362
363
364
365
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
645QGuiApplication::QGuiApplication(
int &argc,
char **argv)
647QGuiApplication::QGuiApplication(
int &argc,
char **argv,
int)
649 : QCoreApplication(*
new QGuiApplicationPrivate(argc, argv))
653 QCoreApplicationPrivate::eventDispatcher->startingUp();
657
658
659QGuiApplication::QGuiApplication(QGuiApplicationPrivate &p)
660 : QCoreApplication(p)
665
666
667QGuiApplication::~QGuiApplication()
669 Q_D(QGuiApplication);
671 qt_call_post_routines();
673 d->eventDispatcher->closingDown();
674 d->eventDispatcher =
nullptr;
676#ifndef QT_NO_CLIPBOARD
677 delete QGuiApplicationPrivate::qt_clipboard;
678 QGuiApplicationPrivate::qt_clipboard =
nullptr;
681#ifndef QT_NO_SESSIONMANAGER
682 delete d->session_manager;
683 d->session_manager =
nullptr;
686 QGuiApplicationPrivate::clearPalette();
687 QFontDatabase::removeAllApplicationFonts();
690 d->cursor_list.clear();
693#if QT_CONFIG(qtgui_threadpool)
695 QThreadPool *guiThreadPool =
nullptr;
697 guiThreadPool = QGuiApplicationPrivate::qtGuiThreadPool();
702 guiThreadPool->waitForDone();
703 delete guiThreadPool;
707 delete QGuiApplicationPrivate::app_icon;
708 QGuiApplicationPrivate::app_icon =
nullptr;
709 delete QGuiApplicationPrivate::platform_name;
710 QGuiApplicationPrivate::platform_name =
nullptr;
711 delete QGuiApplicationPrivate::displayName;
712 QGuiApplicationPrivate::displayName =
nullptr;
713 delete QGuiApplicationPrivate::m_inputDeviceManager;
714 QGuiApplicationPrivate::m_inputDeviceManager =
nullptr;
715 delete QGuiApplicationPrivate::desktopFileName;
716 QGuiApplicationPrivate::desktopFileName =
nullptr;
717 QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
718 QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier;
719 QGuiApplicationPrivate::lastCursorPosition.reset();
720 QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow =
nullptr;
721 QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
722 QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy = Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
723 QGuiApplicationPrivate::currentDragWindow =
nullptr;
724 QGuiApplicationPrivate::tabletDevicePoints.clear();
727QGuiApplicationPrivate::QGuiApplicationPrivate(
int &argc,
char **argv)
728 : QCoreApplicationPrivate(argc, argv),
729 inputMethod(
nullptr),
730 lastTouchType(QEvent::TouchEnd),
731 ownGlobalShareContext(
false)
734 application_type = QCoreApplicationPrivate::Gui;
735#ifndef QT_NO_SESSIONMANAGER
736 is_session_restored =
false;
737 is_saving_session =
false;
742
743
744
745
746
747
748
749
750
751
752
753void QGuiApplication::setApplicationDisplayName(
const QString &name)
755 if (!QGuiApplicationPrivate::displayName) {
756 QGuiApplicationPrivate::displayName =
new QString(name);
758 disconnect(
qGuiApp, &QGuiApplication::applicationNameChanged,
759 qGuiApp, &QGuiApplication::applicationDisplayNameChanged);
761 if (*QGuiApplicationPrivate::displayName != applicationName())
762 emit
qGuiApp->applicationDisplayNameChanged();
764 }
else if (name != *QGuiApplicationPrivate::displayName) {
765 *QGuiApplicationPrivate::displayName = name;
767 emit
qGuiApp->applicationDisplayNameChanged();
771QString QGuiApplication::applicationDisplayName()
773 return QGuiApplicationPrivate::displayName ? *QGuiApplicationPrivate::displayName : applicationName();
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795void QGuiApplication::setBadgeNumber(qint64 number)
797 QGuiApplicationPrivate::platformIntegration()->setApplicationBadge(number);
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816void QGuiApplication::setDesktopFileName(
const QString &name)
818 if (!QGuiApplicationPrivate::desktopFileName)
819 QGuiApplicationPrivate::desktopFileName =
new QString;
820 *QGuiApplicationPrivate::desktopFileName = name;
821 if (name.endsWith(QLatin1String(
".desktop"))) {
822 const QString filePath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, name);
823 if (!filePath.isEmpty()) {
824 qWarning(
"QGuiApplication::setDesktopFileName: the specified desktop file name "
825 "ends with .desktop. For compatibility reasons, the .desktop suffix will "
826 "be removed. Please specify a desktop file name without .desktop suffix");
827 (*QGuiApplicationPrivate::desktopFileName).chop(8);
832QString QGuiApplication::desktopFileName()
834 return QGuiApplicationPrivate::desktopFileName ? *QGuiApplicationPrivate::desktopFileName : QString();
838
839
840
841
842
843
844
845
846
847
848
849
850
851QWindow *QGuiApplication::modalWindow()
854 if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
856 return QGuiApplicationPrivate::self->modalWindowList.constFirst();
861 QWindowPrivate *p = qt_window_private(window);
862 if (p->blockedByModalWindow != shouldBeBlocked) {
863 p->blockedByModalWindow = shouldBeBlocked;
864 QEvent e(shouldBeBlocked ? QEvent::WindowBlocked : QEvent::WindowUnblocked);
865 QGuiApplication::sendEvent(window, &e);
866 for (QObject *c : window->children()) {
867 if (c->isWindowType())
868 updateBlockedStatusRecursion(
static_cast<QWindow *>(c), shouldBeBlocked);
873void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
875 bool shouldBeBlocked =
false;
876 const bool popupType = (window->type() == Qt::ToolTip) || (window->type() == Qt::Popup);
877 if (!popupType && !self->modalWindowList.isEmpty())
878 shouldBeBlocked = self->isWindowBlocked(window);
879 updateBlockedStatusRecursion(window, shouldBeBlocked);
887 return w->isTopLevel() && w->type() != Qt::Desktop;
890void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
892 self->modalWindowList.prepend(modal);
895 if (currentMouseWindow && !QWindowPrivate::get(currentMouseWindow)->isPopup()) {
896 bool shouldBeBlocked = self->isWindowBlocked(currentMouseWindow);
897 if (shouldBeBlocked) {
899 self->modalWindowList.removeFirst();
900 QEvent e(QEvent::Leave);
901 QGuiApplication::sendEvent(currentMouseWindow, &e);
902 currentMouseWindow =
nullptr;
903 self->modalWindowList.prepend(modal);
907 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
908 if (needsWindowBlockedEvent(window) && !window->d_func()->blockedByModalWindow)
909 updateBlockedStatus(window);
912 updateBlockedStatus(modal);
915void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
917 self->modalWindowList.removeAll(window);
919 for (QWindow *window : std::as_const(QGuiApplicationPrivate::window_list)) {
920 if (needsWindowBlockedEvent(window) && window->d_func()->blockedByModalWindow)
921 updateBlockedStatus(window);
925Qt::WindowModality QGuiApplicationPrivate::defaultModality()
const
930bool QGuiApplicationPrivate::windowNeverBlocked(QWindow *window)
const
937
938
939
940
941bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow)
const
943 Q_ASSERT_X(window, Q_FUNC_INFO,
"The window must not be null");
945 QWindow *unused =
nullptr;
947 blockingWindow = &unused;
948 *blockingWindow =
nullptr;
950 if (modalWindowList.isEmpty() || windowNeverBlocked(window))
953 for (
int i = 0; i < modalWindowList.size(); ++i) {
954 QWindow *modalWindow = modalWindowList.at(i);
958 if (window == modalWindow || modalWindow->isAncestorOf(window, QWindow::IncludeTransients))
961 switch (modalWindow->modality() == Qt::NonModal ? defaultModality()
962 : modalWindow->modality()) {
963 case Qt::ApplicationModal:
964 *blockingWindow = modalWindow;
966 case Qt::WindowModal: {
969 auto *current = window;
971 if (current->isAncestorOf(modalWindow, QWindow::IncludeTransients)) {
972 *blockingWindow = modalWindow;
975 current = current->parent(QWindow::IncludeTransients);
980 Q_ASSERT_X(
false,
"QGuiApplication",
"internal error, a modal widget cannot be modeless");
987QWindow *QGuiApplicationPrivate::activePopupWindow()
990 return QGuiApplicationPrivate::popup_list.isEmpty() ?
991 nullptr : QGuiApplicationPrivate::popup_list.constLast();
994void QGuiApplicationPrivate::activatePopup(QWindow *popup)
996 if (!popup->isVisible())
998 popup_list.removeOne(popup);
999 qCDebug(lcPopup) <<
"appending popup" << popup <<
"to existing" << popup_list;
1000 popup_list.append(popup);
1003bool QGuiApplicationPrivate::closePopup(QWindow *popup)
1005 const auto removed = QGuiApplicationPrivate::popup_list.removeAll(popup);
1006 qCDebug(lcPopup) <<
"removed?" << removed <<
"popup" << popup <<
"; remaining" << popup_list;
1011
1012
1013bool QGuiApplicationPrivate::closeAllPopups()
1019 while ((popup = activePopupWindow()) && maxiter--)
1021 return QGuiApplicationPrivate::popup_list.isEmpty();
1025
1026
1027
1028
1029
1030QWindow *QGuiApplication::focusWindow()
1032 return QGuiApplicationPrivate::focus_window;
1036
1037
1038
1039
1040
1041
1042
1045
1046
1047
1048
1049
1050
1051
1054
1055
1056
1057QObject *QGuiApplication::focusObject()
1060 return focusWindow()->focusObject();
1065
1066
1067
1068
1069
1070
1071
1072
1073QWindowList QGuiApplication::allWindows()
1075 return QGuiApplicationPrivate::window_list;
1079
1080
1081
1082
1083
1084
1085QWindowList QGuiApplication::topLevelWindows()
1087 const QWindowList &list = QGuiApplicationPrivate::window_list;
1088 QWindowList topLevelWindows;
1089 for (
int i = 0; i < list.size(); ++i) {
1090 QWindow *window = list.at(i);
1091 if (!window->isTopLevel())
1097 if (window->type() == Qt::Desktop)
1102 if (window->handle() && window->handle()->isEmbedded())
1105 topLevelWindows.prepend(window);
1108 return topLevelWindows;
1111QScreen *QGuiApplication::primaryScreen()
1113 if (QGuiApplicationPrivate::screen_list.isEmpty())
1115 return QGuiApplicationPrivate::screen_list.at(0);
1119
1120
1121
1122QList<QScreen *> QGuiApplication::screens()
1124 return QGuiApplicationPrivate::screen_list;
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138QScreen *QGuiApplication::screenAt(
const QPoint &point)
1140 QVarLengthArray<
const QScreen *, 8> visitedScreens;
1141 for (
const QScreen *screen : QGuiApplication::screens()) {
1142 if (visitedScreens.contains(screen))
1146 for (QScreen *sibling : screen->virtualSiblings()) {
1147 if (sibling->geometry().contains(point))
1150 visitedScreens.append(sibling);
1158
1159
1160
1161
1162
1163
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200qreal QGuiApplication::devicePixelRatio()
const
1202 if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
1203 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1205 QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0;
1206 for (QScreen *screen : std::as_const(QGuiApplicationPrivate::screen_list))
1207 QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
1209 return QGuiApplicationPrivate::m_maxDevicePixelRatio;
1212void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
1214 m_maxDevicePixelRatio = 0.0;
1218
1219
1220QWindow *QGuiApplication::topLevelAt(
const QPoint &pos)
1222 if (QScreen *windowScreen = screenAt(pos)) {
1223 const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
1224 return windowScreen->handle()->topLevelAt(devicePosition);
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1266QString QGuiApplication::platformName()
1268 if (!QGuiApplication::instance()) {
1269#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1270 return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME);
1275 return QGuiApplicationPrivate::platform_name ?
1276 *QGuiApplicationPrivate::platform_name : QString();
1284static void init_platform(
const QString &pluginNamesWithArguments,
const QString &platformPluginPath,
const QString &platformThemeName,
int &argc,
char **argv)
1286 qCDebug(lcQpaPluginLoading) <<
"init_platform called with"
1287 <<
"pluginNamesWithArguments" << pluginNamesWithArguments
1288 <<
"platformPluginPath" << platformPluginPath
1289 <<
"platformThemeName" << platformThemeName;
1291 QStringList plugins = pluginNamesWithArguments.split(u';', Qt::SkipEmptyParts);
1292 QStringList platformArguments;
1293 QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath);
1294 for (
const auto &pluginArgument : plugins) {
1296 QStringList arguments = pluginArgument.split(u':', Qt::SkipEmptyParts);
1297 if (arguments.isEmpty())
1299 const QString name = arguments.takeFirst().toLower();
1300 QString argumentsKey = name;
1303 argumentsKey[0] = argumentsKey.at(0).toUpper();
1304 arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey));
1306 qCDebug(lcQpaPluginLoading) <<
"Attempting to load Qt platform plugin" << name <<
"with arguments" << arguments;
1309 QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
1310 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1311 if (availablePlugins.contains(name)) {
1312 if (name == QStringLiteral(
"xcb") && QVersionNumber::compare(QLibraryInfo::version(), QVersionNumber(6, 5, 0)) >= 0) {
1313 qCWarning(lcQpaPluginLoading).nospace().noquote()
1314 <<
"From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.";
1316 qCInfo(lcQpaPluginLoading).nospace().noquote()
1317 <<
"Could not load the Qt platform plugin \"" << name <<
"\" in \""
1318 << QDir::toNativeSeparators(platformPluginPath) <<
"\" even though it was found.";
1320 qCWarning(lcQpaPluginLoading).nospace().noquote()
1321 <<
"Could not find the Qt platform plugin \"" << name <<
"\" in \""
1322 << QDir::toNativeSeparators(platformPluginPath) <<
"\"";
1325 qCDebug(lcQpaPluginLoading) <<
"Successfully loaded Qt platform plugin" << name;
1326 QGuiApplicationPrivate::platform_name =
new QString(name);
1327 platformArguments = arguments;
1332 if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
1333 QString fatalMessage = QStringLiteral(
"This application failed to start because no Qt platform plugin could be initialized. "
1334 "Reinstalling the application may fix this problem.\n");
1336 if (!availablePlugins.isEmpty())
1337 fatalMessage +=
"\nAvailable platform plugins are: %1.\n"_L1.arg(availablePlugins.join(
", "_L1));
1339#if defined(Q_OS_WIN)
1342 if (!QLibraryInfo::isDebugBuild() && !GetConsoleWindow())
1343 MessageBox(0, (LPCTSTR)fatalMessage.utf16(), (LPCTSTR)(QCoreApplication::applicationName().utf16()), MB_OK | MB_ICONERROR);
1345 qFatal(
"%s", qPrintable(fatalMessage));
1353 QStringList themeNames;
1354 if (!platformThemeName.isEmpty()) {
1355 qCDebug(lcQpaTheme) <<
"Adding" << platformThemeName <<
"from environment to list of theme names";
1356 themeNames.append(platformThemeName);
1361 qCDebug(lcQpaTheme) <<
"Adding xdgdesktopportal to list of theme names";
1362 themeNames.append(QStringLiteral(
"xdgdesktopportal"));
1366 const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames();
1367 qCDebug(lcQpaTheme) <<
"Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames;
1368 themeNames += platformIntegrationThemeNames;
1370 for (
const QString &themeName : std::as_const(themeNames)) {
1371 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via QPlatformThemeFactory::create";
1372 QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath);
1373 if (QGuiApplicationPrivate::platform_theme) {
1374 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName;
1381 if (!QGuiApplicationPrivate::platform_theme) {
1382 for (
const QString &themeName : std::as_const(themeNames)) {
1383 qCDebug(lcQpaTheme) <<
"Attempting to create platform theme" << themeName <<
"via createPlatformTheme";
1384 QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
1385 if (QGuiApplicationPrivate::platform_theme) {
1386 qCDebug(lcQpaTheme) <<
"Successfully created platform theme" << themeName;
1394 if (!QGuiApplicationPrivate::platform_theme) {
1395 qCDebug(lcQpaTheme) <<
"Failed to create platform theme; using \"null\" platform theme";
1396 QGuiApplicationPrivate::platform_theme =
new QPlatformTheme;
1401 if (!platformArguments.isEmpty()) {
1402 if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
1403 for (
const QString &argument : std::as_const(platformArguments)) {
1404 const qsizetype equalsPos = argument.indexOf(u'=');
1405 const QByteArray name =
1406 equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
1407 const QVariant value =
1408 equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(
true);
1409 nativeInterface->setProperty(name.constData(), value);
1414 const auto platformIntegration = QGuiApplicationPrivate::platformIntegration();
1415 fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
1416 QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
1417 !QGuiApplication::styleHints()->showShortcutsInContextMenus());
1419 if (
const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
1420 QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus,
1421 !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool());
1427 for (
int i = 0; i < pluginList.size(); ++i) {
1428 QByteArray pluginSpec = pluginList.at(i);
1429 qsizetype colonPos = pluginSpec.indexOf(
':');
1432 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
1434 plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec.mid(0, colonPos)),
1435 QLatin1StringView(pluginSpec.mid(colonPos+1)));
1437 QGuiApplicationPrivate::generic_plugin_list.append(plugin);
1439 qWarning(
"No such plugin for spec \"%s\"", pluginSpec.constData());
1443#if QT_CONFIG(commandlineparser)
1444void QGuiApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
1446 QCoreApplicationPrivate::addQtOptions(options);
1448#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1449 const QByteArray sessionType = qgetenv(
"XDG_SESSION_TYPE");
1450 const bool x11 = sessionType ==
"x11";
1453 const bool x11 =
false;
1456 options->append(QCommandLineOption(QStringLiteral(
"platform"),
1457 QGuiApplication::tr(
"QPA plugin. See QGuiApplication documentation for available options for each plugin."), QStringLiteral(
"platformName[:options]")));
1458 options->append(QCommandLineOption(QStringLiteral(
"platformpluginpath"),
1459 QGuiApplication::tr(
"Path to the platform plugins."), QStringLiteral(
"path")));
1460 options->append(QCommandLineOption(QStringLiteral(
"platformtheme"),
1461 QGuiApplication::tr(
"Platform theme."), QStringLiteral(
"theme")));
1462 options->append(QCommandLineOption(QStringLiteral(
"plugin"),
1463 QGuiApplication::tr(
"Additional plugins to load, can be specified multiple times."), QStringLiteral(
"plugin")));
1464 options->append(QCommandLineOption(QStringLiteral(
"qwindowgeometry"),
1465 QGuiApplication::tr(
"Window geometry for the main window, using the X11-syntax, like 100x100+50+50."), QStringLiteral(
"geometry")));
1466 options->append(QCommandLineOption(QStringLiteral(
"qwindowicon"),
1467 QGuiApplication::tr(
"Default window icon."), QStringLiteral(
"icon")));
1468 options->append(QCommandLineOption(QStringLiteral(
"qwindowtitle"),
1469 QGuiApplication::tr(
"Title of the first window."), QStringLiteral(
"title")));
1470 options->append(QCommandLineOption(QStringLiteral(
"reverse"),
1471 QGuiApplication::tr(
"Sets the application's layout direction to Qt::RightToLeft (debugging helper).")));
1472 options->append(QCommandLineOption(QStringLiteral(
"session"),
1473 QGuiApplication::tr(
"Restores the application from an earlier session."), QStringLiteral(
"session")));
1476 options->append(QCommandLineOption(QStringLiteral(
"display"),
1477 QGuiApplication::tr(
"Display name, overrides $DISPLAY."), QStringLiteral(
"display")));
1478 options->append(QCommandLineOption(QStringLiteral(
"name"),
1479 QGuiApplication::tr(
"Instance name according to ICCCM 4.1.2.5."), QStringLiteral(
"name")));
1480 options->append(QCommandLineOption(QStringLiteral(
"nograb"),
1481 QGuiApplication::tr(
"Disable mouse grabbing (useful in debuggers).")));
1482 options->append(QCommandLineOption(QStringLiteral(
"dograb"),
1483 QGuiApplication::tr(
"Force mouse grabbing (even when running in a debugger).")));
1484 options->append(QCommandLineOption(QStringLiteral(
"visual"),
1485 QGuiApplication::tr(
"ID of the X11 Visual to use."), QStringLiteral(
"id")));
1487 options->append(QCommandLineOption(QStringLiteral(
"geometry"),
1488 QGuiApplication::tr(
"Alias for --qwindowgeometry."), QStringLiteral(
"geometry")));
1489 options->append(QCommandLineOption(QStringLiteral(
"icon"),
1490 QGuiApplication::tr(
"Alias for --qwindowicon."), QStringLiteral(
"icon")));
1491 options->append(QCommandLineOption(QStringLiteral(
"title"),
1492 QGuiApplication::tr(
"Alias for --qwindowtitle."), QStringLiteral(
"title")));
1497void QGuiApplicationPrivate::createPlatformIntegration()
1499 QHighDpiScaling::initHighDpiScaling();
1502 QString platformPluginPath = qEnvironmentVariable(
"QT_QPA_PLATFORM_PLUGIN_PATH");
1505 QByteArray platformName;
1506#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
1507 platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
1509#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
1510 QList<QByteArray> platformArguments = platformName.split(
':');
1511 QByteArray platformPluginBase = platformArguments.first();
1513 const bool hasWaylandDisplay = qEnvironmentVariableIsSet(
"WAYLAND_DISPLAY");
1514 const bool isWaylandSessionType = qgetenv(
"XDG_SESSION_TYPE") ==
"wayland";
1516 QVector<QByteArray> preferredPlatformOrder;
1517 const bool defaultIsXcb = platformPluginBase ==
"xcb";
1518 const QByteArray xcbPlatformName = defaultIsXcb ? platformName :
"xcb";
1519 if (qEnvironmentVariableIsSet(
"DISPLAY")) {
1520 preferredPlatformOrder << xcbPlatformName;
1522 platformName.clear();
1525 const bool defaultIsWayland = !defaultIsXcb && platformPluginBase.startsWith(
"wayland");
1526 const QByteArray waylandPlatformName = defaultIsWayland ? platformName :
"wayland";
1527 if (hasWaylandDisplay || isWaylandSessionType) {
1528 preferredPlatformOrder.prepend(waylandPlatformName);
1530 if (defaultIsWayland)
1531 platformName.clear();
1534 if (!platformName.isEmpty())
1535 preferredPlatformOrder.append(platformName);
1537 platformName = preferredPlatformOrder.join(
';');
1540 bool platformExplicitlySelected =
false;
1541 QByteArray platformNameEnv = qgetenv(
"QT_QPA_PLATFORM");
1542 if (!platformNameEnv.isEmpty()) {
1543 platformName = platformNameEnv;
1544 platformExplicitlySelected =
true;
1547 QString platformThemeName = QString::fromLocal8Bit(qgetenv(
"QT_QPA_PLATFORMTHEME"));
1553 int j = argc ? 1 : 0;
1554 for (
int i=1; i<argc; i++) {
1557 if (*argv[i] !=
'-') {
1558 argv[j++] = argv[i];
1561 const bool xcbIsDefault = platformName.startsWith(
"xcb");
1562 const char *arg = argv[i];
1565 if (strcmp(arg,
"-platformpluginpath") == 0) {
1567 platformPluginPath = QFile::decodeName(argv[i]);
1568 }
else if (strcmp(arg,
"-platform") == 0) {
1570 platformExplicitlySelected =
true;
1571 platformName = argv[i];
1573 }
else if (strcmp(arg,
"-platformtheme") == 0) {
1575 platformThemeName = QString::fromLocal8Bit(argv[i]);
1576 }
else if (strcmp(arg,
"-qwindowgeometry") == 0 || (xcbIsDefault && strcmp(arg,
"-geometry") == 0)) {
1578 windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]);
1579 }
else if (strcmp(arg,
"-qwindowtitle") == 0 || (xcbIsDefault && strcmp(arg,
"-title") == 0)) {
1581 firstWindowTitle = QString::fromLocal8Bit(argv[i]);
1582 }
else if (strcmp(arg,
"-qwindowicon") == 0 || (xcbIsDefault && strcmp(arg,
"-icon") == 0)) {
1584 icon = QFile::decodeName(argv[i]);
1587 argv[j++] = argv[i];
1596 Q_UNUSED(platformExplicitlySelected);
1598 init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
1599 if (
const QPlatformTheme *theme = platformTheme())
1600 QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(theme->colorScheme());
1602 if (!icon.isEmpty())
1603 forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
1607
1608
1609
1610
1611
1612void QGuiApplicationPrivate::createEventDispatcher()
1614 Q_ASSERT(!eventDispatcher);
1616 if (platform_integration ==
nullptr)
1617 createPlatformIntegration();
1620 Q_ASSERT_X(!threadData.loadRelaxed()->eventDispatcher,
"QGuiApplication",
1621 "Creating the platform integration resulted in creating an event dispatcher");
1624 Q_ASSERT(!eventDispatcher);
1626 eventDispatcher = platform_integration->createEventDispatcher();
1629void QGuiApplicationPrivate::eventDispatcherReady()
1631 if (platform_integration ==
nullptr)
1632 createPlatformIntegration();
1634 platform_integration->initialize();
1637void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
1639 Q_TRACE_SCOPE(QGuiApplicationPrivate_init);
1641#if defined(Q_OS_MACOS)
1642 QMacAutoReleasePool pool;
1645 QCoreApplicationPrivate::init();
1647 QCoreApplicationPrivate::is_app_running =
false;
1649 bool loadTestability =
false;
1650 QList<QByteArray> pluginList;
1652#ifndef QT_NO_SESSIONMANAGER
1654 QString session_key;
1655# if defined(Q_OS_WIN)
1656 wchar_t guidstr[40];
1658 CoCreateGuid(&guid);
1659 StringFromGUID2(guid, guidstr, 40);
1660 session_id = QString::fromWCharArray(guidstr);
1661 CoCreateGuid(&guid);
1662 StringFromGUID2(guid, guidstr, 40);
1663 session_key = QString::fromWCharArray(guidstr);
1667 int j = argc ? 1 : 0;
1668 for (
int i=1; i<argc; i++) {
1671 if (*argv[i] !=
'-') {
1672 argv[j++] = argv[i];
1675 const char *arg = argv[i];
1678 if (strcmp(arg,
"-plugin") == 0) {
1680 pluginList << argv[i];
1681 }
else if (strcmp(arg,
"-reverse") == 0) {
1682 force_reverse =
true;
1684 }
else if (strncmp(arg,
"-psn_", 5) == 0) {
1687 if (QDir::currentPath() ==
"/"_L1) {
1688 QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
1689 QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
1690 kCFURLPOSIXPathStyle));
1691 if (qbundlePath.endsWith(
".app"_L1))
1692 QDir::setCurrent(qbundlePath.section(u'/', 0, -2));
1695#ifndef QT_NO_SESSIONMANAGER
1696 }
else if (strcmp(arg,
"-session") == 0 && i < argc - 1) {
1698 if (argv[i] && *argv[i]) {
1699 session_id = QString::fromLatin1(argv[i]);
1700 qsizetype p = session_id.indexOf(u'_');
1702 session_key = session_id.mid(p +1);
1703 session_id = session_id.left(p);
1705 is_session_restored =
true;
1708 }
else if (strcmp(arg,
"-testability") == 0) {
1709 loadTestability =
true;
1710 }
else if (strncmp(arg,
"-style=", 7) == 0) {
1711 s = QString::fromLocal8Bit(arg + 7);
1712 }
else if (strcmp(arg,
"-style") == 0 && i < argc - 1) {
1713 s = QString::fromLocal8Bit(argv[++i]);
1715 argv[j++] = argv[i];
1728 QByteArray envPlugins = qgetenv(
"QT_QPA_GENERIC_PLUGINS");
1729 if (!envPlugins.isEmpty())
1730 pluginList += envPlugins.split(
',');
1732 if (platform_integration ==
nullptr)
1733 createPlatformIntegration();
1736 QFont::initialize();
1740 QCursorData::initialize();
1744 qRegisterGuiVariant();
1746#if QT_CONFIG(animation)
1748 qRegisterGuiGetInterpolator();
1753 if (
qApp->testAttribute(Qt::AA_ShareOpenGLContexts) && !qt_gl_global_share_context()) {
1754 QOpenGLContext *ctx =
new QOpenGLContext;
1755 ctx->setFormat(QSurfaceFormat::defaultFormat());
1757 qt_gl_set_global_share_context(ctx);
1758 ownGlobalShareContext =
true;
1762 QWindowSystemInterfacePrivate::eventTime.start();
1764 is_app_running =
true;
1765 init_plugins(pluginList);
1766 QWindowSystemInterface::flushWindowSystemEvents();
1768 Q_Q(QGuiApplication);
1769#ifndef QT_NO_SESSIONMANAGER
1771 session_manager =
new QSessionManager(q, session_id, session_key);
1774#if QT_CONFIG(library)
1775 if (qEnvironmentVariableIntValue(
"QT_LOAD_TESTABILITY") > 0)
1776 loadTestability =
true;
1778 if (loadTestability) {
1779 QLibrary testLib(QStringLiteral(
"qttestability"));
1780 if (Q_UNLIKELY(!testLib.load())) {
1781 qCritical() <<
"Library qttestability load failed:" << testLib.errorString();
1783 typedef void (*TasInitialize)(
void);
1784 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
1785 if (Q_UNLIKELY(!initFunction)) {
1786 qCritical(
"Library qttestability resolve failed!");
1793 Q_UNUSED(loadTestability);
1797 QGuiApplication::setLayoutDirection(layout_direction);
1799 if (!QGuiApplicationPrivate::displayName)
1800 QObject::connect(q, &QGuiApplication::applicationNameChanged,
1801 q, &QGuiApplication::applicationDisplayNameChanged);
1804extern void qt_cleanupFontDatabase();
1806QGuiApplicationPrivate::~QGuiApplicationPrivate()
1808 is_app_closing =
true;
1809 is_app_running =
false;
1811 for (
int i = 0; i < generic_plugin_list.size(); ++i)
1812 delete generic_plugin_list.at(i);
1813 generic_plugin_list.clear();
1815 clearFontUnlocked();
1820 QCursorData::cleanup();
1823 layout_direction = Qt::LayoutDirectionAuto;
1825 cleanupThreadData();
1827 delete QGuiApplicationPrivate::styleHints;
1828 QGuiApplicationPrivate::styleHints =
nullptr;
1831 qt_cleanupFontDatabase();
1833 QPixmapCache::clear();
1836 if (ownGlobalShareContext) {
1837 delete qt_gl_global_share_context();
1838 qt_gl_set_global_share_context(
nullptr);
1842#if QT_CONFIG(vulkan)
1843 QVulkanDefaultInstance::cleanup();
1846 platform_integration->destroy();
1848 delete platform_theme;
1849 platform_theme =
nullptr;
1850 delete platform_integration;
1851 platform_integration =
nullptr;
1853 window_list.clear();
1855 screen_list.clear();
1862QCursor *overrideCursor();
1863void setOverrideCursor(
const QCursor &);
1864void changeOverrideCursor(
const QCursor &);
1865void restoreOverrideCursor();
1869static QFont font(
const QWidget*);
1870static QFont font(
const char *className);
1871static void setFont(
const QFont &,
const char *className =
nullptr);
1872static QFontMetrics fontMetrics();
1874#ifndef QT_NO_CLIPBOARD
1875static QClipboard *clipboard();
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
1894 return QGuiApplicationPrivate::modifier_buttons;
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
1916 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1917 return pi->keyMapper()->queryKeyboardModifiers();
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933Qt::MouseButtons QGuiApplication::mouseButtons()
1935 return QGuiApplicationPrivate::mouse_buttons;
1939
1940
1941
1942
1943QPlatformNativeInterface *QGuiApplication::platformNativeInterface()
1945 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1946 return pi ? pi->nativeInterface() :
nullptr;
1950
1951
1952
1953QFunctionPointer QGuiApplication::platformFunction(
const QByteArray &function)
1955 QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
1957 qWarning(
"QGuiApplication::platformFunction(): Must construct a QGuiApplication before accessing a platform function");
1961 return pi->nativeInterface() ? pi->nativeInterface()->platformFunction(function) :
nullptr;
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988int QGuiApplication::exec()
1990#if QT_CONFIG(accessibility)
1991 QAccessible::setRootObject(qApp);
1993 return QCoreApplication::exec();
1996void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e)
1998 if (e->spontaneous()) {
2006 switch (e->type()) {
2007 case QEvent::MouseButtonPress: {
2008 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2009 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2010 QGuiApplicationPrivate::mouse_buttons |= me->button();
2013 case QEvent::MouseButtonDblClick: {
2014 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2015 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2016 QGuiApplicationPrivate::mouse_buttons |= me->button();
2019 case QEvent::MouseButtonRelease: {
2020 QMouseEvent *me =
static_cast<QMouseEvent *>(e);
2021 QGuiApplicationPrivate::modifier_buttons = me->modifiers();
2022 QGuiApplicationPrivate::mouse_buttons &= ~me->button();
2025 case QEvent::KeyPress:
2026 case QEvent::KeyRelease:
2027 case QEvent::MouseMove:
2028#if QT_CONFIG(wheelevent)
2031 case QEvent::TouchBegin:
2032 case QEvent::TouchUpdate:
2033 case QEvent::TouchEnd:
2034#if QT_CONFIG(tabletevent)
2035 case QEvent::TabletMove:
2036 case QEvent::TabletPress:
2037 case QEvent::TabletRelease:
2040 QInputEvent *ie =
static_cast<QInputEvent *>(e);
2041 QGuiApplicationPrivate::modifier_buttons = ie->modifiers();
2051
2052bool QGuiApplication::notify(QObject *object, QEvent *event)
2054 Q_D(QGuiApplication);
2055 if (object->isWindowType()) {
2056 if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(
static_cast<QWindow *>(object), event))
2060 switch (event->type()) {
2061 case QEvent::ApplicationDeactivate:
2062 case QEvent::OrientationChange:
2068 d->closeAllPopups();
2074 QGuiApplicationPrivate::captureGlobalModifierState(event);
2076 return QCoreApplication::notify(object, event);
2080
2081bool QGuiApplication::event(QEvent *e)
2083 switch (e->type()) {
2084 case QEvent::LanguageChange:
2086 if (layout_direction == Qt::LayoutDirectionAuto)
2087 setLayoutDirection(layout_direction);
2088 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
2089 if (topLevelWindow->flags() != Qt::Desktop)
2090 postEvent(topLevelWindow,
new QEvent(QEvent::LanguageChange));
2093 case QEvent::ApplicationFontChange:
2094 case QEvent::ApplicationPaletteChange:
2095 for (
auto *topLevelWindow : QGuiApplication::topLevelWindows()) {
2096 if (topLevelWindow->flags() != Qt::Desktop)
2097 postEvent(topLevelWindow,
new QEvent(e->type()));
2100 case QEvent::ThemeChange:
2101 for (
auto *w : QGuiApplication::allWindows())
2107 for (QWindow *topLevelWindow : QGuiApplication::topLevelWindows()) {
2109 if (!topLevelWindow->handle())
2111 if (!topLevelWindow->close()) {
2120 return QCoreApplication::event(e);
2123#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2125
2126
2127bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
2129 return QCoreApplication::compressEvent(event, receiver, postedEvents);
2133bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
2137 QPlatformWindow *platformWindow = window->handle();
2138 if (!platformWindow)
2141 if (event->spontaneous())
2144 return platformWindow->windowEvent(event);
2147bool QGuiApplicationPrivate::processNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
2149 return window->nativeEvent(eventType, message, result);
2152bool QGuiApplicationPrivate::isUsingVirtualKeyboard()
2154 static const bool usingVirtualKeyboard = getenv(
"QT_IM_MODULE") == QByteArray(
"qtvirtualkeyboard");
2155 return usingVirtualKeyboard;
2159bool QGuiApplicationPrivate::maybeForwardEventToVirtualKeyboard(QEvent *e)
2161 if (!isUsingVirtualKeyboard()) {
2162 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard not supported.";
2166 static QPointer<QWindow> virtualKeyboard;
2167 const QEvent::Type type = e->type();
2168 Q_ASSERT(type == QEvent::MouseButtonPress || type == QEvent::MouseButtonRelease);
2169 const auto me =
static_cast<QMouseEvent *>(e);
2170 const QPointF posF = me->globalPosition();
2171 const QPoint pos = posF.toPoint();
2174 if (!virtualKeyboard) {
2175 if (QWindow *win = QGuiApplication::topLevelAt(pos);
2176 win->inherits(
"QtVirtualKeyboard::InputView")) {
2177 virtualKeyboard = win;
2179 qCDebug(lcVirtualKeyboard) <<
"Virtual keyboard supported, but inactive.";
2184 Q_ASSERT(virtualKeyboard);
2185 const bool virtualKeyboardUnderMouse = virtualKeyboard->isVisible()
2186 && virtualKeyboard->geometry().contains(pos);
2188 if (!virtualKeyboardUnderMouse) {
2189 qCDebug(lcVirtualKeyboard) << type <<
"at" << pos <<
"is outside geometry"
2190 << virtualKeyboard->geometry() <<
"of" << virtualKeyboard.data();
2194 QMouseEvent vkbEvent(type, virtualKeyboard->mapFromGlobal(pos), pos,
2195 me->button(), me->buttons(), me->modifiers(),
2196 me->pointingDevice());
2198 QGuiApplication::sendEvent(virtualKeyboard, &vkbEvent);
2199 qCDebug(lcVirtualKeyboard) <<
"Forwarded" << type <<
"to" << virtualKeyboard.data()
2205void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
2207 Q_TRACE_PARAM_REPLACE(QWindowSystemInterfacePrivate::WindowSystemEvent *,
int);
2208 Q_TRACE_SCOPE(QGuiApplicationPrivate_processWindowSystemEvent, e->type);
2211 case QWindowSystemInterfacePrivate::Mouse:
2212 QGuiApplicationPrivate::processMouseEvent(
static_cast<QWindowSystemInterfacePrivate::MouseEvent *>(e));
2214 case QWindowSystemInterfacePrivate::Wheel:
2215 QGuiApplicationPrivate::processWheelEvent(
static_cast<QWindowSystemInterfacePrivate::WheelEvent *>(e));
2217 case QWindowSystemInterfacePrivate::Key:
2218 QGuiApplicationPrivate::processKeyEvent(
static_cast<QWindowSystemInterfacePrivate::KeyEvent *>(e));
2220 case QWindowSystemInterfacePrivate::Touch:
2221 QGuiApplicationPrivate::processTouchEvent(
static_cast<QWindowSystemInterfacePrivate::TouchEvent *>(e));
2223 case QWindowSystemInterfacePrivate::GeometryChange:
2224 QGuiApplicationPrivate::processGeometryChangeEvent(
static_cast<QWindowSystemInterfacePrivate::GeometryChangeEvent*>(e));
2226 case QWindowSystemInterfacePrivate::Enter:
2227 QGuiApplicationPrivate::processEnterEvent(
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>(e));
2229 case QWindowSystemInterfacePrivate::Leave:
2230 QGuiApplicationPrivate::processLeaveEvent(
static_cast<QWindowSystemInterfacePrivate::LeaveEvent *>(e));
2232 case QWindowSystemInterfacePrivate::FocusWindow:
2233 QGuiApplicationPrivate::processFocusWindowEvent(
static_cast<QWindowSystemInterfacePrivate::FocusWindowEvent *>(e));
2235 case QWindowSystemInterfacePrivate::WindowStateChanged:
2236 QGuiApplicationPrivate::processWindowStateChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowStateChangedEvent *>(e));
2238 case QWindowSystemInterfacePrivate::WindowScreenChanged:
2239 QGuiApplicationPrivate::processWindowScreenChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowScreenChangedEvent *>(e));
2241 case QWindowSystemInterfacePrivate::WindowDevicePixelRatioChanged:
2242 QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(
static_cast<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *>(e));
2244 case QWindowSystemInterfacePrivate::SafeAreaMarginsChanged:
2245 QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(
static_cast<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *>(e));
2247 case QWindowSystemInterfacePrivate::ApplicationStateChanged: {
2248 QWindowSystemInterfacePrivate::ApplicationStateChangedEvent * changeEvent =
static_cast<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent *>(e);
2249 QGuiApplicationPrivate::setApplicationState(changeEvent->newState, changeEvent->forcePropagate); }
2251 case QWindowSystemInterfacePrivate::ApplicationTermination:
2252 QGuiApplicationPrivate::processApplicationTermination(e);
2254 case QWindowSystemInterfacePrivate::FlushEvents: {
2255 QWindowSystemInterfacePrivate::FlushEventsEvent *flushEventsEvent =
static_cast<QWindowSystemInterfacePrivate::FlushEventsEvent *>(e);
2256 QWindowSystemInterface::deferredFlushWindowSystemEvents(flushEventsEvent->flags); }
2258 case QWindowSystemInterfacePrivate::Close:
2259 QGuiApplicationPrivate::processCloseEvent(
2260 static_cast<QWindowSystemInterfacePrivate::CloseEvent *>(e));
2262 case QWindowSystemInterfacePrivate::ScreenOrientation:
2263 QGuiApplicationPrivate::processScreenOrientationChange(
2264 static_cast<QWindowSystemInterfacePrivate::ScreenOrientationEvent *>(e));
2266 case QWindowSystemInterfacePrivate::ScreenGeometry:
2267 QGuiApplicationPrivate::processScreenGeometryChange(
2268 static_cast<QWindowSystemInterfacePrivate::ScreenGeometryEvent *>(e));
2270 case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch:
2271 QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(
2272 static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
2274 case QWindowSystemInterfacePrivate::ScreenRefreshRate:
2275 QGuiApplicationPrivate::processScreenRefreshRateChange(
2276 static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
2278 case QWindowSystemInterfacePrivate::ThemeChange:
2279 QGuiApplicationPrivate::processThemeChanged(
2280 static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
2282 case QWindowSystemInterfacePrivate::Expose:
2283 QGuiApplicationPrivate::processExposeEvent(
static_cast<QWindowSystemInterfacePrivate::ExposeEvent *>(e));
2285 case QWindowSystemInterfacePrivate::Paint:
2286 QGuiApplicationPrivate::processPaintEvent(
static_cast<QWindowSystemInterfacePrivate::PaintEvent *>(e));
2288 case QWindowSystemInterfacePrivate::Tablet:
2289 QGuiApplicationPrivate::processTabletEvent(
2290 static_cast<QWindowSystemInterfacePrivate::TabletEvent *>(e));
2292 case QWindowSystemInterfacePrivate::TabletEnterProximity:
2293 QGuiApplicationPrivate::processTabletEnterProximityEvent(
2294 static_cast<QWindowSystemInterfacePrivate::TabletEnterProximityEvent *>(e));
2296 case QWindowSystemInterfacePrivate::TabletLeaveProximity:
2297 QGuiApplicationPrivate::processTabletLeaveProximityEvent(
2298 static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
2300#ifndef QT_NO_GESTURES
2301 case QWindowSystemInterfacePrivate::Gesture:
2302 QGuiApplicationPrivate::processGestureEvent(
2303 static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
2306 case QWindowSystemInterfacePrivate::PlatformPanel:
2307 QGuiApplicationPrivate::processPlatformPanelEvent(
2308 static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
2310 case QWindowSystemInterfacePrivate::FileOpen:
2311 QGuiApplicationPrivate::processFileOpenEvent(
2312 static_cast<QWindowSystemInterfacePrivate::FileOpenEvent *>(e));
2314#ifndef QT_NO_CONTEXTMENU
2315 case QWindowSystemInterfacePrivate::ContextMenu:
2316 QGuiApplicationPrivate::processContextMenuEvent(
2317 static_cast<QWindowSystemInterfacePrivate::ContextMenuEvent *>(e));
2320 case QWindowSystemInterfacePrivate::EnterWhatsThisMode:
2321 QGuiApplication::postEvent(QGuiApplication::instance(),
new QEvent(QEvent::EnterWhatsThisMode));
2324 qWarning() <<
"Unknown user input event type:" << e->type;
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e)
2343 QEvent::Type type = QEvent::None;
2344 Qt::MouseButton button = Qt::NoButton;
2345 QWindow *window = e->window.data();
2346 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2348 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(
const_cast<QPointingDevice*>(device));
2349 bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos;
2350 bool mouseMove =
false;
2351 bool mousePress =
false;
2352 const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition;
2353 QPointF globalPoint = e->globalPos;
2355 if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) {
2356 qWarning(
"QGuiApplicationPrivate::processMouseEvent: Got NaN in mouse position");
2360 type = e->buttonType;
2363 if (type == QEvent::NonClientAreaMouseMove || type == QEvent::MouseMove)
2365 else if (type == QEvent::NonClientAreaMouseButtonPress || type == QEvent::MouseButtonPress)
2368 if (!mouseMove && positionChanged) {
2369 QWindowSystemInterfacePrivate::MouseEvent moveEvent(window, e->timestamp,
2370 e->localPos, e->globalPos, e->buttons ^ button, e->modifiers, Qt::NoButton,
2371 e->nonClientArea ? QEvent::NonClientAreaMouseMove : QEvent::MouseMove,
2372 e->source, e->nonClientArea, device, e->eventPointId);
2374 moveEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2375 processMouseEvent(&moveEvent);
2376 processMouseEvent(e);
2379 if (type == QEvent::MouseMove && !positionChanged) {
2387 modifier_buttons = e->modifiers;
2388 QPointF localPoint = e->localPos;
2389 bool doubleClick =
false;
2390 auto persistentEPD = devPriv->pointById(0);
2392 if (e->synthetic();
auto *originalDeviceEPD = devPriv->queryPointById(e->eventPointId))
2393 QMutableEventPoint::update(originalDeviceEPD->eventPoint, persistentEPD->eventPoint);
2396 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2397 const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
2398 mouseDoubleClickDistance : touchDoubleTapDistance);
2399 const auto pressPos = persistentEPD->eventPoint.globalPressPosition();
2400 if (qAbs(globalPoint.x() - pressPos.x()) > doubleClickDistance ||
2401 qAbs(globalPoint.y() - pressPos.y()) > doubleClickDistance)
2402 mousePressButton = Qt::NoButton;
2404 static unsigned long lastPressTimestamp = 0;
2405 mouse_buttons = e->buttons;
2407 ulong doubleClickInterval =
static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
2408 const auto timestampDelta = e->timestamp - lastPressTimestamp;
2409 doubleClick = timestampDelta > 0 && timestampDelta < doubleClickInterval && button == mousePressButton;
2410 mousePressButton = button;
2411 lastPressTimestamp = e ->timestamp;
2415 if (e->nullWindow()) {
2416 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2420 if (e->buttons != Qt::NoButton) {
2421 if (!currentMousePressWindow)
2422 currentMousePressWindow = window;
2424 window = currentMousePressWindow;
2425 }
else if (currentMousePressWindow) {
2426 window = currentMousePressWindow;
2427 currentMousePressWindow =
nullptr;
2429 localPoint = window->mapFromGlobal(globalPoint);
2437 if (!e->synthetic()) {
2438 if (
const QScreen *screen = window->screen())
2439 if (QPlatformCursor *cursor = screen->handle()->cursor()) {
2440 const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
2441 const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
2442 QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
2443 button, e->buttons, e->modifiers, e->source, device);
2447 ev.QInputEvent::setTimestamp(e->timestamp);
2448 cursor->pointerEvent(ev);
2453 const auto *activePopup = activePopupWindow();
2454 if (type == QEvent::MouseButtonPress)
2455 active_popup_on_press = activePopup;
2456 if (window->d_func()->blockedByModalWindow && !activePopup) {
2461 QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
2462 Q_ASSERT(devPriv->pointById(0) == persistentEPD);
2465 QMutableEventPoint::setGlobalLastPosition(persistentEPD->eventPoint, lastGlobalPosition);
2466 persistentEPD =
nullptr;
2468 ev.setTimestamp(e->timestamp);
2470 if (activePopup && activePopup != window && (!popup_closed_on_press || type == QEvent::MouseButtonRelease)) {
2472 auto *handlingPopup = window->d_func()->forwardToPopup(&ev, active_popup_on_press);
2473 if (handlingPopup) {
2474 if (type == QEvent::MouseButtonPress)
2475 active_popup_on_press = handlingPopup;
2480 if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
2482 QMutableSinglePointEvent::setDoubleClick(&ev,
true);
2485 QGuiApplication::sendSpontaneousEvent(window, &ev);
2486 e->eventAccepted = ev.isAccepted();
2487 if (!e->synthetic() && !ev.isAccepted()
2488 && !e->nonClientArea
2489 &&
qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
2490 QList<QWindowSystemInterface::TouchPoint> points;
2491 QWindowSystemInterface::TouchPoint point;
2493 point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
2498 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
2499 point.state = QEventPoint::State::Pressed;
2500 }
else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
2501 point.state = QEventPoint::State::Released;
2502 }
else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
2503 point.state = QEventPoint::State::Updated;
2511 const QList<QEventPoint> &touchPoints =
2512 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
2514 QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
2515 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
2516 processTouchEvent(&fake);
2519 mousePressButton = Qt::NoButton;
2520 if (!e->window.isNull() || e->nullWindow()) {
2521 const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
2522 QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
2523 button, e->buttons, e->modifiers, e->source, device);
2524 dblClickEvent.setTimestamp(e->timestamp);
2525 QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
2528 if (type == QEvent::MouseButtonRelease && e->buttons == Qt::NoButton) {
2529 popup_closed_on_press =
false;
2530 if (
auto *persistentEPD = devPriv->queryPointById(0)) {
2531 ev.setExclusiveGrabber(persistentEPD->eventPoint,
nullptr);
2532 ev.clearPassiveGrabbers(persistentEPD->eventPoint);
2537void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e)
2539#if QT_CONFIG(wheelevent)
2540 QWindow *window = e->window.data();
2541 QPointF globalPoint = e->globalPos;
2542 QPointF localPoint = e->localPos;
2544 if (e->nullWindow()) {
2545 window = QGuiApplication::topLevelAt(globalPoint.toPoint());
2547 localPoint = window->mapFromGlobal(globalPoint);
2553 QGuiApplicationPrivate::lastCursorPosition = globalPoint;
2554 modifier_buttons = e->modifiers;
2556 if (window->d_func()->blockedByModalWindow) {
2561 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
2562 QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
2563 mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
2564 ev.setTimestamp(e->timestamp);
2565 QGuiApplication::sendSpontaneousEvent(window, &ev);
2566 e->eventAccepted = ev.isAccepted();
2572void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e)
2574 QWindow *window = e->window.data();
2575 modifier_buttons = e->modifiers;
2578 || e->key == Qt::Key_Back || e->key == Qt::Key_Menu
2581 window = QGuiApplication::focusWindow();
2585 e->eventAccepted =
false;
2589#if defined(Q_OS_ANDROID)
2590 static bool backKeyPressAccepted =
false;
2591 static bool menuKeyPressAccepted =
false;
2594#if !defined(Q_OS_MACOS)
2597 if (e->keyType == QEvent::KeyPress) {
2598 if (QWindowSystemInterface::handleShortcutEvent(window, e->timestamp, e->key, e->modifiers,
2599 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers, e->unicode, e->repeat, e->repeatCount)) {
2600#if defined(Q_OS_ANDROID)
2601 backKeyPressAccepted = e->key == Qt::Key_Back;
2602 menuKeyPressAccepted = e->key == Qt::Key_Menu;
2609 QKeyEvent ev(e->keyType, e->key, e->modifiers,
2610 e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
2611 e->unicode, e->repeat, e->repeatCount);
2612 ev.setTimestamp(e->timestamp);
2614 const auto *activePopup = activePopupWindow();
2615 if (activePopup && activePopup != window) {
2617 if (window->d_func()->forwardToPopup(&ev, active_popup_on_press))
2623 if (!window->d_func()->blockedByModalWindow)
2624 QGuiApplication::sendSpontaneousEvent(window, &ev);
2627 ev.setAccepted(
false);
2629 if (e->keyType == QEvent::KeyPress) {
2630 backKeyPressAccepted = e->key == Qt::Key_Back && ev.isAccepted();
2631 menuKeyPressAccepted = e->key == Qt::Key_Menu && ev.isAccepted();
2632 }
else if (e->keyType == QEvent::KeyRelease) {
2633 if (e->key == Qt::Key_Back && !backKeyPressAccepted && !ev.isAccepted()) {
2635 QWindowSystemInterface::handleCloseEvent(window);
2636 }
else if (e->key == Qt::Key_Menu && !menuKeyPressAccepted && !ev.isAccepted()) {
2637 platform_theme->showPlatformMenuBar();
2641 e->eventAccepted = ev.isAccepted();
2644void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
2648 if (e->enter.data()->d_func()->blockedByModalWindow) {
2653 currentMouseWindow = e->enter;
2656 QEnterEvent event(e->localPos, e->localPos, e->globalPos);
2663 const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice());
2664 auto epd = devPriv->queryPointById(event.points().first().id());
2666 QMutableEventPoint::setVelocity(epd->eventPoint, {});
2668 QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
2671void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e)
2675 if (e->leave.data()->d_func()->blockedByModalWindow) {
2680 currentMouseWindow =
nullptr;
2682 QEvent event(QEvent::Leave);
2683 QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
2686void QGuiApplicationPrivate::processFocusWindowEvent(QWindowSystemInterfacePrivate::FocusWindowEvent *e)
2688 QWindow *previous = QGuiApplicationPrivate::focus_window;
2689 QWindow *newFocus = e->focused.data();
2691 if (previous == newFocus)
2694 bool activatedPopup =
false;
2696 if (QPlatformWindow *platformWindow = newFocus->handle())
2697 if (platformWindow->isAlertState())
2698 platformWindow->setAlertState(
false);
2699 activatedPopup = (newFocus->flags() & Qt::WindowType_Mask) == Qt::Popup;
2701 activatePopup(newFocus);
2704 QObject *previousFocusObject = previous ? previous->focusObject() :
nullptr;
2707 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
2708 QCoreApplication::sendSpontaneousEvent(previous, &focusAboutToChange);
2711 QGuiApplicationPrivate::focus_window = newFocus;
2716 Qt::FocusReason r = e->reason;
2717 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) && activatedPopup)
2718 r = Qt::PopupFocusReason;
2719 QFocusEvent focusOut(QEvent::FocusOut, r);
2720 QCoreApplication::sendSpontaneousEvent(previous, &focusOut);
2721 QObject::disconnect(previous, SIGNAL(focusObjectChanged(QObject*)),
2722 qApp, SLOT(_q_updateFocusObject(QObject*)));
2723 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2724 setApplicationState(Qt::ApplicationActive);
2727 if (QGuiApplicationPrivate::focus_window) {
2728 Qt::FocusReason r = e->reason;
2729 if ((r == Qt::OtherFocusReason || r == Qt::ActiveWindowFocusReason) &&
2730 previous && (previous->flags() & Qt::Popup) == Qt::Popup)
2731 r = Qt::PopupFocusReason;
2732 QFocusEvent focusIn(QEvent::FocusIn, r);
2733 QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
2734 QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
2735 qApp, SLOT(_q_updateFocusObject(QObject*)));
2736 }
else if (!platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
2737 setApplicationState(Qt::ApplicationInactive);
2741 self->notifyActiveWindowChange(previous);
2743 if (previousFocusObject !=
qApp->focusObject() ||
2749 (previous && previousFocusObject ==
nullptr &&
qApp->focusObject() ==
nullptr)) {
2750 self->_q_updateFocusObject(
qApp->focusObject());
2754 emit
qApp->focusWindowChanged(newFocus);
2756 emit previous->activeChanged();
2758 emit newFocus->activeChanged();
2761void QGuiApplicationPrivate::processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *wse)
2763 if (QWindow *window = wse->window.data()) {
2764 QWindowPrivate *windowPrivate = qt_window_private(window);
2765 const auto originalEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2767 windowPrivate->windowState = wse->newState;
2768 const auto newEffectiveState = QWindowPrivate::effectiveState(windowPrivate->windowState);
2769 if (newEffectiveState != originalEffectiveState)
2770 emit window->windowStateChanged(newEffectiveState);
2772 windowPrivate->updateVisibility();
2774 QWindowStateChangeEvent e(wse->oldState);
2775 QGuiApplication::sendSpontaneousEvent(window, &e);
2779void QGuiApplicationPrivate::processWindowScreenChangedEvent(QWindowSystemInterfacePrivate::WindowScreenChangedEvent *wse)
2781 QWindow *window = wse->window.data();
2785 if (window->screen() == wse->screen.data())
2788 if (QWindow *topLevelWindow = window->d_func()->topLevelWindow(QWindow::ExcludeTransients)) {
2789 if (QScreen *screen = wse->screen.data())
2790 topLevelWindow->d_func()->setTopLevelScreen(screen,
false );
2792 topLevelWindow->setScreen(
nullptr);
2796void QGuiApplicationPrivate::processWindowDevicePixelRatioChangedEvent(QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent *wde)
2798 if (wde->window.isNull())
2800 QWindowPrivate::get(wde->window)->updateDevicePixelRatio();
2803void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent *wse)
2805 if (wse->window.isNull())
2808 emit wse->window->safeAreaMarginsChanged(wse->window->safeAreaMargins());
2810 QEvent event(QEvent::SafeAreaMarginsChange);
2811 QGuiApplication::sendSpontaneousEvent(wse->window, &event);
2814void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce)
2817 self->handleThemeChanged();
2819 QIconPrivate::clearIconCache();
2821 QEvent themeChangeEvent(QEvent::ThemeChange);
2823 QGuiApplication::sendSpontaneousEvent(tce->window, &themeChangeEvent);
2825 QGuiApplication::sendSpontaneousEvent(
qGuiApp, &themeChangeEvent);
2828void QGuiApplicationPrivate::handleThemeChanged()
2830 const auto newColorScheme = platformTheme() ? platformTheme()->colorScheme()
2831 : Qt::ColorScheme::Unknown;
2832 QStyleHintsPrivate::get(QGuiApplication::styleHints())->updateColorScheme(newColorScheme);
2836 QIconLoader::instance()->updateSystemTheme();
2837 QAbstractFileIconProviderPrivate::clearIconTypeCache();
2839 if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
2840 const auto locker = qt_scoped_lock(applicationFontMutex);
2841 clearFontUnlocked();
2847void QGuiApplicationPrivate::processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e)
2849 if (e->window.isNull())
2852 QWindow *window = e->window.data();
2856 const QRect lastReportedGeometry = window->d_func()->geometry;
2857 const QRect requestedGeometry = e->requestedGeometry;
2858 const QRect actualGeometry = e->newGeometry;
2868 const bool isResize = actualGeometry.size() != lastReportedGeometry.size()
2869 || requestedGeometry.size() != actualGeometry.size();
2870 const bool isMove = actualGeometry.topLeft() != lastReportedGeometry.topLeft()
2871 || requestedGeometry.topLeft() != actualGeometry.topLeft();
2873 window->d_func()->geometry = actualGeometry;
2875 if (isResize || window->d_func()->resizeEventPending) {
2876 QResizeEvent e(actualGeometry.size(), lastReportedGeometry.size());
2877 QGuiApplication::sendSpontaneousEvent(window, &e);
2879 window->d_func()->resizeEventPending =
false;
2881 if (actualGeometry.width() != lastReportedGeometry.width())
2882 emit window->widthChanged(actualGeometry.width());
2883 if (actualGeometry.height() != lastReportedGeometry.height())
2884 emit window->heightChanged(actualGeometry.height());
2889 QMoveEvent e(actualGeometry.topLeft(), lastReportedGeometry.topLeft());
2890 QGuiApplication::sendSpontaneousEvent(window, &e);
2892 if (actualGeometry.x() != lastReportedGeometry.x())
2893 emit window->xChanged(actualGeometry.x());
2894 if (actualGeometry.y() != lastReportedGeometry.y())
2895 emit window->yChanged(actualGeometry.y());
2899void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e)
2901 if (e->window.isNull())
2903 if (e->window.data()->d_func()->blockedByModalWindow && !e->window.data()->d_func()->inClose) {
2906 e->eventAccepted =
false;
2911 QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
2913 e->eventAccepted = event.isAccepted();
2916void QGuiApplicationPrivate::processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e)
2918 if (e->url.isEmpty())
2921 QFileOpenEvent event(e->url);
2922 QGuiApplication::sendSpontaneousEvent(
qApp, &event);
2925QGuiApplicationPrivate::TabletPointData &QGuiApplicationPrivate::tabletDevicePoint(qint64 deviceId)
2927 for (
int i = 0; i < tabletDevicePoints.size(); ++i) {
2928 TabletPointData &pointData = tabletDevicePoints[i];
2929 if (pointData.deviceId == deviceId)
2933 tabletDevicePoints.append(TabletPointData(deviceId));
2934 return tabletDevicePoints.last();
2937void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e)
2939#if QT_CONFIG(tabletevent)
2940 const auto device =
static_cast<
const QPointingDevice *>(e->device);
2941 TabletPointData &pointData = tabletDevicePoint(device->uniqueId().numericId());
2943 QEvent::Type type = QEvent::TabletMove;
2944 if (e->buttons != pointData.state)
2945 type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease;
2947 QWindow *window = e->window.data();
2948 modifier_buttons = e->modifiers;
2950 bool localValid =
true;
2954 if (type == QEvent::TabletPress) {
2955 if (e->nullWindow()) {
2956 window = QGuiApplication::topLevelAt(e->global.toPoint());
2961 active_popup_on_press = activePopupWindow();
2962 pointData.target = window;
2964 if (e->nullWindow()) {
2965 window = pointData.target;
2968 if (type == QEvent::TabletRelease)
2969 pointData.target =
nullptr;
2973 QPointF local = e->local;
2975 QPointF delta = e->global - e->global.toPoint();
2976 local = window->mapFromGlobal(e->global.toPoint()) + delta;
2980 Qt::MouseButtons stateChange = e->buttons ^ pointData.state;
2981 Qt::MouseButton button = Qt::NoButton;
2982 for (
int check = Qt::LeftButton; check <=
int(Qt::MaxMouseButton); check = check << 1) {
2983 if (check & stateChange) {
2984 button = Qt::MouseButton(check);
2989 const auto *activePopup = activePopupWindow();
2990 if (window->d_func()->blockedByModalWindow && !activePopup) {
2995 QTabletEvent tabletEvent(type, device, local, e->global,
2996 e->pressure, e->xTilt, e->yTilt,
2997 e->tangentialPressure, e->rotation, e->z,
2998 e->modifiers, button, e->buttons);
2999 tabletEvent.setAccepted(
false);
3000 tabletEvent.setTimestamp(e->timestamp);
3002 if (activePopup && activePopup != window) {
3004 if (window->d_func()->forwardToPopup(&tabletEvent, active_popup_on_press))
3008 QGuiApplication::sendSpontaneousEvent(window, &tabletEvent);
3009 pointData.state = e->buttons;
3010 if (!tabletEvent.isAccepted()
3011 && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse
3012 && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) {
3014 const QEvent::Type mouseType = [&]() {
3016 case QEvent::TabletPress:
return QEvent::MouseButtonPress;
3017 case QEvent::TabletMove:
return QEvent::MouseMove;
3018 case QEvent::TabletRelease:
return QEvent::MouseButtonRelease;
3019 default: Q_UNREACHABLE();
3022 QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
3023 e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized,
false, device);
3024 mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3025 qCDebug(lcPtrDispatch) <<
"synthesizing mouse from tablet event" << mouseType
3026 << e->local << button << e->buttons << e->modifiers;
3027 processMouseEvent(&mouseEvent);
3034void QGuiApplicationPrivate::processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e)
3036#if QT_CONFIG(tabletevent)
3037 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3038 QTabletEvent ev(QEvent::TabletEnterProximity, dev, QPointF(), QPointF(),
3039 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3040 tabletDevicePoint(dev->uniqueId().numericId()).state);
3041 ev.setTimestamp(e->timestamp);
3042 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3048void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e)
3050#if QT_CONFIG(tabletevent)
3051 const QPointingDevice *dev =
static_cast<
const QPointingDevice *>(e->device);
3052 QTabletEvent ev(QEvent::TabletLeaveProximity, dev, QPointF(), QPointF(),
3053 0, 0, 0, 0, 0, 0, e->modifiers, Qt::NoButton,
3054 tabletDevicePoint(dev->uniqueId().numericId()).state);
3055 ev.setTimestamp(e->timestamp);
3056 QGuiApplication::sendSpontaneousEvent(qGuiApp, &ev);
3062#ifndef QT_NO_GESTURES
3063void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
3065 if (e->window.isNull())
3068 const QPointingDevice *device =
static_cast<
const QPointingDevice *>(e->device);
3069 QNativeGestureEvent ev(e->type, device, e->fingerCount, e->pos, e->pos, e->globalPos, (e->intValue ? e->intValue : e->realValue),
3070 e->delta, e->sequenceId);
3071 ev.setTimestamp(e->timestamp);
3072 QGuiApplication::sendSpontaneousEvent(e->window, &ev);
3076void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
3081 if (e->window->d_func()->blockedByModalWindow) {
3086 QEvent ev(QEvent::PlatformPanel);
3087 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3090#ifndef QT_NO_CONTEXTMENU
3091void QGuiApplicationPrivate::processContextMenuEvent(QWindowSystemInterfacePrivate::ContextMenuEvent *e)
3095 if (!e->window || e->mouseTriggered || e->window->d_func()->blockedByModalWindow)
3098 QContextMenuEvent ev(QContextMenuEvent::Keyboard, e->pos, e->globalPos, e->modifiers);
3099 QGuiApplication::sendSpontaneousEvent(e->window.data(), &ev);
3100 e->eventAccepted = ev.isAccepted();
3104void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e)
3106 if (!QInputDevicePrivate::isRegistered(e->device))
3109 modifier_buttons = e->modifiers;
3110 QPointingDevice *device =
const_cast<QPointingDevice *>(
static_cast<
const QPointingDevice *>(e->device));
3111 QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(device);
3113 if (e->touchType == QEvent::TouchCancel) {
3116 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3117 touchEvent.setTimestamp(e->timestamp);
3118 constexpr qsizetype Prealloc =
decltype(devPriv->activePoints)::mapped_container_type::PreallocatedSize;
3119 QMinimalVarLengthFlatSet<QWindow *, Prealloc> windowsNeedingCancel;
3121 for (
auto &epd : devPriv->activePoints.values()) {
3122 if (QWindow *w = QMutableEventPoint::window(epd.eventPoint))
3123 windowsNeedingCancel.insert(w);
3126 for (QWindow *w : windowsNeedingCancel)
3127 QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
3129 if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
3130 for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
3131 synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
3132 if (!synthIt->window)
3134 QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
3141 QEvent::MouseButtonRelease,
3142 Qt::MouseEventNotSynthesized,
3145 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3146 processMouseEvent(&fake);
3148 self->synthesizedMousePoints.clear();
3150 self->lastTouchType = e->touchType;
3155 if (self->lastTouchType == QEvent::TouchCancel && e->touchType != QEvent::TouchBegin)
3158 self->lastTouchType = e->touchType;
3160 QPointer<QWindow> window = e->window;
3161 QVarLengthArray<QMutableTouchEvent, 2> touchEvents;
3167 for (
auto &tempPt : e->points) {
3169 auto epd = devPriv->pointById(tempPt.id());
3170 auto &ep = epd->eventPoint;
3171 epd->eventPoint.setAccepted(
false);
3172 switch (tempPt.state()) {
3173 case QEventPoint::State::Pressed:
3175 if (!window && e->device && e->device->type() == QInputDevice::DeviceType::TouchPad)
3176 window = devPriv->firstActiveWindow();
3179 window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
3180 QMutableEventPoint::setWindow(ep, window);
3181 active_popup_on_press = activePopupWindow();
3184 case QEventPoint::State::Released:
3185 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3186 qCDebug(lcPtrDispatch) <<
"delivering touch release to same window"
3187 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3188 window = QMutableEventPoint::window(ep);
3192 if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
3193 qCDebug(lcPtrDispatch) <<
"delivering touch update to same window"
3194 << QMutableEventPoint::window(ep) <<
"not" << window.data();
3195 window = QMutableEventPoint::window(ep);
3199 if (Q_UNLIKELY(!window)) {
3200 qCDebug(lcPtrDispatch) <<
"skipping" << &tempPt <<
": no target window";
3203 QMutableEventPoint::update(tempPt, ep);
3205 Q_ASSERT(window.data() !=
nullptr);
3208 QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
3211 QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
3214 QMutableEventPoint::setTimestamp(ep, e->timestamp);
3218 for (QMutableTouchEvent &ev : touchEvents) {
3219 if (ev.target() == window.data()) {
3226 QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
3227 mte.setTimestamp(e->timestamp);
3228 mte.setTarget(window.data());
3229 touchEvents.append(mte);
3233 if (touchEvents.isEmpty())
3236 for (QMutableTouchEvent &touchEvent : touchEvents) {
3237 QWindow *window =
static_cast<QWindow *>(touchEvent.target());
3239 QEvent::Type eventType;
3240 switch (touchEvent.touchPointStates()) {
3241 case QEventPoint::State::Pressed:
3242 eventType = QEvent::TouchBegin;
3244 case QEventPoint::State::Released:
3245 eventType = QEvent::TouchEnd;
3248 eventType = QEvent::TouchUpdate;
3252 const auto *activePopup = activePopupWindow();
3253 if (window->d_func()->blockedByModalWindow && !activePopup) {
3257 if (touchEvent.type() == QEvent::TouchEnd) {
3260 QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
3261 touchEvent.setTimestamp(e->timestamp);
3262 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3267 if (activePopup && activePopup != window) {
3269 if (window->d_func()->forwardToPopup(&touchEvent, active_popup_on_press))
3276 QGuiApplication::sendSpontaneousEvent(window, &touchEvent);
3278 if (!e->synthetic() && !touchEvent.isAccepted() &&
qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
3280 if (!(touchEvent.device()->capabilities().testFlag(QInputDevice::Capability::MouseEmulation))) {
3282 QEvent::Type mouseEventType = QEvent::MouseMove;
3283 Qt::MouseButton button = Qt::NoButton;
3284 Qt::MouseButtons buttons = Qt::LeftButton;
3285 if (eventType == QEvent::TouchBegin || m_fakeMouseSourcePointId < 0) {
3286 m_fakeMouseSourcePointId = touchEvent.point(0).id();
3287 qCDebug(lcPtrDispatch) <<
"synthesizing mouse events from touchpoint" << m_fakeMouseSourcePointId;
3289 if (m_fakeMouseSourcePointId >= 0) {
3290 const auto *touchPoint = touchEvent.pointById(m_fakeMouseSourcePointId);
3292 switch (touchPoint->state()) {
3293 case QEventPoint::State::Pressed:
3294 mouseEventType = QEvent::MouseButtonPress;
3295 button = Qt::LeftButton;
3297 case QEventPoint::State::Released:
3298 mouseEventType = QEvent::MouseButtonRelease;
3299 button = Qt::LeftButton;
3300 buttons = Qt::NoButton;
3301 Q_ASSERT(m_fakeMouseSourcePointId == touchPoint->id());
3302 m_fakeMouseSourcePointId = -1;
3307 if (touchPoint->state() != QEventPoint::State::Released) {
3308 self->synthesizedMousePoints.insert(window, SynthesizedMouseData(
3309 touchPoint->position(), touchPoint->globalPosition(), window));
3315 QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp,
3316 window->mapFromGlobal(touchPoint->globalPosition().toPoint()),
3317 touchPoint->globalPosition(),
3322 Qt::MouseEventSynthesizedByQt,
3326 fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
3327 processMouseEvent(&fake);
3330 if (eventType == QEvent::TouchEnd)
3331 self->synthesizedMousePoints.clear();
3338 for (
const QEventPoint &touchPoint : e->points) {
3339 if (touchPoint.state() == QEventPoint::State::Released)
3340 devPriv->removePointById(touchPoint.id());
3344void QGuiApplicationPrivate::processScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e)
3347 if (QCoreApplication::startingUp())
3353 QScreen *s = e->screen.data();
3354 s->d_func()->orientation = e->orientation;
3356 emit s->orientationChanged(s->orientation());
3358 QScreenOrientationChangeEvent event(s, s->orientation());
3359 QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
3362void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
3365 if (QCoreApplication::startingUp())
3372 QScreen *s = e->screen.data();
3373 QScreenPrivate::UpdateEmitter updateEmitter(s);
3377 s->d_func()->geometry = e->geometry;
3378 s->d_func()->availableGeometry = e->availableGeometry;
3380 s->d_func()->updatePrimaryOrientation();
3383 resetCachedDevicePixelRatio();
3386void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
3389 if (QCoreApplication::startingUp())
3392 QHighDpiScaling::updateHighDpiScaling();
3398 QScreen *s = e->screen.data();
3399 QScreenPrivate::UpdateEmitter updateEmitter(s);
3400 s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
3401 s->d_func()->updateGeometry();
3404 for (QWindow *window : QGuiApplication::allWindows())
3405 if (window->screen() == e->screen)
3406 QWindowPrivate::get(window)->updateDevicePixelRatio();
3408 resetCachedDevicePixelRatio();
3411void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
3414 if (QCoreApplication::startingUp())
3420 QScreen *s = e->screen.data();
3421 qreal rate = e->rate;
3425 if (!qFuzzyCompare(s->d_func()->refreshRate, rate)) {
3426 s->d_func()->refreshRate = rate;
3427 emit s->refreshRateChanged(s->refreshRate());
3431void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
3436 QWindow *window = e->window.data();
3439 QWindowPrivate *p = qt_window_private(window);
3441 if (!p->receivedExpose) {
3442 if (p->resizeEventPending) {
3445 QResizeEvent e(window->geometry().size(), p->geometry.size());
3446 QGuiApplication::sendSpontaneousEvent(window, &e);
3448 p->resizeEventPending =
false;
3457 p->receivedExpose =
true;
3461 const bool shouldSynthesizePaintEvents = !platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents);
3463 const bool wasExposed = p->exposed;
3464 p->exposed = e->isExposed && window->screen();
3469 if (e->isExposed && !e->region.isEmpty()) {
3470 const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio();
3472 qWarning() <<
"The cached device pixel ratio value was stale on window expose. "
3473 <<
"Please file a QTBUG which explains how to reproduce.";
3477 if (wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3478 QPaintEvent paintEvent(e->region);
3479 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3480 if (paintEvent.isAccepted())
3488 QExposeEvent exposeEvent(e->region);
3489 QCoreApplication::sendSpontaneousEvent(window, &exposeEvent);
3490 e->eventAccepted = exposeEvent.isAccepted();
3497 if (!wasExposed && p->exposed && shouldSynthesizePaintEvents) {
3498 QPaintEvent paintEvent(e->region);
3499 QCoreApplication::sendSpontaneousEvent(window, &paintEvent);
3503void QGuiApplicationPrivate::processPaintEvent(QWindowSystemInterfacePrivate::PaintEvent *e)
3505 Q_ASSERT_X(platformIntegration()->hasCapability(QPlatformIntegration::PaintEvents),
"QGuiApplication",
3506 "The platform sent paint events without claiming support for it in QPlatformIntegration::capabilities()");
3511 QPaintEvent paintEvent(e->region);
3512 QCoreApplication::sendSpontaneousEvent(e->window, &paintEvent);
3516 e->eventAccepted = paintEvent.isAccepted();
3519#if QT_CONFIG(draganddrop)
3522
3523
3524
3525
3526static void updateMouseAndModifierButtonState(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3528 QGuiApplicationPrivate::mouse_buttons = buttons;
3529 QGuiApplicationPrivate::modifier_buttons = modifiers;
3532QPlatformDragQtResponse QGuiApplicationPrivate::processDrag(QWindow *w,
const QMimeData *dropData,
3533 const QPoint &p, Qt::DropActions supportedActions,
3534 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3536 updateMouseAndModifierButtonState(buttons, modifiers);
3538 static Qt::DropAction lastAcceptedDropAction = Qt::IgnoreAction;
3539 QPlatformDrag *platformDrag = platformIntegration()->drag();
3540 if (!platformDrag || (w && w->d_func()->blockedByModalWindow)) {
3541 lastAcceptedDropAction = Qt::IgnoreAction;
3542 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3546 currentDragWindow =
nullptr;
3548 QGuiApplication::sendEvent(w, &e);
3549 lastAcceptedDropAction = Qt::IgnoreAction;
3550 return QPlatformDragQtResponse(
false, lastAcceptedDropAction, QRect());
3552 QDragMoveEvent me(p, supportedActions, dropData, buttons, modifiers);
3554 if (w != currentDragWindow) {
3555 lastAcceptedDropAction = Qt::IgnoreAction;
3556 if (currentDragWindow) {
3558 QGuiApplication::sendEvent(currentDragWindow, &e);
3560 currentDragWindow = w;
3561 QDragEnterEvent e(p, supportedActions, dropData, buttons, modifiers);
3562 QGuiApplication::sendEvent(w, &e);
3563 if (e.isAccepted() && e.dropAction() != Qt::IgnoreAction)
3564 lastAcceptedDropAction = e.dropAction();
3568 if (lastAcceptedDropAction != Qt::IgnoreAction
3569 && (supportedActions & lastAcceptedDropAction)) {
3570 me.setDropAction(lastAcceptedDropAction);
3573 QGuiApplication::sendEvent(w, &me);
3574 lastAcceptedDropAction = me.isAccepted() ?
3575 me.dropAction() : Qt::IgnoreAction;
3576 return QPlatformDragQtResponse(me.isAccepted(), lastAcceptedDropAction, me.answerRect());
3579QPlatformDropQtResponse QGuiApplicationPrivate::processDrop(QWindow *w,
const QMimeData *dropData,
3580 const QPoint &p, Qt::DropActions supportedActions,
3581 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3583 updateMouseAndModifierButtonState(buttons, modifiers);
3585 currentDragWindow =
nullptr;
3587 QDropEvent de(p, supportedActions, dropData, buttons, modifiers);
3588 QGuiApplication::sendEvent(w, &de);
3590 Qt::DropAction acceptedAction = de.isAccepted() ? de.dropAction() : Qt::IgnoreAction;
3591 QPlatformDropQtResponse response(de.isAccepted(),acceptedAction);
3597#ifndef QT_NO_CLIPBOARD
3599
3600
3601QClipboard * QGuiApplication::clipboard()
3603 if (QGuiApplicationPrivate::qt_clipboard ==
nullptr) {
3605 qWarning(
"QGuiApplication: Must construct a QGuiApplication before accessing a QClipboard");
3608 QGuiApplicationPrivate::qt_clipboard =
new QClipboard(
nullptr);
3610 return QGuiApplicationPrivate::qt_clipboard;
3615
3616
3617
3618
3619
3620
3621
3622
3623
3626
3627
3628
3629
3630
3631
3633QPalette QGuiApplication::palette()
3635 if (!QGuiApplicationPrivate::app_pal)
3636 QGuiApplicationPrivate::updatePalette();
3638 return *QGuiApplicationPrivate::app_pal;