5#include <qpa/qplatformwindow.h>
7#include "private/qguiapplication_p.h"
8#include "private/qevent_p.h"
9#include "private/qeventpoint_p.h"
10#include "private/qpointingdevice_p.h"
11#include "private/qscreen_p.h"
12#include <QAbstractEventDispatcher>
13#include <qpa/qplatformintegration.h>
17#include <QtCore/qscopedvaluerollback.h>
18#include <QtCore/private/qlocking_p.h>
20#if QT_CONFIG(draganddrop)
21#include <qpa/qplatformdrag.h>
26using namespace Qt::StringLiterals;
30Q_CONSTINIT QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
31bool QWindowSystemInterfacePrivate::synchronousWindowSystemEvents =
false;
32bool QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse =
true;
33QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
34Q_CONSTINIT QMutex QWindowSystemInterfacePrivate::flushEventMutex;
35Q_CONSTINIT QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
36QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
37QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue;
42
43
44
45
46
47
48
49
51template<
typename Delivery>
54 template<
typename EventType,
typename ...Args>
59
60
61
62
63
64
65
66
67
68
69
70
71
72
74template<
typename EventType,
typename ...Args>
75bool QWindowSystemHelper<QWindowSystemInterface::DefaultDelivery>::handleEvent(Args ...args)
77 return QWindowSystemInterfacePrivate::synchronousWindowSystemEvents
78 ? QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent<EventType>(args...)
79 : QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
83
84
85
86
87
88
89
90
91
93template<
typename EventType,
typename ...Args>
94bool QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent(Args ...args)
96 if (QThread::isMainThread()) {
97 EventType event(args...);
99 if (QWindowSystemInterfacePrivate::eventHandler) {
100 if (!QWindowSystemInterfacePrivate::eventHandler->sendEvent(&event))
103 QGuiApplicationPrivate::processWindowSystemEvent(&event);
105 return event.eventAccepted;
111 QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
112 return QWindowSystemInterface::flushWindowSystemEvents();
117
118
119
120
121
122
124template<
typename EventType,
typename ...Args>
125bool QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent(Args ...args)
127 QWindowSystemInterfacePrivate::windowSystemEventQueue.append(
new EventType(args...));
128 if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
129 dispatcher->wakeUp();
139qsizetype QWindowSystemInterfacePrivate::windowSystemEventsQueued()
141 return windowSystemEventQueue.count();
144bool QWindowSystemInterfacePrivate::nonUserInputEventsQueued()
146 return windowSystemEventQueue.nonUserInputEventsQueued();
149QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
151 return windowSystemEventQueue.takeFirstOrReturnNull();
154QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
156 return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
159QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
161 return windowSystemEventQueue.peekAtFirstOfType(t);
164void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
166 windowSystemEventQueue.remove(event);
169void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
172 eventHandler = handler;
175void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
177 if (eventHandler == handler)
178 eventHandler =
nullptr;
181QWindowSystemEventHandler::~QWindowSystemEventHandler()
183 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(
this);
186bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
188 QGuiApplicationPrivate::processWindowSystemEvent(e);
197#define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName, ...)
198 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::DefaultDelivery>(__VA_ARGS__);
199 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::SynchronousDelivery>(__VA_ARGS__);
200 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::AsynchronousDelivery>(__VA_ARGS__);
201 template<typename Delivery> ReturnType QWindowSystemInterface::HandlerName(__VA_ARGS__)
204
205
206
207
208
209
210
211
212
213
218 handleWindowSystemEvent<QWindowSystemInterfacePrivate::EnterEvent, Delivery>(window,
219 QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window));
225 handleWindowSystemEvent<QWindowSystemInterfacePrivate::LeaveEvent, Delivery>(window);
229
230
231
232
233
234
235void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave,
const QPointF &local,
const QPointF& global)
237 handleLeaveEvent<AsynchronousDelivery>(leave);
238 handleEnterEvent(enter, local, global);
243 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FocusWindowEvent, Delivery>(window, r);
249 if (oldState < Qt::WindowNoState)
250 oldState = window->windowStates();
252 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowStateChangedEvent, Delivery>(window, newState, Qt::WindowStates(oldState));
257 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowScreenChangedEvent, Delivery>(window, screen);
262 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent, Delivery>(window);
268 handleWindowSystemEvent<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent, Delivery>(window);
273 Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
274 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent, Delivery>(newState, forcePropagate);
279 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent, Delivery>(
280 QWindowSystemInterfacePrivate::ApplicationTermination);
283QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow *window,
284 QRect requestedGeometry,
286 : WindowSystemEvent(GeometryChange)
288 , requestedGeometry(requestedGeometry)
289 , newGeometry(newGeometry)
296 const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window);
297 QRect requestedGeometry;
298 if (
auto *handle = window->handle()) {
299 requestedGeometry = QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(),
302 handle->QPlatformWindow::setGeometry(newRect);
307 handleWindowSystemEvent<QWindowSystemInterfacePrivate::GeometryChangeEvent, Delivery>(window,
312QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window,
const QRegion ®ion)
313 : WindowSystemEvent(Expose)
315 , isExposed(window && window->handle() ? window->handle()->isExposed() :
false)
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
339 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ExposeEvent, Delivery>(window,
340 QHighDpi::fromNativeLocalExposedRegion(region, window));
345 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::PaintEvent, Delivery>(window,
346 QHighDpi::fromNativeLocalExposedRegion(region, window));
353 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::CloseEvent, Delivery>(window);
357
358
359
360
363 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
364 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
365 Qt::MouseEventSource source)
367 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
368 return handleMouseEvent<Delivery>(window, time, local, global, state, button, type, mods, source);
372 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
373 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
374 Qt::MouseEventSource source)
376 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
377 return handleMouseEvent<Delivery>(window, time, device, local, global, state, button, type, mods, source);
381 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
382 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
383 Qt::MouseEventSource source)
385 return handleMouseEvent<Delivery>(window, timestamp, QPointingDevice::primaryPointingDevice(),
386 local, global, state, button, type, mods, source);
390 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
391 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
392 Qt::MouseEventSource source)
395 bool isNonClientArea = {};
398 case QEvent::MouseButtonDblClick:
399 case QEvent::NonClientAreaMouseButtonDblClick:
400 Q_ASSERT_X(
false,
"QWindowSystemInterface::handleMouseEvent",
401 "QTBUG-71263: Native double clicks are not implemented.");
403 case QEvent::MouseMove:
404 case QEvent::MouseButtonPress:
405 case QEvent::MouseButtonRelease:
406 isNonClientArea =
false;
408 case QEvent::NonClientAreaMouseMove:
409 case QEvent::NonClientAreaMouseButtonPress:
410 case QEvent::NonClientAreaMouseButtonRelease:
411 isNonClientArea =
true;
417 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
418 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
420 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::MouseEvent, Delivery>(window,
421 timestamp, localPos, globalPos, state, mods, button, type, source, isNonClientArea, device);
424bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp,
int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
425 quint32 nativeVirtualKey, quint32 nativeModifiers,
const QString &text,
bool autorepeat, ushort count)
427#if QT_CONFIG(shortcut)
429 window = QGuiApplication::focusWindow();
431 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
432 if (shortcutMap.state() == QKeySequence::NoMatch) {
438 bool overridden = handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, SynchronousDelivery>
439 (window,timestamp, QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
440 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
448 QKeyEvent keyEvent(QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
449 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
451 return shortcutMap.tryShortcut(&keyEvent);
457 Q_UNUSED(nativeScanCode);
458 Q_UNUSED(nativeVirtualKey);
459 Q_UNUSED(nativeModifiers);
461 Q_UNUSED(autorepeat);
467QT_DEFINE_QPA_EVENT_HANDLER(
bool, handleKeyEvent, QWindow *window, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text,
bool autorep, ushort count) {
468 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
469 return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count);
472QT_DEFINE_QPA_EVENT_HANDLER(
bool, handleKeyEvent, QWindow *window, ulong timestamp, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text,
bool autorep, ushort count)
474 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, Delivery>(window,
475 timestamp, t, k, mods, text, autorep, count);
478bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type,
int key, Qt::KeyboardModifiers modifiers,
479 quint32 nativeScanCode, quint32 nativeVirtualKey,
480 quint32 nativeModifiers,
481 const QString& text,
bool autorep,
484 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
485 return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
486 text, autorep, count);
489bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type,
int key,
490 Qt::KeyboardModifiers modifiers,
491 quint32 nativeScanCode, quint32 nativeVirtualKey,
492 quint32 nativeModifiers,
493 const QString& text,
bool autorep,
496 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent>(window,
497 timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
500bool QWindowSystemInterface::handleWheelEvent(QWindow *window,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
502 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
503 return handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source);
506bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
507 Qt::MouseEventSource source,
bool invertedScrolling)
509 return handleWheelEvent(window, timestamp, QPointingDevice::primaryPointingDevice(), local, global,
510 pixelDelta, angleDelta, mods, phase, source, invertedScrolling);
513bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
514 const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta,
515 Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
516 Qt::MouseEventSource source,
bool invertedScrolling)
528 if (angleDelta.isNull() && phase == Qt::ScrollUpdate)
532 if (angleDelta.y() != 0 && angleDelta.x() == 0) {
533 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
534 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
535 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
539 if (angleDelta.y() == 0 && angleDelta.x() != 0) {
540 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
541 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
542 pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
550 acceptVert = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
551 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
552 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
556 acceptHorz = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
557 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
558 QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
560 return acceptVert || acceptHorz;
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579void QWindowSystemInterface::registerInputDevice(
const QInputDevice *device)
581 QInputDevicePrivate::registerDevice(device);
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
612 QWindowSystemInterfacePrivate::fromNativeTouchPoints(
const QList<QWindowSystemInterface::TouchPoint> &points,
613 const QWindow *window, QEvent::Type *type)
615 QList<QEventPoint> touchPoints;
616 QEventPoint::States states;
618 touchPoints.reserve(points.size());
619 QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
620 QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
621 while (point != end) {
622 QPointF globalPos = QHighDpi::fromNativeGlobalPosition(point->area.center(), window);
623 QEventPoint p(point->id, point->state, globalPos, globalPos);
624 states |= point->state;
625 if (point->uniqueId >= 0)
626 QMutableEventPoint::setUniqueId(p, QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
627 QMutableEventPoint::setPressure(p, point->pressure);
628 QMutableEventPoint::setRotation(p, point->rotation);
629 QMutableEventPoint::setEllipseDiameters(p, QHighDpi::fromNativePixels(point->area.size(), window));
630 QMutableEventPoint::setVelocity(p, QHighDpi::fromNativePixels(point->velocity, window));
635 touchPoints.append(p);
641 *type = QEvent::TouchUpdate;
642 if (states == QEventPoint::State::Pressed)
643 *type = QEvent::TouchBegin;
644 else if (states == QEventPoint::State::Released)
645 *type = QEvent::TouchEnd;
651QWindowSystemInterface::TouchPoint
652QWindowSystemInterfacePrivate::toNativeTouchPoint(
const QEventPoint &pt,
const QWindow *window)
654 QWindowSystemInterface::TouchPoint p;
656 QRectF area(QPointF(), pt.ellipseDiameters());
657 area.moveCenter(pt.globalPosition());
659 p.area = QHighDpi::toNativePixels(area, window);
660 p.pressure = pt.pressure();
661 p.state = pt.state();
662 p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
667 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
669 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
670 return handleTouchEvent<Delivery>(window, time, device, points, mods);
674 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
679 if (!QPointingDevicePrivate::isRegistered(device))
683 QList<QEventPoint> touchPoints =
684 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
686 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
687 timestamp, type, device, touchPoints, mods);
691 Qt::KeyboardModifiers mods)
693 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
694 return handleTouchCancelEvent<Delivery>(window, time, device, mods);
698 Qt::KeyboardModifiers mods)
700 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
701 timestamp, QEvent::TouchCancel, device, QList<QEventPoint>(), mods);
705
706
707
708
709
710
711
712
713
714
715void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *platformScreen,
bool isPrimary)
717 QScreen *screen =
new QScreen(platformScreen);
720 QGuiApplicationPrivate::screen_list.prepend(screen);
722 QGuiApplicationPrivate::screen_list.append(screen);
724 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
725 QHighDpiScaling::updateHighDpiScaling();
726 screen->d_func()->updateGeometry();
728 emit qGuiApp->screenAdded(screen);
731 emit qGuiApp->primaryScreenChanged(screen);
735
736
737
738
739
740
741
742void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen)
744 QScreen *screen = platformScreen->screen();
747 const bool wasPrimary = QGuiApplication::primaryScreen() == screen;
748 QGuiApplicationPrivate::screen_list.removeOne(screen);
749 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
752 QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
753 if (wasPrimary && newPrimaryScreen)
754 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
758 emit qApp->screenRemoved(screen);
760 if (!QGuiApplication::closingDown()) {
761 bool movingFromVirtualSibling = newPrimaryScreen
762 && newPrimaryScreen->handle()->virtualSiblings().contains(platformScreen);
765 const auto allWindows = QGuiApplication::allWindows();
766 for (QWindow *window : allWindows) {
767 if (!window->isTopLevel() || window->screen() != screen)
770 const bool wasVisible = window->isVisible();
771 window->setScreen(newPrimaryScreen);
775 if (movingFromVirtualSibling)
776 window->setVisible(wasVisible);
783 delete platformScreen;
787
788
789
790
791
792void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
794 QScreen *newPrimaryScreen = newPrimary->screen();
795 qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
796 Q_ASSERT(indexOfScreen >= 0);
797 if (indexOfScreen == 0)
800 QGuiApplicationPrivate::screen_list.swapItemsAt(0, indexOfScreen);
801 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
804void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
806 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenOrientationEvent>(screen, orientation);
809void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen,
const QRect &geometry,
const QRect &availableGeometry)
811 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenGeometryEvent>(screen,
812 QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry,
813 screen, geometry.topLeft()));
816void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
821 QHighDpiScaling::updateHighDpiScaling();
823 const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
824 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent>(screen,
825 effectiveDpi.first, effectiveDpi.second);
828void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
830 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent>(screen, newRefreshRate);
835 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ThemeChangeEvent, Delivery>();
838#if QT_CONFIG(draganddrop)
840
841
842
843
844
845
846QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window,
const QMimeData *dropData,
847 const QPoint &p, Qt::DropActions supportedActions,
848 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
850 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
851 return QGuiApplicationPrivate::processDrag(window, dropData, pos, supportedActions, buttons, modifiers);
854QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window,
const QMimeData *dropData,
855 const QPoint &p, Qt::DropActions supportedActions,
856 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
858 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
859 return QGuiApplicationPrivate::processDrop(window, dropData, pos, supportedActions, buttons, modifiers);
864
865
866
867
868
870bool QWindowSystemInterface::handleNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
872 return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
875void QWindowSystemInterface::handleFileOpenEvent(
const QString& fileName)
877 QWindowSystemInterfacePrivate::FileOpenEvent e(fileName);
878 QGuiApplicationPrivate::processWindowSystemEvent(&e);
881void QWindowSystemInterface::handleFileOpenEvent(
const QUrl &url)
883 QWindowSystemInterfacePrivate::FileOpenEvent e(url);
884 QGuiApplicationPrivate::processWindowSystemEvent(&e);
887void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
bool v)
889 platformSynthesizesMouse = v;
892bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
893 const QPointF &local,
const QPointF &global,
894 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
895 qreal tangentialPressure, qreal rotation, qreal z,
896 Qt::KeyboardModifiers modifiers)
898 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEvent>(window,
900 QHighDpi::fromNativeLocalPosition(local, window),
901 QHighDpi::fromNativeGlobalPosition(global, window),
902 device, buttons, pressure,
903 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
906bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointingDevice *device,
907 const QPointF &local,
const QPointF &global,
908 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
909 qreal tangentialPressure, qreal rotation, qreal z,
910 Qt::KeyboardModifiers modifiers)
912 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
913 return handleTabletEvent(window, time, device, local, global,
914 buttons, pressure, xTilt, yTilt, tangentialPressure,
915 rotation, z, modifiers);
918bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global,
919 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
920 qreal tangentialPressure, qreal rotation, qreal z, qint64 uid,
921 Qt::KeyboardModifiers modifiers)
923 const QPointingDevice *dev = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
924 QPointingDeviceUniqueId::fromNumericId(uid));
925 return handleTabletEvent(window, timestamp, dev, local, global, buttons, pressure,
926 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
929bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointF &local,
const QPointF &global,
930 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
931 qreal tangentialPressure, qreal rotation, qreal z, qint64 uid,
932 Qt::KeyboardModifiers modifiers)
934 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
935 return handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
936 xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
939bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
940 bool inProximity,
const QPointF &local,
const QPointF &global,
941 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
942 qreal tangentialPressure, qreal rotation, qreal z,
943 Qt::KeyboardModifiers modifiers)
946 ? handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(
947 window, timestamp, local, global, device, buttons,
948 xTilt, yTilt, tangentialPressure, rotation, z, modifiers)
949 : handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(
950 window, timestamp, local, global, device, buttons,
951 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
954bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window,
const QPointingDevice *device,
955 bool inProximity,
const QPointF &local,
const QPointF &global,
956 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
957 qreal tangentialPressure, qreal rotation, qreal z,
958 Qt::KeyboardModifiers modifiers)
960 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
961 return handleTabletEnterLeaveProximityEvent(window, time, device, inProximity,
962 local, global, buttons, xTilt, yTilt,
963 tangentialPressure, rotation, z, modifiers);
967bool QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
969 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
970 QPointingDevice::PointerType(pointerType),
971 QPointingDeviceUniqueId::fromNumericId(uid));
972 return handleTabletEnterLeaveProximityEvent(
nullptr, timestamp, device,
true);
975void QWindowSystemInterface::handleTabletEnterProximityEvent(
int deviceType,
int pointerType, qint64 uid)
977 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
978 handleTabletEnterProximityEvent(time, deviceType, pointerType, uid);
981bool QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
983 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
984 QPointingDevice::PointerType(pointerType),
985 QPointingDeviceUniqueId::fromNumericId(uid));
986 return handleTabletEnterLeaveProximityEvent(
nullptr, timestamp, device,
false);
989void QWindowSystemInterface::handleTabletLeaveProximityEvent(
int deviceType,
int pointerType, qint64 uid)
991 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
992 handleTabletLeaveProximityEvent(time, deviceType, pointerType, uid);
995#ifndef QT_NO_GESTURES
996bool QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
997 Qt::NativeGestureType type,
const QPointF &local,
const QPointF &global,
int fingerCount)
999 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, {}, {}, local, global, fingerCount);
1002bool QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1003 Qt::NativeGestureType type, qreal value,
const QPointF &local,
const QPointF &global,
int fingerCount)
1005 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, value, {}, local, global, fingerCount);
1008bool QWindowSystemInterface::handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1009 Qt::NativeGestureType type, qreal value,
const QPointF &delta,
1010 const QPointF &local,
const QPointF &global,
int fingerCount)
1012 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
1013 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
1015 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::GestureEvent>(window,
1016 timestamp, type, device, fingerCount, localPos, globalPos, value, delta);
1020void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
1022 handleWindowSystemEvent<QWindowSystemInterfacePrivate::PlatformPanelEvent>(w);
1025#ifndef QT_NO_CONTEXTMENU
1027 const QPoint &pos,
const QPoint &globalPos,
1028 Qt::KeyboardModifiers modifiers)
1030 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ContextMenuEvent, Delivery>(
1031 window, mouseTriggered, pos, globalPos, modifiers);
1035#if QT_CONFIG(whatsthis)
1036void QWindowSystemInterface::handleEnterWhatsThisEvent()
1038 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent>(
1039 QWindowSystemInterfacePrivate::EnterWhatsThisMode);
1043#ifndef QT_NO_DEBUG_STREAM
1044Q_GUI_EXPORT
QDebug operator<<(QDebug dbg,
const QWindowSystemInterface::TouchPoint &p)
1046 QDebugStateSaver saver(dbg);
1047 dbg.nospace() <<
"TouchPoint(" << p.id <<
" @" << p.area <<
" normalized " << p.normalPosition
1048 <<
" press " << p.pressure <<
" vel " << p.velocity <<
" state " << (
int)p.state;
1056
1057
1058
1059bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1061 const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
1064 if (!QGuiApplication::instance()) {
1065 qWarning().nospace()
1066 <<
"QWindowSystemInterface::flushWindowSystemEvents() invoked after "
1067 "QGuiApplication destruction, discarding " << count <<
" events.";
1068 QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
1071 if (!QThread::isMainThread()) {
1074 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1075 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FlushEventsEvent, AsynchronousDelivery>(flags);
1076 QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
1078 sendWindowSystemEvents(flags);
1080 return QWindowSystemInterfacePrivate::eventAccepted.loadRelaxed() > 0;
1083void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1085 Q_ASSERT(QThread::isMainThread());
1087 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1088 sendWindowSystemEvents(flags);
1089 QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
1092bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1096 while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
1097 QWindowSystemInterfacePrivate::WindowSystemEvent *event =
1098 flags & QEventLoop::ExcludeUserInputEvents ?
1099 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
1100 QWindowSystemInterfacePrivate::getWindowSystemEvent();
1104 if (QWindowSystemInterfacePrivate::eventHandler) {
1105 if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
1109 QGuiApplicationPrivate::processWindowSystemEvent(event);
1115 if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
1116 QWindowSystemInterfacePrivate::eventAccepted.storeRelaxed(event->eventAccepted);
1121 return (nevents > 0);
1124void QWindowSystemInterface::setSynchronousWindowSystemEvents(
bool enable)
1126 QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
1129int QWindowSystemInterface::windowSystemEventsQueued()
1131 return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
1134bool QWindowSystemInterface::nonUserInputEventsQueued()
1136 return QWindowSystemInterfacePrivate::nonUserInputEventsQueued();
1147 Qt::MouseButtons state, Qt::MouseButton button,
1148 QEvent::Type type, Qt::KeyboardModifiers mods,
int timestamp)
1150 QPointF nativeLocal =
QHighDpi::toNativeLocalPosition(local, window);
1151 QPointF nativeGlobal =
QHighDpi::toNativeGlobalPosition(global, window);
1152 QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
1153 timestamp, nativeLocal, nativeGlobal, state, button, type, mods);
1157
1158
1159Q_GUI_EXPORT
void qt_handleKeyEvent(QWindow *window, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text = QString(),
bool autorep =
false, ushort count = 1)
1161#if defined(Q_OS_MACOS)
1163 auto timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
1164 if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
1168 QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
1171Q_GUI_EXPORT
bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp,
int k, Qt::KeyboardModifiers mods,
const QString &text = QString(),
bool autorep =
false, ushort count = 1)
1173#if QT_CONFIG(shortcut)
1181 QGuiApplicationPrivate::modifier_buttons = mods;
1183 QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count);
1184 qevent.setTimestamp(timestamp);
1186 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
1187 if (shortcutMap.state() == QKeySequence::NoMatch) {
1189 QCoreApplication::sendEvent(o, &qevent);
1190 if (qevent.isAccepted())
1195 return shortcutMap.tryShortcut(&qevent);
1198 Q_UNUSED(timestamp);
1209 QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
1210 Qt::ScrollPhase phase)
1212 QPointF nativeLocal =
QHighDpi::toNativeLocalPosition(local, window);
1213 QPointF nativeGlobal =
QHighDpi::toNativeGlobalPosition(global, window);
1214 QWindowSystemInterface::handleWheelEvent(window, nativeLocal, nativeGlobal, pixelDelta, angleDelta,
1233 const QList<QEventPoint> &points,
1234 Qt::KeyboardModifiers mods)
1236 return QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
1237 QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
1241 const QList<QEventPoint> &points,
1242 Qt::KeyboardModifiers mods)
1244 qt_handleTouchEventv2(window, device, points, mods);
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
Q_GUI_EXPORT bool qt_handleTouchEventv2(QWindow *window, const QPointingDevice *device, const QList< QEventPoint > &points, Qt::KeyboardModifiers mods)
Q_GUI_EXPORT void qt_handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase)
static bool handleWindowSystemEvent(Args ...args)
Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, const QPointingDevice *device, const QList< QEventPoint > &points, Qt::KeyboardModifiers mods)
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
#define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName,...)
Q_GUI_EXPORT void qt_handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods, int timestamp)
static bool handleEvent(Args ...)