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,
286 QRect requestedGeometry,
288 : WindowSystemEvent(GeometryChange)
290 , requestedGeometry(requestedGeometry)
291 , newGeometry(newGeometry)
298 const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window);
299 QRect requestedGeometry;
300 if (
auto *handle = window->handle()) {
301 requestedGeometry = QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(),
304 handle->QPlatformWindow::setGeometry(newRect);
309 handleWindowSystemEvent<QWindowSystemInterfacePrivate::GeometryChangeEvent, Delivery>(window,
314QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window,
const QRegion ®ion)
315 : WindowSystemEvent(Expose)
317 , isExposed(window && window->handle() ? window->handle()->isExposed() :
false)
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
341 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ExposeEvent, Delivery>(window,
342 QHighDpi::fromNativeLocalExposedRegion(region, window));
347 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::PaintEvent, Delivery>(window,
348 QHighDpi::fromNativeLocalExposedRegion(region, window));
355 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::CloseEvent, Delivery>(window);
359
360
361
362
365 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
366 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
367 Qt::MouseEventSource source)
369 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
370 return handleMouseEvent<Delivery>(window, time, local, global, state, button, type, mods, source);
374 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
375 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
376 Qt::MouseEventSource source)
378 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
379 return handleMouseEvent<Delivery>(window, time, device, local, global, state, button, type, mods, source);
383 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
384 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
385 Qt::MouseEventSource source)
387 return handleMouseEvent<Delivery>(window, timestamp, QPointingDevice::primaryPointingDevice(),
388 local, global, state, button, type, mods, source);
392 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
393 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
394 Qt::MouseEventSource source)
397 bool isNonClientArea = {};
400 case QEvent::MouseButtonDblClick:
401 case QEvent::NonClientAreaMouseButtonDblClick:
402 Q_ASSERT_X(
false,
"QWindowSystemInterface::handleMouseEvent",
403 "QTBUG-71263: Native double clicks are not implemented.");
405 case QEvent::MouseMove:
406 case QEvent::MouseButtonPress:
407 case QEvent::MouseButtonRelease:
408 isNonClientArea =
false;
410 case QEvent::NonClientAreaMouseMove:
411 case QEvent::NonClientAreaMouseButtonPress:
412 case QEvent::NonClientAreaMouseButtonRelease:
413 isNonClientArea =
true;
419 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
420 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
422 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::MouseEvent, Delivery>(window,
423 timestamp, localPos, globalPos, state, mods, button, type, source, isNonClientArea, device);
426bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp,
int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
427 quint32 nativeVirtualKey, quint32 nativeModifiers,
const QString &text,
bool autorepeat, ushort count)
429#if QT_CONFIG(shortcut)
431 window = QGuiApplication::focusWindow();
433 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
434 if (shortcutMap.state() == QKeySequence::NoMatch) {
440 bool overridden = handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, SynchronousDelivery>
441 (window,timestamp, QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
442 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
450 QKeyEvent keyEvent(QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
451 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
453 return shortcutMap.tryShortcut(&keyEvent);
459 Q_UNUSED(nativeScanCode);
460 Q_UNUSED(nativeVirtualKey);
461 Q_UNUSED(nativeModifiers);
463 Q_UNUSED(autorepeat);
469QT_DEFINE_QPA_EVENT_HANDLER(
bool, handleKeyEvent, QWindow *window, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text,
bool autorep, ushort count) {
470 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
471 return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count);
474QT_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)
476 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, Delivery>(window,
477 timestamp, t, k, mods, text, autorep, count);
480bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type,
int key, Qt::KeyboardModifiers modifiers,
481 quint32 nativeScanCode, quint32 nativeVirtualKey,
482 quint32 nativeModifiers,
483 const QString& text,
bool autorep,
486 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
487 return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
488 text, autorep, count);
491bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type,
int key,
492 Qt::KeyboardModifiers modifiers,
493 quint32 nativeScanCode, quint32 nativeVirtualKey,
494 quint32 nativeModifiers,
495 const QString& text,
bool autorep,
498 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent>(window,
499 timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
502bool QWindowSystemInterface::handleWheelEvent(QWindow *window,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
504 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
505 return handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source);
508bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
509 Qt::MouseEventSource source,
bool invertedScrolling)
511 return handleWheelEvent(window, timestamp, QPointingDevice::primaryPointingDevice(), local, global,
512 pixelDelta, angleDelta, mods, phase, source, invertedScrolling);
515bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
516 const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta,
517 Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
518 Qt::MouseEventSource source,
bool invertedScrolling)
530 if (angleDelta.isNull() && phase == Qt::ScrollUpdate)
534 if (angleDelta.y() != 0 && angleDelta.x() == 0) {
535 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
536 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
537 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
541 if (angleDelta.y() == 0 && angleDelta.x() != 0) {
542 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
543 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
544 pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
552 acceptVert = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
553 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
554 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
558 acceptHorz = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
559 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
560 QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
562 return acceptVert || acceptHorz;
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581void QWindowSystemInterface::registerInputDevice(
const QInputDevice *device)
583 QInputDevicePrivate::registerDevice(device);
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
614 QWindowSystemInterfacePrivate::fromNativeTouchPoints(
const QList<QWindowSystemInterface::TouchPoint> &points,
615 const QWindow *window, QEvent::Type *type)
617 QList<QEventPoint> touchPoints;
618 QEventPoint::States states;
620 touchPoints.reserve(points.size());
621 QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
622 QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
623 while (point != end) {
624 QPointF globalPos = QHighDpi::fromNativePixels(point->area.center(), window);
625 QEventPoint p(point->id, point->state, globalPos, globalPos);
626 states |= point->state;
627 if (point->uniqueId >= 0)
628 QMutableEventPoint::setUniqueId(p, QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
629 QMutableEventPoint::setPressure(p, point->pressure);
630 QMutableEventPoint::setRotation(p, point->rotation);
631 QMutableEventPoint::setEllipseDiameters(p, QHighDpi::fromNativePixels(point->area.size(), window));
632 QMutableEventPoint::setVelocity(p, QHighDpi::fromNativePixels(point->velocity, window));
637 touchPoints.append(p);
643 *type = QEvent::TouchUpdate;
644 if (states == QEventPoint::State::Pressed)
645 *type = QEvent::TouchBegin;
646 else if (states == QEventPoint::State::Released)
647 *type = QEvent::TouchEnd;
653QWindowSystemInterface::TouchPoint
654QWindowSystemInterfacePrivate::toNativeTouchPoint(
const QEventPoint &pt,
const QWindow *window)
656 QWindowSystemInterface::TouchPoint p;
658 QRectF area(QPointF(), pt.ellipseDiameters());
659 area.moveCenter(pt.globalPosition());
661 p.area = QHighDpi::toNativePixels(area, window);
662 p.pressure = pt.pressure();
663 p.state = pt.state();
664 p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
669 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
671 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
672 return handleTouchEvent<Delivery>(window, time, device, points, mods);
676 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
681 if (!QPointingDevicePrivate::isRegistered(device))
685 QList<QEventPoint> touchPoints =
686 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
688 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
689 timestamp, type, device, touchPoints, mods);
693 Qt::KeyboardModifiers mods)
695 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
696 return handleTouchCancelEvent<Delivery>(window, time, device, mods);
700 Qt::KeyboardModifiers mods)
702 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
703 timestamp, QEvent::TouchCancel, device, QList<QEventPoint>(), mods);
707
708
709
710
711
712
713
714
715
716
717void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *platformScreen,
bool isPrimary)
719 QScreen *screen =
new QScreen(platformScreen);
722 QGuiApplicationPrivate::screen_list.prepend(screen);
724 QGuiApplicationPrivate::screen_list.append(screen);
726 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
727 QHighDpiScaling::updateHighDpiScaling();
728 screen->d_func()->updateGeometry();
730 emit qGuiApp->screenAdded(screen);
733 emit qGuiApp->primaryScreenChanged(screen);
737
738
739
740
741
742
743
744void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen)
746 QScreen *screen = platformScreen->screen();
749 const bool wasPrimary = QGuiApplication::primaryScreen() == screen;
750 QGuiApplicationPrivate::screen_list.removeOne(screen);
751 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
754 QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
755 if (wasPrimary && newPrimaryScreen)
756 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
760 emit qApp->screenRemoved(screen);
762 if (!QGuiApplication::closingDown()) {
763 bool movingFromVirtualSibling = newPrimaryScreen
764 && newPrimaryScreen->handle()->virtualSiblings().contains(platformScreen);
767 const auto allWindows = QGuiApplication::allWindows();
768 for (QWindow *window : allWindows) {
769 if (!window->isTopLevel() || window->screen() != screen)
772 const bool wasVisible = window->isVisible();
773 window->setScreen(newPrimaryScreen);
777 if (movingFromVirtualSibling)
778 window->setVisible(wasVisible);
785 delete platformScreen;
789
790
791
792
793
794void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
796 QScreen *newPrimaryScreen = newPrimary->screen();
797 qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
798 Q_ASSERT(indexOfScreen >= 0);
799 if (indexOfScreen == 0)
802 QGuiApplicationPrivate::screen_list.swapItemsAt(0, indexOfScreen);
803 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
806void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
808 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenOrientationEvent>(screen, orientation);
811void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen,
const QRect &geometry,
const QRect &availableGeometry)
813 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenGeometryEvent>(screen,
814 QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry,
815 screen, geometry.topLeft()));
818void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
823 QHighDpiScaling::updateHighDpiScaling();
825 const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
826 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent>(screen,
827 effectiveDpi.first, effectiveDpi.second);
830void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
832 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent>(screen, newRefreshRate);
837 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ThemeChangeEvent, Delivery>();
840#if QT_CONFIG(draganddrop)
842
843
844
845
846
847
848QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window,
const QMimeData *dropData,
849 const QPoint &p, Qt::DropActions supportedActions,
850 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
852 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
853 return QGuiApplicationPrivate::processDrag(window, dropData, pos, supportedActions, buttons, modifiers);
856QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window,
const QMimeData *dropData,
857 const QPoint &p, Qt::DropActions supportedActions,
858 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
860 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
861 return QGuiApplicationPrivate::processDrop(window, dropData, pos, supportedActions, buttons, modifiers);
866
867
868
869
870
872bool QWindowSystemInterface::handleNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
874 return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
877void QWindowSystemInterface::handleFileOpenEvent(
const QString& fileName)
879 QWindowSystemInterfacePrivate::FileOpenEvent e(fileName);
880 QGuiApplicationPrivate::processWindowSystemEvent(&e);
883void QWindowSystemInterface::handleFileOpenEvent(
const QUrl &url)
885 QWindowSystemInterfacePrivate::FileOpenEvent e(url);
886 QGuiApplicationPrivate::processWindowSystemEvent(&e);
889void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
bool v)
891 platformSynthesizesMouse = v;
894bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
895 const QPointF &local,
const QPointF &global,
896 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
897 qreal tangentialPressure, qreal rotation,
int z,
898 Qt::KeyboardModifiers modifiers)
900 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEvent>(window,
902 QHighDpi::fromNativeLocalPosition(local, window),
903 QHighDpi::fromNativeGlobalPosition(global, window),
904 device, buttons, pressure,
905 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
908bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointingDevice *device,
909 const QPointF &local,
const QPointF &global,
910 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
911 qreal tangentialPressure, qreal rotation,
int z,
912 Qt::KeyboardModifiers modifiers)
914 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
915 return handleTabletEvent(window, time, device, local, global,
916 buttons, pressure, xTilt, yTilt, tangentialPressure,
917 rotation, z, modifiers);
920bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global,
921 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
922 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
923 Qt::KeyboardModifiers modifiers)
925 const QPointingDevice *dev = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
926 QPointingDeviceUniqueId::fromNumericId(uid));
927 return handleTabletEvent(window, timestamp, dev, local, global, buttons, pressure,
928 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
931bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointF &local,
const QPointF &global,
932 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
933 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
934 Qt::KeyboardModifiers modifiers)
936 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
937 return handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
938 xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
941bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
942 bool inProximity,
const QPointF &local,
const QPointF &global,
943 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
944 qreal tangentialPressure, qreal rotation,
int z,
945 Qt::KeyboardModifiers modifiers)
953 Q_UNUSED(tangentialPressure);
958 ? handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device)
959 : handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
962bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window,
const QPointingDevice *device,
963 bool inProximity,
const QPointF &local,
const QPointF &global,
964 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
965 qreal tangentialPressure, qreal rotation,
int z,
966 Qt::KeyboardModifiers modifiers)
968 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
969 return handleTabletEnterLeaveProximityEvent(window, time, device, inProximity,
970 local, global, buttons, xTilt, yTilt,
971 tangentialPressure, rotation, z, modifiers);
975bool QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
977 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
978 QPointingDevice::PointerType(pointerType),
979 QPointingDeviceUniqueId::fromNumericId(uid));
980 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device);
983void QWindowSystemInterface::handleTabletEnterProximityEvent(
int deviceType,
int pointerType, qint64 uid)
985 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
986 handleTabletEnterProximityEvent(time, deviceType, pointerType, uid);
989bool QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
991 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
992 QPointingDevice::PointerType(pointerType),
993 QPointingDeviceUniqueId::fromNumericId(uid));
994 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
997void QWindowSystemInterface::handleTabletLeaveProximityEvent(
int deviceType,
int pointerType, qint64 uid)
999 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
1000 handleTabletLeaveProximityEvent(time, deviceType, pointerType, uid);
1003#ifndef QT_NO_GESTURES
1004bool QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1005 Qt::NativeGestureType type,
const QPointF &local,
const QPointF &global,
int fingerCount)
1007 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, {}, {}, local, global, fingerCount);
1010bool QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1011 Qt::NativeGestureType type, qreal value,
const QPointF &local,
const QPointF &global,
int fingerCount)
1013 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, value, {}, local, global, fingerCount);
1016bool QWindowSystemInterface::handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1017 Qt::NativeGestureType type, qreal value,
const QPointF &delta,
1018 const QPointF &local,
const QPointF &global,
int fingerCount)
1020 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
1021 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
1023 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::GestureEvent>(window,
1024 timestamp, type, device, fingerCount, localPos, globalPos, value, delta);
1028void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
1030 handleWindowSystemEvent<QWindowSystemInterfacePrivate::PlatformPanelEvent>(w);
1033#ifndef QT_NO_CONTEXTMENU
1035 const QPoint &pos,
const QPoint &globalPos,
1036 Qt::KeyboardModifiers modifiers)
1038 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ContextMenuEvent, Delivery>(
1039 window, mouseTriggered, pos, globalPos, modifiers);
1043#if QT_CONFIG(whatsthis)
1044void QWindowSystemInterface::handleEnterWhatsThisEvent()
1046 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent>(
1047 QWindowSystemInterfacePrivate::EnterWhatsThisMode);
1051#ifndef QT_NO_DEBUG_STREAM
1052Q_GUI_EXPORT
QDebug operator<<(QDebug dbg,
const QWindowSystemInterface::TouchPoint &p)
1054 QDebugStateSaver saver(dbg);
1055 dbg.nospace() <<
"TouchPoint(" << p.id <<
" @" << p.area <<
" normalized " << p.normalPosition
1056 <<
" press " << p.pressure <<
" vel " << p.velocity <<
" state " << (
int)p.state;
1064
1065
1066
1067bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1069 const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
1072 if (!QGuiApplication::instance()) {
1073 qWarning().nospace()
1074 <<
"QWindowSystemInterface::flushWindowSystemEvents() invoked after "
1075 "QGuiApplication destruction, discarding " << count <<
" events.";
1076 QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
1079 if (QThread::currentThread() != QGuiApplication::instance()->thread()) {
1082 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1083 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FlushEventsEvent, AsynchronousDelivery>(flags);
1084 QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
1086 sendWindowSystemEvents(flags);
1088 return QWindowSystemInterfacePrivate::eventAccepted.loadRelaxed() > 0;
1091void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1093 Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread());
1095 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1096 sendWindowSystemEvents(flags);
1097 QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
1100bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1104 while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
1105 QWindowSystemInterfacePrivate::WindowSystemEvent *event =
1106 flags & QEventLoop::ExcludeUserInputEvents ?
1107 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
1108 QWindowSystemInterfacePrivate::getWindowSystemEvent();
1112 if (QWindowSystemInterfacePrivate::eventHandler) {
1113 if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
1117 QGuiApplicationPrivate::processWindowSystemEvent(event);
1123 if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
1124 QWindowSystemInterfacePrivate::eventAccepted.storeRelaxed(event->eventAccepted);
1129 return (nevents > 0);
1132void QWindowSystemInterface::setSynchronousWindowSystemEvents(
bool enable)
1134 QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
1137int QWindowSystemInterface::windowSystemEventsQueued()
1139 return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
1142bool QWindowSystemInterface::nonUserInputEventsQueued()
1144 return QWindowSystemInterfacePrivate::nonUserInputEventsQueued();
1155 Qt::MouseButtons state, Qt::MouseButton button,
1156 QEvent::Type type, Qt::KeyboardModifiers mods,
int timestamp)
1158 QPointF nativeLocal =
QHighDpi::toNativeLocalPosition(local, window);
1159 QPointF nativeGlobal =
QHighDpi::toNativeGlobalPosition(global, window);
1160 QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
1161 timestamp, nativeLocal, nativeGlobal, state, button, type, mods);
1165
1166
1167Q_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)
1169#if defined(Q_OS_MACOS)
1171 auto timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
1172 if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
1176 QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
1179Q_GUI_EXPORT
bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp,
int k, Qt::KeyboardModifiers mods,
const QString &text = QString(),
bool autorep =
false, ushort count = 1)
1181#if QT_CONFIG(shortcut)
1189 QGuiApplicationPrivate::modifier_buttons = mods;
1191 QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count);
1192 qevent.setTimestamp(timestamp);
1194 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
1195 if (shortcutMap.state() == QKeySequence::NoMatch) {
1197 QCoreApplication::sendEvent(o, &qevent);
1198 if (qevent.isAccepted())
1203 return shortcutMap.tryShortcut(&qevent);
1206 Q_UNUSED(timestamp);
1217 QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
1218 Qt::ScrollPhase phase)
1220 QWindowSystemInterface::handleWheelEvent(window, local, global, pixelDelta, angleDelta, mods, phase);
1238 const QList<QEventPoint> &points,
1239 Qt::KeyboardModifiers mods)
1241 return QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
1242 QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
1246 const QList<QEventPoint> &points,
1247 Qt::KeyboardModifiers mods)
1249 qt_handleTouchEventv2(window, device, points, mods);
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 ...)