diff --git a/src/plugins/platforms/wasm/qwasmevent.cpp b/src/plugins/platforms/wasm/qwasmevent.cpp index ec37c64b2da..52514def8ad 100644 --- a/src/plugins/platforms/wasm/qwasmevent.cpp +++ b/src/plugins/platforms/wasm/qwasmevent.cpp @@ -184,6 +184,10 @@ PointerEvent::PointerEvent(EventType type, emscripten::val event) : MouseEvent(t width = event["width"].as(); height = event["height"].as(); pressure = event["pressure"].as(); + tiltX = event["tiltX"].as(); + tiltY = event["tiltY"].as(); + tangentialPressure = event["tangentialPressure"].as(); + twist = event["twist"].as(); isPrimary = event["isPrimary"].as(); } diff --git a/src/plugins/platforms/wasm/qwasmevent.h b/src/plugins/platforms/wasm/qwasmevent.h index 3b2e5bfc52d..e59618a9be3 100644 --- a/src/plugins/platforms/wasm/qwasmevent.h +++ b/src/plugins/platforms/wasm/qwasmevent.h @@ -215,6 +215,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; diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index b93b8bb6f9c..be391f4aff2 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ QWasmIntegration::QWasmIntegration() qt_set_sequence_auto_mnemonic(false); touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as(); + 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 diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index c035de4a339..3aee11f43fd 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -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( + "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()); } diff --git a/src/plugins/platforms/wasm/qwasmscreen.h b/src/plugins/platforms/wasm/qwasmscreen.h index e0195549f98..4906907b606 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.h +++ b/src/plugins/platforms/wasm/qwasmscreen.h @@ -37,6 +37,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(); } @@ -70,6 +71,7 @@ private: emscripten::val m_shadowContainer; std::unique_ptr m_compositor; std::unique_ptr m_touchDevice; + std::unique_ptr m_tabletDevice; std::unique_ptr m_deadKeySupport; QRect m_geometry = QRect(0, 0, 100, 100); int m_depth = 32; diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index de592bd6484..23ba913296d 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -490,7 +490,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) { diff --git a/src/plugins/platforms/wasm/qwasmwindowclientarea.cpp b/src/plugins/platforms/wasm/qwasmwindowclientarea.cpp index aa8cfeebb2e..f1f0833c9a9 100644 --- a/src/plugins/platforms/wasm/qwasmwindowclientarea.cpp +++ b/src/plugins/platforms/wasm/qwasmwindowclientarea.cpp @@ -91,6 +91,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 =