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;
45
46
47
48
49
50
51
52
54template<
typename Delivery>
57 template<
typename EventType,
typename ...Args>
62
63
64
65
66
67
68
69
70
71
72
73
74
75
77template<
typename EventType,
typename ...Args>
78bool QWindowSystemHelper<QWindowSystemInterface::DefaultDelivery>::handleEvent(Args ...args)
80 return QWindowSystemInterfacePrivate::synchronousWindowSystemEvents
81 ? QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent<EventType>(args...)
82 : QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
86
87
88
89
90
91
92
93
94
96template<
typename EventType,
typename ...Args>
97bool QWindowSystemHelper<QWindowSystemInterface::SynchronousDelivery>::handleEvent(Args ...args)
99 if (QThread::isMainThread()) {
100 EventType event(args...);
102 if (QWindowSystemInterfacePrivate::eventHandler) {
103 if (!QWindowSystemInterfacePrivate::eventHandler->sendEvent(&event))
106 QGuiApplicationPrivate::processWindowSystemEvent(&event);
108 return event.eventAccepted;
114 QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent<EventType>(args...);
115 return QWindowSystemInterface::flushWindowSystemEvents();
120
121
122
123
124
125
127template<
typename EventType,
typename ...Args>
128bool QWindowSystemHelper<QWindowSystemInterface::AsynchronousDelivery>::handleEvent(Args ...args)
130 QWindowSystemInterfacePrivate::windowSystemEventQueue.append(
new EventType(args...));
131 if (QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::qt_qpa_core_dispatcher())
132 dispatcher->wakeUp();
142qsizetype QWindowSystemInterfacePrivate::windowSystemEventsQueued()
144 return windowSystemEventQueue.count();
147bool QWindowSystemInterfacePrivate::nonUserInputEventsQueued()
149 return windowSystemEventQueue.nonUserInputEventsQueued();
152QWindowSystemInterfacePrivate::WindowSystemEvent * QWindowSystemInterfacePrivate::getWindowSystemEvent()
154 return windowSystemEventQueue.takeFirstOrReturnNull();
157QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent()
159 return windowSystemEventQueue.takeFirstNonUserInputOrReturnNull();
162QWindowSystemInterfacePrivate::WindowSystemEvent *QWindowSystemInterfacePrivate::peekWindowSystemEvent(EventType t)
164 return windowSystemEventQueue.peekAtFirstOfType(t);
167void QWindowSystemInterfacePrivate::removeWindowSystemEvent(WindowSystemEvent *event)
169 windowSystemEventQueue.remove(event);
172void QWindowSystemInterfacePrivate::installWindowSystemEventHandler(QWindowSystemEventHandler *handler)
175 eventHandler = handler;
178void QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(QWindowSystemEventHandler *handler)
180 if (eventHandler == handler)
181 eventHandler =
nullptr;
184QWindowSystemEventHandler::~QWindowSystemEventHandler()
186 QWindowSystemInterfacePrivate::removeWindowSystemEventhandler(
this);
189bool QWindowSystemEventHandler::sendEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e)
191 QGuiApplicationPrivate::processWindowSystemEvent(e);
200#define QT_DEFINE_QPA_EVENT_HANDLER(ReturnType, HandlerName, ...)
201 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::DefaultDelivery>(__VA_ARGS__);
202 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::SynchronousDelivery>(__VA_ARGS__);
203 template Q_GUI_EXPORT ReturnType QWindowSystemInterface::HandlerName<QWindowSystemInterface::AsynchronousDelivery>(__VA_ARGS__);
204 template<typename Delivery> ReturnType QWindowSystemInterface::HandlerName(__VA_ARGS__)
207
208
209
210
211
212
213
214
215
216
221 handleWindowSystemEvent<QWindowSystemInterfacePrivate::EnterEvent, Delivery>(window,
222 QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window));
228 handleWindowSystemEvent<QWindowSystemInterfacePrivate::LeaveEvent, Delivery>(window);
232
233
234
235
236
237
238void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave,
const QPointF &local,
const QPointF& global)
240 handleLeaveEvent<AsynchronousDelivery>(leave);
241 handleEnterEvent(enter, local, global);
246 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FocusWindowEvent, Delivery>(window, r);
252 if (oldState < Qt::WindowNoState)
253 oldState = window->windowStates();
255 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowStateChangedEvent, Delivery>(window, newState, Qt::WindowStates(oldState));
260 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowScreenChangedEvent, Delivery>(window, screen);
265 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowDevicePixelRatioChangedEvent, Delivery>(window);
271 handleWindowSystemEvent<QWindowSystemInterfacePrivate::SafeAreaMarginsChangedEvent, Delivery>(window);
276 Q_ASSERT(QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState));
277 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ApplicationStateChangedEvent, Delivery>(newState, forcePropagate);
282 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent, Delivery>(
283 QWindowSystemInterfacePrivate::ApplicationTermination);
286QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow *window,
287 QRect requestedGeometry,
289 : WindowSystemEvent(GeometryChange)
291 , requestedGeometry(requestedGeometry)
292 , newGeometry(newGeometry)
299 const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window);
300 QRect requestedGeometry;
301 if (
auto *handle = window->handle()) {
302 requestedGeometry = QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(),
305 handle->QPlatformWindow::setGeometry(newRect);
310 handleWindowSystemEvent<QWindowSystemInterfacePrivate::GeometryChangeEvent, Delivery>(window,
315QWindowSystemInterfacePrivate::ExposeEvent::ExposeEvent(QWindow *window,
const QRegion ®ion)
316 : WindowSystemEvent(Expose)
318 , isExposed(window && window->handle() ? window->handle()->isExposed() :
false)
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
342 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ExposeEvent, Delivery>(window,
343 QHighDpi::fromNativeLocalExposedRegion(region, window));
348 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::PaintEvent, Delivery>(window,
349 QHighDpi::fromNativeLocalExposedRegion(region, window));
356 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::CloseEvent, Delivery>(window);
360
361
362
363
366 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
367 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
368 Qt::MouseEventSource source)
370 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
371 return handleMouseEvent<Delivery>(window, time, local, global, state, button, type, mods, source);
375 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
376 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
377 Qt::MouseEventSource source)
379 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
380 return handleMouseEvent<Delivery>(window, time, device, local, global, state, button, type, mods, source);
384 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
385 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
386 Qt::MouseEventSource source)
388 return handleMouseEvent<Delivery>(window, timestamp, QPointingDevice::primaryPointingDevice(),
389 local, global, state, button, type, mods, source);
393 const QPointF &local,
const QPointF &global, Qt::MouseButtons state,
394 Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods,
395 Qt::MouseEventSource source)
398 bool isNonClientArea = {};
401 case QEvent::MouseButtonDblClick:
402 case QEvent::NonClientAreaMouseButtonDblClick:
403 Q_ASSERT_X(
false,
"QWindowSystemInterface::handleMouseEvent",
404 "QTBUG-71263: Native double clicks are not implemented.");
406 case QEvent::MouseMove:
407 case QEvent::MouseButtonPress:
408 case QEvent::MouseButtonRelease:
409 isNonClientArea =
false;
411 case QEvent::NonClientAreaMouseMove:
412 case QEvent::NonClientAreaMouseButtonPress:
413 case QEvent::NonClientAreaMouseButtonRelease:
414 isNonClientArea =
true;
420 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
421 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
423 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::MouseEvent, Delivery>(window,
424 timestamp, localPos, globalPos, state, mods, button, type, source, isNonClientArea, device);
427bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp,
int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode,
428 quint32 nativeVirtualKey, quint32 nativeModifiers,
const QString &text,
bool autorepeat, ushort count)
430#if QT_CONFIG(shortcut)
432 window = QGuiApplication::focusWindow();
434 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
435 if (shortcutMap.state() == QKeySequence::NoMatch) {
441 bool overridden = handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, SynchronousDelivery>
442 (window,timestamp, QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
443 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
451 QKeyEvent keyEvent(QEvent::ShortcutOverride, keyCode, modifiers, nativeScanCode,
452 nativeVirtualKey, nativeModifiers, text, autorepeat, count);
454 return shortcutMap.tryShortcut(&keyEvent);
460 Q_UNUSED(nativeScanCode);
461 Q_UNUSED(nativeVirtualKey);
462 Q_UNUSED(nativeModifiers);
464 Q_UNUSED(autorepeat);
470QT_DEFINE_QPA_EVENT_HANDLER(
bool, handleKeyEvent, QWindow *window, QEvent::Type t,
int k, Qt::KeyboardModifiers mods,
const QString & text,
bool autorep, ushort count) {
471 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
472 return handleKeyEvent<Delivery>(window, time, t, k, mods, text, autorep, count);
475QT_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)
477 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent, Delivery>(window,
478 timestamp, t, k, mods, text, autorep, count);
481bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, QEvent::Type type,
int key, Qt::KeyboardModifiers modifiers,
482 quint32 nativeScanCode, quint32 nativeVirtualKey,
483 quint32 nativeModifiers,
484 const QString& text,
bool autorep,
487 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
488 return handleExtendedKeyEvent(window, time, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers,
489 text, autorep, count);
492bool QWindowSystemInterface::handleExtendedKeyEvent(QWindow *window, ulong timestamp, QEvent::Type type,
int key,
493 Qt::KeyboardModifiers modifiers,
494 quint32 nativeScanCode, quint32 nativeVirtualKey,
495 quint32 nativeModifiers,
496 const QString& text,
bool autorep,
499 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::KeyEvent>(window,
500 timestamp, type, key, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
503bool QWindowSystemInterface::handleWheelEvent(QWindow *window,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase, Qt::MouseEventSource source)
505 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
506 return handleWheelEvent(window, time, local, global, pixelDelta, angleDelta, mods, phase, source);
509bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
510 Qt::MouseEventSource source,
bool invertedScrolling)
512 return handleWheelEvent(window, timestamp, QPointingDevice::primaryPointingDevice(), local, global,
513 pixelDelta, angleDelta, mods, phase, source, invertedScrolling);
516bool QWindowSystemInterface::handleWheelEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
517 const QPointF &local,
const QPointF &global, QPoint pixelDelta, QPoint angleDelta,
518 Qt::KeyboardModifiers mods, Qt::ScrollPhase phase,
519 Qt::MouseEventSource source,
bool invertedScrolling)
531 if (angleDelta.isNull() && phase == Qt::ScrollUpdate)
535 if (angleDelta.y() != 0 && angleDelta.x() == 0) {
536 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
537 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
538 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
542 if (angleDelta.y() == 0 && angleDelta.x() != 0) {
543 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
544 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
545 pixelDelta, angleDelta, angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
553 acceptVert = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
554 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
555 pixelDelta, angleDelta, angleDelta.y(), Qt::Vertical, mods, phase, source, invertedScrolling, device);
559 acceptHorz = handleWindowSystemEvent<QWindowSystemInterfacePrivate::WheelEvent>(window,
560 timestamp, QHighDpi::fromNativeLocalPosition(local, window), QHighDpi::fromNativeGlobalPosition(global, window),
561 QPoint(), QPoint(), angleDelta.x(), Qt::Horizontal, mods, phase, source, invertedScrolling, device);
563 return acceptVert || acceptHorz;
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582void QWindowSystemInterface::registerInputDevice(
const QInputDevice *device)
584 QInputDevicePrivate::registerDevice(device);
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
615 QWindowSystemInterfacePrivate::fromNativeTouchPoints(
const QList<QWindowSystemInterface::TouchPoint> &points,
616 const QWindow *window, QEvent::Type *type)
618 QList<QEventPoint> touchPoints;
619 QEventPoint::States states;
621 touchPoints.reserve(points.size());
622 QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
623 QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
624 while (point != end) {
625 QPointF globalPos = QHighDpi::fromNativePixels(point->area.center(), window);
626 QEventPoint p(point->id, point->state, globalPos, globalPos);
627 states |= point->state;
628 if (point->uniqueId >= 0)
629 QMutableEventPoint::setUniqueId(p, QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
630 QMutableEventPoint::setPressure(p, point->pressure);
631 QMutableEventPoint::setRotation(p, point->rotation);
632 QMutableEventPoint::setEllipseDiameters(p, QHighDpi::fromNativePixels(point->area.size(), window));
633 QMutableEventPoint::setVelocity(p, QHighDpi::fromNativePixels(point->velocity, window));
638 touchPoints.append(p);
644 *type = QEvent::TouchUpdate;
645 if (states == QEventPoint::State::Pressed)
646 *type = QEvent::TouchBegin;
647 else if (states == QEventPoint::State::Released)
648 *type = QEvent::TouchEnd;
654QWindowSystemInterface::TouchPoint
655QWindowSystemInterfacePrivate::toNativeTouchPoint(
const QEventPoint &pt,
const QWindow *window)
657 QWindowSystemInterface::TouchPoint p;
659 QRectF area(QPointF(), pt.ellipseDiameters());
660 area.moveCenter(pt.globalPosition());
662 p.area = QHighDpi::toNativePixels(area, window);
663 p.pressure = pt.pressure();
664 p.state = pt.state();
665 p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
670 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
672 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
673 return handleTouchEvent<Delivery>(window, time, device, points, mods);
677 const QList<TouchPoint> &points, Qt::KeyboardModifiers mods)
682 if (!QPointingDevicePrivate::isRegistered(device))
686 QList<QEventPoint> touchPoints =
687 QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
689 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
690 timestamp, type, device, touchPoints, mods);
694 Qt::KeyboardModifiers mods)
696 unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed();
697 return handleTouchCancelEvent<Delivery>(window, time, device, mods);
701 Qt::KeyboardModifiers mods)
703 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TouchEvent, Delivery>(window,
704 timestamp, QEvent::TouchCancel, device, QList<QEventPoint>(), mods);
708
709
710
711
712
713
714
715
716
717
718void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *platformScreen,
bool isPrimary)
720 QScreen *screen =
new QScreen(platformScreen);
723 QGuiApplicationPrivate::screen_list.prepend(screen);
725 QGuiApplicationPrivate::screen_list.append(screen);
727 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
728 QHighDpiScaling::updateHighDpiScaling();
729 screen->d_func()->updateGeometry();
731 emit qGuiApp->screenAdded(screen);
734 emit qGuiApp->primaryScreenChanged(screen);
738
739
740
741
742
743
744
745void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen)
747 QScreen *screen = platformScreen->screen();
750 const bool wasPrimary = QGuiApplication::primaryScreen() == screen;
751 QGuiApplicationPrivate::screen_list.removeOne(screen);
752 QGuiApplicationPrivate::resetCachedDevicePixelRatio();
755 QScreen *newPrimaryScreen = QGuiApplication::primaryScreen();
756 if (wasPrimary && newPrimaryScreen)
757 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
761 emit qApp->screenRemoved(screen);
763 if (!QGuiApplication::closingDown()) {
764 bool movingFromVirtualSibling = newPrimaryScreen
765 && newPrimaryScreen->handle()->virtualSiblings().contains(platformScreen);
768 const auto allWindows = QGuiApplication::allWindows();
769 for (QWindow *window : allWindows) {
770 if (!window->isTopLevel() || window->screen() != screen)
773 const bool wasVisible = window->isVisible();
774 window->setScreen(newPrimaryScreen);
778 if (movingFromVirtualSibling)
779 window->setVisible(wasVisible);
786 delete platformScreen;
790
791
792
793
794
795void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
797 QScreen *newPrimaryScreen = newPrimary->screen();
798 qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
799 Q_ASSERT(indexOfScreen >= 0);
800 if (indexOfScreen == 0)
803 QGuiApplicationPrivate::screen_list.swapItemsAt(0, indexOfScreen);
804 emit qGuiApp->primaryScreenChanged(newPrimaryScreen);
807void QWindowSystemInterface::handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation orientation)
809 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenOrientationEvent>(screen, orientation);
812void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen,
const QRect &geometry,
const QRect &availableGeometry)
814 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenGeometryEvent>(screen,
815 QHighDpi::fromNativeScreenGeometry(geometry, screen), QHighDpi::fromNative(availableGeometry,
816 screen, geometry.topLeft()));
819void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
824 QHighDpiScaling::updateHighDpiScaling();
826 const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
827 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent>(screen,
828 effectiveDpi.first, effectiveDpi.second);
831void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
833 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent>(screen, newRefreshRate);
838 handleWindowSystemEvent<QWindowSystemInterfacePrivate::ThemeChangeEvent, Delivery>();
841#if QT_CONFIG(draganddrop)
843
844
845
846
847
848
849QPlatformDragQtResponse QWindowSystemInterface::handleDrag(QWindow *window,
const QMimeData *dropData,
850 const QPoint &p, Qt::DropActions supportedActions,
851 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
853 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
854 return QGuiApplicationPrivate::processDrag(window, dropData, pos, supportedActions, buttons, modifiers);
857QPlatformDropQtResponse QWindowSystemInterface::handleDrop(QWindow *window,
const QMimeData *dropData,
858 const QPoint &p, Qt::DropActions supportedActions,
859 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
861 auto pos = QHighDpi::fromNativeLocalPosition(p, window);
862 return QGuiApplicationPrivate::processDrop(window, dropData, pos, supportedActions, buttons, modifiers);
867
868
869
870
871
873bool QWindowSystemInterface::handleNativeEvent(QWindow *window,
const QByteArray &eventType,
void *message, qintptr *result)
875 return QGuiApplicationPrivate::processNativeEvent(window, eventType, message, result);
878void QWindowSystemInterface::handleFileOpenEvent(
const QString& fileName)
880 QWindowSystemInterfacePrivate::FileOpenEvent e(fileName);
881 QGuiApplicationPrivate::processWindowSystemEvent(&e);
884void QWindowSystemInterface::handleFileOpenEvent(
const QUrl &url)
886 QWindowSystemInterfacePrivate::FileOpenEvent e(url);
887 QGuiApplicationPrivate::processWindowSystemEvent(&e);
890void QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(
bool v)
892 platformSynthesizesMouse = v;
895bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
896 const QPointF &local,
const QPointF &global,
897 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
898 qreal tangentialPressure, qreal rotation,
int z,
899 Qt::KeyboardModifiers modifiers)
901 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEvent>(window,
903 QHighDpi::fromNativeLocalPosition(local, window),
904 QHighDpi::fromNativeGlobalPosition(global, window),
905 device, buttons, pressure,
906 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
909bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointingDevice *device,
910 const QPointF &local,
const QPointF &global,
911 Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
912 qreal tangentialPressure, qreal rotation,
int z,
913 Qt::KeyboardModifiers modifiers)
915 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
916 return handleTabletEvent(window, time, device, local, global,
917 buttons, pressure, xTilt, yTilt, tangentialPressure,
918 rotation, z, modifiers);
921bool QWindowSystemInterface::handleTabletEvent(QWindow *window, ulong timestamp,
const QPointF &local,
const QPointF &global,
922 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
923 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
924 Qt::KeyboardModifiers modifiers)
926 const QPointingDevice *dev = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(device),QPointingDevice::PointerType(pointerType),
927 QPointingDeviceUniqueId::fromNumericId(uid));
928 return handleTabletEvent(window, timestamp, dev, local, global, buttons, pressure,
929 xTilt, yTilt, tangentialPressure, rotation, z, modifiers);
932bool QWindowSystemInterface::handleTabletEvent(QWindow *window,
const QPointF &local,
const QPointF &global,
933 int device,
int pointerType, Qt::MouseButtons buttons, qreal pressure, qreal xTilt, qreal yTilt,
934 qreal tangentialPressure, qreal rotation,
int z, qint64 uid,
935 Qt::KeyboardModifiers modifiers)
937 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
938 return handleTabletEvent(window, time, local, global, device, pointerType, buttons, pressure,
939 xTilt, yTilt, tangentialPressure, rotation, z, uid, modifiers);
942bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
943 bool inProximity,
const QPointF &local,
const QPointF &global,
944 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
945 qreal tangentialPressure, qreal rotation,
int z,
946 Qt::KeyboardModifiers modifiers)
954 Q_UNUSED(tangentialPressure);
959 ? handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device)
960 : handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
963bool QWindowSystemInterface::handleTabletEnterLeaveProximityEvent(QWindow *window,
const QPointingDevice *device,
964 bool inProximity,
const QPointF &local,
const QPointF &global,
965 Qt::MouseButtons buttons, qreal xTilt, qreal yTilt,
966 qreal tangentialPressure, qreal rotation,
int z,
967 Qt::KeyboardModifiers modifiers)
969 const ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
970 return handleTabletEnterLeaveProximityEvent(window, time, device, inProximity,
971 local, global, buttons, xTilt, yTilt,
972 tangentialPressure, rotation, z, modifiers);
976bool QWindowSystemInterface::handleTabletEnterProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
978 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
979 QPointingDevice::PointerType(pointerType),
980 QPointingDeviceUniqueId::fromNumericId(uid));
981 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletEnterProximityEvent>(timestamp, device);
984void QWindowSystemInterface::handleTabletEnterProximityEvent(
int deviceType,
int pointerType, qint64 uid)
986 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
987 handleTabletEnterProximityEvent(time, deviceType, pointerType, uid);
990bool QWindowSystemInterface::handleTabletLeaveProximityEvent(ulong timestamp,
int deviceType,
int pointerType, qint64 uid)
992 const QPointingDevice *device = QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
993 QPointingDevice::PointerType(pointerType),
994 QPointingDeviceUniqueId::fromNumericId(uid));
995 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent>(timestamp, device);
998void QWindowSystemInterface::handleTabletLeaveProximityEvent(
int deviceType,
int pointerType, qint64 uid)
1000 ulong time = QWindowSystemInterfacePrivate::eventTime.elapsed();
1001 handleTabletLeaveProximityEvent(time, deviceType, pointerType, uid);
1004#ifndef QT_NO_GESTURES
1005bool QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1006 Qt::NativeGestureType type,
const QPointF &local,
const QPointF &global,
int fingerCount)
1008 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, {}, {}, local, global, fingerCount);
1011bool QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1012 Qt::NativeGestureType type, qreal value,
const QPointF &local,
const QPointF &global,
int fingerCount)
1014 return handleGestureEventWithValueAndDelta(window, timestamp, device, type, value, {}, local, global, fingerCount);
1017bool QWindowSystemInterface::handleGestureEventWithValueAndDelta(QWindow *window, ulong timestamp,
const QPointingDevice *device,
1018 Qt::NativeGestureType type, qreal value,
const QPointF &delta,
1019 const QPointF &local,
const QPointF &global,
int fingerCount)
1021 auto localPos = QHighDpi::fromNativeLocalPosition(local, window);
1022 auto globalPos = QHighDpi::fromNativeGlobalPosition(global, window);
1024 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::GestureEvent>(window,
1025 timestamp, type, device, fingerCount, localPos, globalPos, value, delta);
1029void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
1031 handleWindowSystemEvent<QWindowSystemInterfacePrivate::PlatformPanelEvent>(w);
1034#ifndef QT_NO_CONTEXTMENU
1036 const QPoint &pos,
const QPoint &globalPos,
1037 Qt::KeyboardModifiers modifiers)
1039 return handleWindowSystemEvent<QWindowSystemInterfacePrivate::ContextMenuEvent, Delivery>(
1040 window, mouseTriggered, pos, globalPos, modifiers);
1044#if QT_CONFIG(whatsthis)
1045void QWindowSystemInterface::handleEnterWhatsThisEvent()
1047 handleWindowSystemEvent<QWindowSystemInterfacePrivate::WindowSystemEvent>(
1048 QWindowSystemInterfacePrivate::EnterWhatsThisMode);
1052#ifndef QT_NO_DEBUG_STREAM
1053Q_GUI_EXPORT
QDebug operator<<(QDebug dbg,
const QWindowSystemInterface::TouchPoint &p)
1055 QDebugStateSaver saver(dbg);
1056 dbg.nospace() <<
"TouchPoint(" << p.id <<
" @" << p.area <<
" normalized " << p.normalPosition
1057 <<
" press " << p.pressure <<
" vel " << p.velocity <<
" state " << (
int)p.state;
1065
1066
1067
1068bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1070 const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
1073 if (!QGuiApplication::instance()) {
1074 qWarning().nospace()
1075 <<
"QWindowSystemInterface::flushWindowSystemEvents() invoked after "
1076 "QGuiApplication destruction, discarding " << count <<
" events.";
1077 QWindowSystemInterfacePrivate::windowSystemEventQueue.clear();
1080 if (QThread::currentThread() != QGuiApplication::instance()->thread()) {
1083 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1084 handleWindowSystemEvent<QWindowSystemInterfacePrivate::FlushEventsEvent, AsynchronousDelivery>(flags);
1085 QWindowSystemInterfacePrivate::eventsFlushed.wait(&QWindowSystemInterfacePrivate::flushEventMutex);
1087 sendWindowSystemEvents(flags);
1089 return QWindowSystemInterfacePrivate::eventAccepted.loadRelaxed() > 0;
1092void QWindowSystemInterface::deferredFlushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1094 Q_ASSERT(QThread::currentThread() == QGuiApplication::instance()->thread());
1096 QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex);
1097 sendWindowSystemEvents(flags);
1098 QWindowSystemInterfacePrivate::eventsFlushed.wakeOne();
1101bool QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
1105 while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) {
1106 QWindowSystemInterfacePrivate::WindowSystemEvent *event =
1107 flags & QEventLoop::ExcludeUserInputEvents ?
1108 QWindowSystemInterfacePrivate::getNonUserInputWindowSystemEvent() :
1109 QWindowSystemInterfacePrivate::getWindowSystemEvent();
1113 if (QWindowSystemInterfacePrivate::eventHandler) {
1114 if (QWindowSystemInterfacePrivate::eventHandler->sendEvent(event))
1118 QGuiApplicationPrivate::processWindowSystemEvent(event);
1124 if (event->type != QWindowSystemInterfacePrivate::FlushEvents)
1125 QWindowSystemInterfacePrivate::eventAccepted.storeRelaxed(event->eventAccepted);
1130 return (nevents > 0);
1133void QWindowSystemInterface::setSynchronousWindowSystemEvents(
bool enable)
1135 QWindowSystemInterfacePrivate::synchronousWindowSystemEvents = enable;
1138int QWindowSystemInterface::windowSystemEventsQueued()
1140 return QWindowSystemInterfacePrivate::windowSystemEventsQueued();
1143bool QWindowSystemInterface::nonUserInputEventsQueued()
1145 return QWindowSystemInterfacePrivate::nonUserInputEventsQueued();
1156 Qt::MouseButtons state, Qt::MouseButton button,
1157 QEvent::Type type, Qt::KeyboardModifiers mods,
int timestamp)
1159 QPointF nativeLocal =
QHighDpi::toNativeLocalPosition(local, window);
1160 QPointF nativeGlobal =
QHighDpi::toNativeGlobalPosition(global, window);
1161 QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(window,
1162 timestamp, nativeLocal, nativeGlobal, state, button, type, mods);
1166
1167
1168Q_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)
1170#if defined(Q_OS_MACOS)
1172 auto timestamp = QWindowSystemInterfacePrivate::eventTime.elapsed();
1173 if (t == QEvent::KeyPress && QWindowSystemInterface::handleShortcutEvent(window, timestamp, k, mods, 0, 0, 0, text, autorep, count))
1177 QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(window, t, k, mods, text, autorep, count);
1180Q_GUI_EXPORT
bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp,
int k, Qt::KeyboardModifiers mods,
const QString &text = QString(),
bool autorep =
false, ushort count = 1)
1182#if QT_CONFIG(shortcut)
1190 QGuiApplicationPrivate::modifier_buttons = mods;
1192 QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count);
1193 qevent.setTimestamp(timestamp);
1195 QShortcutMap &shortcutMap = QGuiApplicationPrivate::instance()->shortcutMap;
1196 if (shortcutMap.state() == QKeySequence::NoMatch) {
1198 QCoreApplication::sendEvent(o, &qevent);
1199 if (qevent.isAccepted())
1204 return shortcutMap.tryShortcut(&qevent);
1207 Q_UNUSED(timestamp);
1218 QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods,
1219 Qt::ScrollPhase phase)
1221 QWindowSystemInterface::handleWheelEvent(window, local, global, pixelDelta, angleDelta, mods, phase);
1239 const QList<QEventPoint> &points,
1240 Qt::KeyboardModifiers mods)
1242 return QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
1243 QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window), mods);
1247 const QList<QEventPoint> &points,
1248 Qt::KeyboardModifiers mods)
1250 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 ...)