summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmcompositor.cpp
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-08-01 14:35:43 +0200
committerMikolaj Boc <mikolaj.boc@qt.io>2022-08-27 00:10:34 +0200
commitf35e5a44b0d148ede055a11c89fcd7e9920f0b85 (patch)
tree85f2db49b536508997c5b6a34dac16aa274f85bf /src/plugins/platforms/wasm/qwasmcompositor.cpp
parentb48364d49b46c5233d761616a573c010824bcb2b (diff)
Implement mouse capture on WASM
This fixes dock widget undocking - previously, without the capture, any widget that the mouse accidentally entered would get the event, resulting in re-docking problems, cursor issues etc. Fixes: QTBUG-105621 Pick-to: 6.4 Change-Id: Ia1f2c91578018f2ae9df903bc0730200ede17d32 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmcompositor.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmcompositor.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp
index 8f9a6bb72b3..5c13e27880b 100644
--- a/src/plugins/platforms/wasm/qwasmcompositor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp
@@ -581,9 +581,10 @@ bool QWasmCompositor::processPointer(const PointerEvent& event)
const QPoint targetPointInScreenCoords = screen()->geometry().topLeft() + event.point;
QWindow *const targetWindow = ([this, &targetPointInScreenCoords]() -> QWindow * {
- auto *targetWindow =
- m_windowManipulation.operation() == WindowManipulation::Operation::None ?
- screen()->compositor()->windowAt(targetPointInScreenCoords, 5) : nullptr;
+ auto *targetWindow = m_mouseCaptureWindow != nullptr ? m_mouseCaptureWindow.get()
+ : m_windowManipulation.operation() == WindowManipulation::Operation::None
+ ? screen()->compositor()->windowAt(targetPointInScreenCoords, 5)
+ : nullptr;
return targetWindow ? targetWindow : m_lastMouseTargetWindow.get();
})();
@@ -679,6 +680,8 @@ bool QWasmCompositor::processPointer(const PointerEvent& event)
bool QWasmCompositor::deliverEventToTarget(const PointerEvent &event, QWindow *eventTarget)
{
+ Q_ASSERT(!m_mouseCaptureWindow || m_mouseCaptureWindow.get() == eventTarget);
+
const QPoint pointInScreenCoords = screen()->geometry().topLeft() + event.point;
const QPoint targetPointClippedToScreen(
std::max(screen()->geometry().left(),
@@ -698,8 +701,8 @@ bool QWasmCompositor::deliverEventToTarget(const PointerEvent &event, QWindow *e
}
WindowArea windowArea = WindowArea::Client;
- if (!eventTarget->geometry().contains(targetPointClippedToScreen)
- && !deliveringToPreviouslyClickedWindow) {
+ if (!deliveringToPreviouslyClickedWindow && !m_mouseCaptureWindow
+ && !eventTarget->geometry().contains(targetPointClippedToScreen)) {
if (!eventTarget->frameGeometry().contains(targetPointClippedToScreen))
return false;
windowArea = WindowArea::NonClient;
@@ -972,6 +975,17 @@ int QWasmCompositor::handleTouch(int eventType, const EmscriptenTouchEvent *touc
return static_cast<int>(accepted);
}
+void QWasmCompositor::setCapture(QWasmWindow *window)
+{
+ Q_ASSERT(std::find(m_windowStack.begin(), m_windowStack.end(), window) != m_windowStack.end());
+ m_mouseCaptureWindow = window->window();
+}
+
+void QWasmCompositor::releaseCapture()
+{
+ m_mouseCaptureWindow = nullptr;
+}
+
void QWasmCompositor::leaveWindow(QWindow *window)
{
m_windowUnderMouse = nullptr;