wasm: Handle stylus events by generating QTabletEvents

Pick-to: 6.6
Fixes: QTBUG-120327
Change-Id: I37a92b9850385712b638c30f9a43028d8134f416
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
(cherry picked from commit bc578ec6efcf667e0be2ea5c3d68bd22135cadd0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Shawn Rutledge 2023-12-22 21:48:59 -07:00 committed by Qt Cherry-pick Bot
parent c28e68c729
commit d7bc61ac51
7 changed files with 48 additions and 1 deletions

View File

@ -187,6 +187,10 @@ PointerEvent::PointerEvent(EventType type, emscripten::val event) : MouseEvent(t
width = event["width"].as<qreal>();
height = event["height"].as<qreal>();
pressure = event["pressure"].as<qreal>();
tiltX = event["tiltX"].as<qreal>();
tiltY = event["tiltY"].as<qreal>();
tangentialPressure = event["tangentialPressure"].as<qreal>();
twist = event["twist"].as<qreal>();
isPrimary = event["isPrimary"].as<bool>();
}

View File

@ -221,6 +221,10 @@ struct PointerEvent : public MouseEvent
PointerType pointerType;
int pointerId;
qreal pressure;
qreal tiltX;
qreal tiltY;
qreal tangentialPressure;
qreal twist;
qreal width;
qreal height;
bool isPrimary;

View File

@ -21,6 +21,7 @@
#include <qpa/qwindowsysteminterface.h>
#include <QtCore/qcoreapplication.h>
#include <qpa/qplatforminputcontextfactory_p.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
@ -94,6 +95,7 @@ QWasmIntegration::QWasmIntegration()
qt_set_sequence_auto_mnemonic(false);
touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as<int>();
QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false);
// Create screens for container elements. Each container element will ultimately become a
// div element. Qt historically supported supplying canvas for screen elements - these elements

View File

@ -92,6 +92,16 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
QPointingDevice::Capability::Position | QPointingDevice::Capability::Area
| QPointingDevice::Capability::NormalizedPosition,
10, 0);
m_tabletDevice = std::make_unique<QPointingDevice>(
"stylus", 2, QInputDevice::DeviceType::Stylus,
QPointingDevice::PointerType::Pen,
QPointingDevice::Capability::Position | QPointingDevice::Capability::Pressure
| QPointingDevice::Capability::NormalizedPosition
| QInputDevice::Capability::MouseEmulation
| QInputDevice::Capability::Hover | QInputDevice::Capability::Rotation
| QInputDevice::Capability::XTilt | QInputDevice::Capability::YTilt
| QInputDevice::Capability::TangentialPressure,
0, 0);
QWindowSystemInterface::registerInputDevice(m_touchDevice.get());
}

View File

@ -39,6 +39,7 @@ public:
QString eventTargetId() const;
QString outerScreenId() const;
QPointingDevice *touchDevice() { return m_touchDevice.get(); }
QPointingDevice *tabletDevice() { return m_tabletDevice.get(); }
QWasmCompositor *compositor();
QWasmDeadKeySupport *deadKeySupport() { return m_deadKeySupport.get(); }
@ -82,6 +83,7 @@ private:
emscripten::val m_shadowContainer;
std::unique_ptr<QWasmCompositor> m_compositor;
std::unique_ptr<QPointingDevice> m_touchDevice;
std::unique_ptr<QPointingDevice> m_tabletDevice;
std::unique_ptr<QWasmDeadKeySupport> m_deadKeySupport;
QRect m_geometry = QRect(0, 0, 100, 100);
int m_depth = 32;

View File

@ -514,7 +514,7 @@ bool QWasmWindow::processKey(const KeyEvent &event)
bool QWasmWindow::processPointer(const PointerEvent &event)
{
if (event.pointerType != PointerType::Mouse)
if (event.pointerType != PointerType::Mouse && event.pointerType != PointerType::Pen)
return false;
switch (event.type) {

View File

@ -105,6 +105,31 @@ bool ClientArea::deliverEvent(const PointerEvent &event)
eventType, event.modifiers);
}
if (event.pointerType == PointerType::Pen) {
qreal pressure;
switch (event.type) {
case EventType::PointerDown :
case EventType::PointerMove :
pressure = event.pressure;
break;
case EventType::PointerUp :
pressure = 0.0;
break;
default:
return false;
}
// Tilt in the browser is in the range +-90, but QTabletEvent only goes to +-60.
qreal xTilt = qBound(-60.0, event.tiltX, 60.0);
qreal yTilt = qBound(-60.0, event.tiltY, 60.0);
// Barrel rotation is reported as 0 to 359, but QTabletEvent wants a signed value.
qreal rotation = event.twist > 180.0 ? 360.0 - event.twist : event.twist;
return QWindowSystemInterface::handleTabletEvent(
m_window->window(), QWasmIntegration::getTimestamp(), m_screen->tabletDevice(),
m_window->window()->mapFromGlobal(targetPointClippedToScreen),
targetPointClippedToScreen, event.mouseButtons, pressure, xTilt, yTilt,
event.tangentialPressure, rotation, event.modifiers);
}
QWindowSystemInterface::TouchPoint *touchPoint;
QPointF pointInTargetWindowCoords =