4#include <qpa/qplatformwindow.h>
6#include "private/qguiapplication_p.h"
7#include "private/qevent_p.h"
8#include "private/qeventpoint_p.h"
9#include "private/qpointingdevice_p.h"
10#include "private/qscreen_p.h"
11#include <QAbstractEventDispatcher>
12#include <qpa/qplatformintegration.h>
16#include <QtCore/qscopedvaluerollback.h>
17#include <QtCore/private/qlocking_p.h>
19#if QT_CONFIG(draganddrop)
20#include <qpa/qplatformdrag.h>
25using namespace Qt::StringLiterals;
29Q_CONSTINIT QElapsedTimer QWindowSystemInterfacePrivate::eventTime;
30bool QWindowSystemInterfacePrivate::synchronousWindowSystemEvents =
false;
31bool QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse =
true;
32QWaitCondition QWindowSystemInterfacePrivate::eventsFlushed;
33Q_CONSTINIT QMutex QWindowSystemInterfacePrivate::flushEventMutex;
34Q_CONSTINIT QAtomicInt QWindowSystemInterfacePrivate::eventAccepted;
35QWindowSystemEventHandler *QWindowSystemInterfacePrivate::eventHandler;
36QWindowSystemInterfacePrivate::WindowSystemEventList QWindowSystemInterfacePrivate::windowSystemEventQueue;
44
45
46
47
48
49
50
51
53template<
typename Delivery>
56 template<
typename EventType,
typename ...Args>
61
62
63
64
65
66
67
68
69
70
71
72
73
74
76template<
typename EventType,
typename ...Args>
77bool QWindowSystemHelper<QWindowSystemInterface::DefaultDelivery>::handleEvent(Args ...args)
79 return QWindowSystemInterfacePrivate::synchronousWindowSystemEvents
80 ? QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent<EventType>(args...)
81 : QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
85
86
87
88
89
90
91
92
93
95template<
typename EventType,
typename ...Args>
96bool QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent(Args ...args)
98 if (QThread::isMainThread()) {
99 EventType event(args...);
101 if (QWindowSystemInterfacePrivate::eventHandler) {
102 if (!QWindowSystemInterfacePrivate::eventHandler->sendEvent(&event))
105 QGuiApplicationPrivate::processWindowSystemEvent(&event);
107 return event.eventAccepted;
113 QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
114 return QWindowSystemInterface::flushWindowSystemEvents();
119
120
121
122
123
124
126template<
typename EventType,
typename ...Args>
127bool QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent(Args ...args)
129 QWindowSystemInterfacePrivate::windowSystemEventQueue.append(
new EventType(args...));
130 if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
131 dispatcher->wakeUp();
141qsizetype QWindowSystemInterfacePrivate::windowSystemEventsQueued()
143 return windowSystemEventQueue.count();
146bool QWindowSystemInterfacePrivate::nonUserInputEventsQueued()
148 return windowSystemEventQueue.nonUserInputEventsQueued();
151QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
153 return windowSystemEventQueue.takeFirstOrReturnNull();
156QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
158 return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
161QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
163 return windowSystemEventQueue.peekAtFirstOfType(t);
166void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
168 windowSystemEventQueue.remove(event);
171void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
174 eventHandler = handler;
177void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
179 if (eventHandler == handler)
180 eventHandler =
nullptr;
183QWindowSystemEventHandler::~QWindowSystemEventHandler()
185 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(
this);
188bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
190 QGuiApplicationPrivate::processWindowSystemEvent(e);
199#define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName, ...)
200 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::DefaultDelivery>(__VA_ARGS__);
201 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::SynchronousDelivery>(__VA_ARGS__);
202 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::AsynchronousDelivery>(__VA_ARGS__);
203 template<typename Delivery> ReturnType QWindowSystemInterface::HandlerName(__VA_ARGS__)
206
207
208
209
210
211
212
213
214
215
220 handleWindowSystemEvent<QWindowSystemInterfacePrivate::EnterEvent, Delivery>(window,
221 QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window));
227 handleWindowSystemEvent<QWindowSystemInterfacePrivate::LeaveEvent, Delivery>(window);
231
232
233
234
235
236
237void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave,
const QPointF &local,
const QPointF& global)
239 handleLeaveEvent<AsynchronousDelivery>(leave);
240 handleEnterEvent(enter, local, global);
245 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FocusWindowEvent, Delivery>(window, r);
251 if (oldState < Qt::WindowNoState)
252 oldState = window->windowStates();
254 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowStateChangedEvent, Delivery>(window, newState, Qt::WindowStates(oldState));
259 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowScreenChangedEvent, Delivery>(window, screen);
264 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent, Delivery>(window);
270 handleWindowSystemEvent<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent, Delivery>(window);
275 Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
276 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent, Delivery>(newState, forcePropagate);
281 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent, Delivery>(
282 QWindowSystemInterfacePrivate::ApplicationTermination);
285QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow *window,
const QRect &newGeometry)
286 : WindowSystemEvent(GeometryChange)
288 , newGeometry(newGeometry)
290 if (
const QPlatformWindow *pw = window->handle()) {
291 const auto nativeGeometry = pw->QPlatformWindow::geometry();
292 requestedGeometry = QHighDpi::fromNativeWindowGeometry(nativeGeometry, window);
299 const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window);
300 if (window->handle()) {
302 window->handle()->QPlatformWindow::setGeometry(newRect);
307 handleWindowSystemEvent<QWindowSystemInterfacePrivate::GeometryChangeEvent, Delivery>(window, newRectDi);
310QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window,
const QRegion ®ion)
311 : WindowSystemEvent(Expose)
313 , isExposed(window && window->handle() ? window->handle()->isExposed() :
false)
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
337 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ExposeEvent, Delivery>(window,
338 QHighDpi::fromNativeLocalExposedRegion(region, window));
343 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::PaintEvent, Delivery>(window,
344 QHighDpi::fromNativeLocalExposedRegion(region, window));
351 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::CloseEvent, Delivery>(window);
355
356
357
358
361 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
362 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
363 Qt::MouseEventSource source)
365 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
366 return handleMouseEvent<Delivery>(window, time, local, global, state, button, type, mods, source);
370 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
371 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
372 Qt::MouseEventSource source)
374 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
375 return handleMouseEvent<Delivery>(window, time, device, local, global, state, button, type, mods, source);
379 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
380 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
381 Qt::MouseEventSource source)
383 return handleMouseEvent<Delivery>(window, timestamp, QPointingDevice::primaryPointingDevice(),
384 local, global, state, button, type, mods, source);
388 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
389 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
390 Qt::MouseEventSource source)
393 bool isNonClientArea = {};
396 case QEvent::MouseButtonDblClick:
397 case QEvent::NonClientAreaMouseButtonDblClick:
398 Q_ASSERT_X(
false,
"QWindowSystemInterface::handleMouseEvent",
399 "QTBUG-71263: Native double clicks are not implemented.");
401 case QEvent::MouseMove:
402 case QEvent::MouseButtonPress:
403 case QEvent::MouseButtonRelease:
404 isNonClientArea =
false;
406 case QEvent::NonClientAreaMouseMove:
407 case QEvent::NonClientAreaMouseButtonPress:
408 case QEvent::NonClientAreaMouseButtonRelease:
409 isNonClientArea =
true;
415 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
416 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
418 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::MouseEvent, Delivery>(window,
419 timestamp, localPos, globalPos, state, mods, button, type, source, isNonClientArea, device);
422bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp,
int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
423 quint32 nativeVirtualKey, quint32 nativeModifiers,
const QString &text,
bool autorepeat, ushort count)
425#if QT_CONFIG(shortcut)
427 window = QGuiApplication::focusWindow();
429 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
430 if (shortcutMap.state() == QKeySequence::NoMatch) {
436 bool overridden = handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, SynchronousDelivery>
437 (window,timestamp, QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
438 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
446 QKeyEvent keyEvent(QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
447 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
449 return shortcutMap.tryShortcut(&keyEvent);
455 Q_UNUSED(nativeScanCode);
456 Q_UNUSED(nativeVirtualKey);
457 Q_UNUSED(nativeModifiers);
459 Q_UNUSED(autorepeat);
465QT_DEFINE_QPA_EVENT_HANDLER(
bool, handleKeyEvent, QWindow *window, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text,
bool autorep, ushort count) {
466 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
467 return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count);
470QT_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)
472 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, Delivery>(window,
473 timestamp, t, k, mods, text, autorep, count);
476bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type,
int key, Qt::KeyboardModifiers modifiers,
477 quint32 nativeScanCode, quint32 nativeVirtualKey,
478 quint32 nativeModifiers,
479 const QString& text,
bool autorep,
482 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
483 return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
484 text, autorep, count);
487bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type,
int key,
488 Qt::KeyboardModifiers modifiers,
489 quint32 nativeScanCode, quint32 nativeVirtualKey,
490 quint32 nativeModifiers,
491 const QString& text,
bool autorep,
494 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent>(window,
495 timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
498bool QWindowSystemInterface::handleWheelEvent(QWindow *window,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
500 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
501 return handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source);
504bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
505 Qt::MouseEventSource source,
bool invertedScrolling)
507 return handleWheelEvent(window, timestamp, QPointingDevice::primaryPointingDevice(), local, global,
508 pixelDelta, angleDelta, mods, phase, source, invertedScrolling);
511bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
512 const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta,
513 Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
514 Qt::MouseEventSource source,
bool invertedScrolling)
526 if (angleDelta.isNull() && phase == Qt::ScrollUpdate)
530 if (angleDelta.y() != 0 && angleDelta.x() == 0) {
531 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
532 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
533 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
537 if (angleDelta.y() == 0 && angleDelta.x() != 0) {
538 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
539 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
540 pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
548 acceptVert = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
549 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
550 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
554 acceptHorz = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
555 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
556 QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
558 return acceptVert || acceptHorz;
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577void QWindowSystemInterface::registerInputDevice(
const QInputDevice *device)
579 QInputDevicePrivate::registerDevice(device);
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
610 QWindowSystemInterfacePrivate::fromNativeTouchPoints(
const QList<QWindowSystemInterface::TouchPoint> &points,
611 const QWindow *window, QEvent::Type *type)
613 QList<QEventPoint> touchPoints;
614 QEventPoint::States states;
616 touchPoints.reserve(points.size());
617 QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
618 QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
619 while (point != end) {
620 QPointF globalPos = QHighDpi::fromNativePixels(point->area.center(), window);
621 QEventPoint p(point->id, point->state, globalPos, globalPos);
622 states |= point->state;
623 if (point->uniqueId >= 0)
624 QMutableEventPoint::setUniqueId(p, QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
625 QMutableEventPoint::setPressure(p, point->pressure);
626 QMutableEventPoint::setRotation(p, point->rotation);
627 QMutableEventPoint::setEllipseDiameters(p, QHighDpi::fromNativePixels(point->area.size(), window));
628 QMutableEventPoint::setVelocity(p, QHighDpi::fromNativePixels(point->velocity, window));
633 touchPoints.append(p);
639 *type = QEvent::TouchUpdate;
640 if (states == QEventPoint::State::Pressed)
641 *type = QEvent::TouchBegin;
642 else if (states == QEventPoint::State::Released)
643 *type = QEvent::TouchEnd;
649QWindowSystemInterface::TouchPoint
650QWindowSystemInterfacePrivate::toNativeTouchPoint(
const QEventPoint &pt,
const QWindow *window)
652 QWindowSystemInterface::TouchPoint p;
654 QRectF area(QPointF(), pt.ellipseDiameters());
655 area.moveCenter(pt.globalPosition());
657 p.area = QHighDpi::toNativePixels(area, window);
658 p.pressure = pt.pressure();
659 p.state = pt.state();
660 p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
665 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
667 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
668 return handleTouchEvent<Delivery>(window, time, device, points, mods);
672 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
677 if (!QPointingDevicePrivate::isRegistered(device))
681 QList<QEventPoint> touchPoints =
682 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
684 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
685 timestamp, type, device, touchPoints, mods);
689 Qt::KeyboardModifiers mods)
691 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
692 return handleTouchCancelEvent<Delivery>(window, time, device, mods);
696 Qt::KeyboardModifiers mods)
698 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
699 timestamp, QEvent::TouchCancel, device, QList<QEventPoint>(), mods);
703
704
705
706
707
708
709
710
711
712
713void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *platformScreen,
bool isPrimary)
715 QScreen *screen =
new QScreen(platformScreen);
718 QGuiApplicationPrivate::screen_list.prepend(screen);
720 QGuiApplicationPrivate::screen_list.append(screen);
722 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
723 QHighDpiScaling::updateHighDpiScaling();
724 screen->d_func()->updateGeometry();
726 emit qGuiApp->screenAdded(screen);
729 emit qGuiApp->primaryScreenChanged(screen);
733
734
735
736
737
738
739
740void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen)
742 QScreen *screen = platformScreen->screen();
745 const bool wasPrimary = QGuiApplication::primaryScreen() == screen;
746 QGuiApplicationPrivate::screen_list.removeOne(screen);
747 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
750 QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
751 if (wasPrimary && newPrimaryScreen)
752 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
756 emit qApp->screenRemoved(screen);
758 if (!QGuiApplication::closingDown()) {
759 bool movingFromVirtualSibling = newPrimaryScreen
760 && newPrimaryScreen->handle()->virtualSiblings().contains(platformScreen);
763 const auto allWindows = QGuiApplication::allWindows();
764 for (QWindow *window : allWindows) {
765 if (!window->isTopLevel() || window->screen() != screen)
768 const bool wasVisible = window->isVisible();
769 window->setScreen(newPrimaryScreen);
773 if (movingFromVirtualSibling)
774 window->setVisible(wasVisible);
781 delete platformScreen;
785
786
787
788
789
790void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
792 QScreen *newPrimaryScreen = newPrimary->screen();
793 qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
794 Q_ASSERT(indexOfScreen >= 0);
795 if (indexOfScreen == 0)
798 QGuiApplicationPrivate::screen_list.swapItemsAt(0, indexOfScreen);
799 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
802void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
804 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenOrientationEvent>(screen, orientation);
807void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen,
const QRect &geometry,
const QRect &availableGeometry)
809 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenGeometryEvent>(screen,
810 QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry,
811 screen, geometry.topLeft()));
814void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
819 QHighDpiScaling::updateHighDpiScaling();
821 const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
822 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent>(screen,
823 effectiveDpi.first, effectiveDpi.second);
826void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
828 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent>(screen, newRefreshRate);
833 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ThemeChangeEvent, Delivery>(window);
836#if QT_CONFIG(draganddrop)
838
839
840
841
842
843
844QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window,
const QMimeData *dropData,
845 const QPoint &p, Qt::DropActions supportedActions,
846 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
848 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
849 return QGuiApplicationPrivate::processDrag(window, dropData, pos, supportedActions, buttons, modifiers);
852QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window,
const QMimeData *dropData,
853 const QPoint &p, Qt::DropActions supportedActions,
854 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
856 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
857 return QGuiApplicationPrivate::processDrop(window, dropData, pos, supportedActions, buttons, modifiers);
862
863
864
865
866
868bool QWindowSystemInterface::handleNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
870 return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
873void QWindowSystemInterface::handleFileOpenEvent(
const QString& fileName)
875 QWindowSystemInterfacePrivate::FileOpenEvent e(fileName);
876 QGuiApplicationPrivate::processWindowSystemEvent(&e);
879void QWindowSystemInterface::handleFileOpenEvent(
const QUrl &url)
881 QWindowSystemInterfacePrivate::FileOpenEvent e(url);
882 QGuiApplicationPrivate::processWindowSystemEvent(&e);
885void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
bool v)
887 platformSynthesizesMouse = v;
890bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
891 const QPointF &local,
const QPointF &global,
892 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
893 qreal tangentialPressure, qreal rotation,
int z,
894 Qt::KeyboardModifiers modifiers)
896 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEvent>(window,
898 QHighDpi::fromNativeLocalPosition(local, window),
899 QHighDpi::fromNativeGlobalPosition(global, window),
900 device, buttons, pressure,
901 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
904bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointingDevice *device,
905 const QPointF &local,
const QPointF &global,
906 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
907 qreal tangentialPressure, qreal rotation,
int z,
908 Qt::KeyboardModifiers modifiers)
910 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
911 return handleTabletEvent(window, time, device, local, global,
912 buttons, pressure, xTilt, yTilt, tangentialPressure,
913 rotation, z, modifiers);
916bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global,
917 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
918 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
919 Qt::KeyboardModifiers modifiers)
921 const QPointingDevice *dev = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
922 QPointingDeviceUniqueId::fromNumericId(uid));
923 return handleTabletEvent(window, timestamp, dev, local, global, buttons, pressure,
924 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
927bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointF &local,
const QPointF &global,
928 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
929 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
930 Qt::KeyboardModifiers modifiers)
932 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
933 return handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
934 xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
937bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
938 bool inProximity,
const QPointF &local,
const QPointF &global,
939 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
940 qreal tangentialPressure, qreal rotation,
int z,
941 Qt::KeyboardModifiers modifiers)
949 Q_UNUSED(tangentialPressure);
954 ? handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device)
955 : handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
958bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window,
const QPointingDevice *device,
959 bool inProximity,
const QPointF &local,
const QPointF &global,
960 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
961 qreal tangentialPressure, qreal rotation,
int z,
962 Qt::KeyboardModifiers modifiers)
964 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
965 return handleTabletEnterLeaveProximityEvent(window, time, device, inProximity,
966 local, global, buttons, xTilt, yTilt,
967 tangentialPressure, rotation, z, modifiers);
971bool QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
973 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
974 QPointingDevice::PointerType(pointerType),
975 QPointingDeviceUniqueId::fromNumericId(uid));
976 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device);
979void QWindowSystemInterface::handleTabletEnterProximityEvent(
int deviceType,
int pointerType, qint64 uid)
981 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
982 handleTabletEnterProximityEvent(time, deviceType, pointerType, uid);
985bool QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
987 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
988 QPointingDevice::PointerType(pointerType),
989 QPointingDeviceUniqueId::fromNumericId(uid));
990 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
993void QWindowSystemInterface::handleTabletLeaveProximityEvent(
int deviceType,
int pointerType, qint64 uid)
995 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
996 handleTabletLeaveProximityEvent(time, deviceType, pointerType, uid);
999#ifndef QT_NO_GESTURES
1000bool QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1001 Qt::NativeGestureType type,
const QPointF &local,
const QPointF &global,
int fingerCount)
1003 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, {}, {}, local, global, fingerCount);
1006bool QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1007 Qt::NativeGestureType type, qreal value,
const QPointF &local,
const QPointF &global,
int fingerCount)
1009 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, value, {}, local, global, fingerCount);
1012bool QWindowSystemInterface::handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1013 Qt::NativeGestureType type, qreal value,
const QPointF &delta,
1014 const QPointF &local,
const QPointF &global,
int fingerCount)
1016 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
1017 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
1019 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::GestureEvent>(window,
1020 timestamp, type, device, fingerCount, localPos, globalPos, value, delta);
1024void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
1026 handleWindowSystemEvent<QWindowSystemInterfacePrivate::PlatformPanelEvent>(w);
1029#ifndef QT_NO_CONTEXTMENU
1031 const QPoint &pos,
const QPoint &globalPos,
1032 Qt::KeyboardModifiers modifiers)
1034 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ContextMenuEvent, Delivery>(
1035 window, mouseTriggered, pos, globalPos, modifiers);
1039#if QT_CONFIG(whatsthis)
1040void QWindowSystemInterface::handleEnterWhatsThisEvent()
1042 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent>(
1043 QWindowSystemInterfacePrivate::EnterWhatsThisMode);
1047#ifndef QT_NO_DEBUG_STREAM
1048Q_GUI_EXPORT
QDebug operator<<(QDebug dbg,
const QWindowSystemInterface::TouchPoint &p)
1050 QDebugStateSaver saver(dbg);
1051 dbg.nospace() <<
"TouchPoint(" << p.id <<
" @" << p.area <<
" normalized " << p.normalPosition
1052 <<
" press " << p.pressure <<
" vel " << p.velocity <<
" state " << (
int)p.state;
1060
1061
1062
1063bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1065 const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
1068 if (!QGuiApplication::instance()) {
1069 qWarning().nospace()
1070 <<
"QWindowSystemInterface::flushWindowSystemEvents() invoked after "
1071 "QGuiApplication destruction, discarding " << count <<
" events.";
1072 QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
1075 if (QThread::currentThread() != QGuiApplication::instance()->thread()) {
1078 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1079 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FlushEventsEvent, AsynchronousDelivery>(flags);
1080 QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
1082 sendWindowSystemEvents(flags);
1084 return QWindowSystemInterfacePrivate::eventAccepted.loadRelaxed() > 0;
1087void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1089 Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread());
1091 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1092 sendWindowSystemEvents(flags);
1093 QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
1096bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1100 while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
1101 QWindowSystemInterfacePrivate::WindowSystemEvent *event =
1102 flags & QEventLoop::ExcludeUserInputEvents ?
1103 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
1104 QWindowSystemInterfacePrivate::getWindowSystemEvent();
1108 if (QWindowSystemInterfacePrivate::eventHandler) {
1109 if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
1113 QGuiApplicationPrivate::processWindowSystemEvent(event);
1119 if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
1120 QWindowSystemInterfacePrivate::eventAccepted.storeRelaxed(event->eventAccepted);
1125 return (nevents > 0);
1128void QWindowSystemInterface::setSynchronousWindowSystemEvents(
bool enable)
1130 QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
1133int QWindowSystemInterface::windowSystemEventsQueued()
1135 return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
1138bool QWindowSystemInterface::nonUserInputEventsQueued()
1140 return QWindowSystemInterfacePrivate::nonUserInputEventsQueued();
1151 Qt::MouseButtons state, Qt::MouseButton button,
1152 QEvent::Type type, Qt::KeyboardModifiers mods,
int timestamp)
1154 QPointF nativeLocal =
QHighDpi::toNativeLocalPosition(local, window);
1155 QPointF nativeGlobal =
QHighDpi::toNativeGlobalPosition(global, window);
1156 QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
1157 timestamp, nativeLocal, nativeGlobal, state, button, type, mods);
1161
1162
1163Q_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)
1165#if defined(Q_OS_MACOS)
1167 auto timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
1168 if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
1172 QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
1175Q_GUI_EXPORT
bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp,
int k, Qt::KeyboardModifiers mods,
const QString &text = QString(),
bool autorep =
false, ushort count = 1)
1177#if QT_CONFIG(shortcut)
1185 QGuiApplicationPrivate::modifier_buttons = mods;
1187 QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count);
1188 qevent.setTimestamp(timestamp);
1190 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
1191 if (shortcutMap.state() == QKeySequence::NoMatch) {
1193 QCoreApplication::sendEvent(o, &qevent);
1194 if (qevent.isAccepted())
1199 return shortcutMap.tryShortcut(&qevent);
1202 Q_UNUSED(timestamp);
1213 QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
1214 Qt::ScrollPhase phase)
1216 QWindowSystemInterface::handleWheelEvent(window, local, global, pixelDelta, angleDelta, mods, phase);
1234 const QList<QEventPoint> &points,
1235 Qt::KeyboardModifiers mods)
1237 return QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
1238 QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
1242 const QList<QEventPoint> &points,
1243 Qt::KeyboardModifiers mods)
1245 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,...)
QPointer< QWindow > qt_last_mouse_receiver
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 ...)