diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2021-12-16 12:54:31 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2022-01-12 11:41:10 +1000 |
commit | 8f7bebb611958fe937c5bd38947f75620cfb94a8 (patch) | |
tree | c127f2c383b1693aa9eeef70806593fb2e9eaa14 | |
parent | 66a183298a8ff3d51da02f25ffe5eeea0ea76862 (diff) |
wasm: ensure cursor reverts after window resize
This partially reverts 97be0cca174a3b92c24062c557bf4df34db23f7b
but without the crash
We temporarily override the wasm cursor while leaving the
application/window cursor alone to mimic what desktop application
behavior is like.
Pick-to: 6.3
Fixes: QTBUG-99111
Change-Id: I23df48b2eaa82830593f1753ec23d14fe375b70c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcursor.cpp | 26 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcursor.h | 5 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmeventtranslator.cpp | 22 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmeventtranslator.h | 2 |
4 files changed, 46 insertions, 9 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp index 4b4bb61071..a9336bdc8f 100644 --- a/src/plugins/platforms/wasm/qwasmcursor.cpp +++ b/src/plugins/platforms/wasm/qwasmcursor.cpp @@ -47,7 +47,6 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window) if (!screen) return; - QByteArray htmlCursorName; if (windowCursor) { // Bitmap and custom cursors are not implemented (will fall back to "auto") @@ -60,10 +59,7 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window) if (htmlCursorName.isEmpty()) htmlCursorName = "default"; - // Set cursor on the canvas - val canvas = QWasmScreen::get(screen)->canvas(); - val canvasStyle = canvas["style"]; - canvasStyle.set("cursor", val(htmlCursorName.constData())); + setWasmCursor(screen, htmlCursorName); } QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape) @@ -143,3 +139,23 @@ QByteArray QWasmCursor::cursorShapeToHtml(Qt::CursorShape shape) return cursorName; } + +void QWasmCursor::setWasmCursor(QScreen *screen, const QByteArray &name) +{ + // Set cursor on the canvas + val canvas = QWasmScreen::get(screen)->canvas(); + val canvasStyle = canvas["style"]; + canvasStyle.set("cursor", val(name.constData())); +} + +void QWasmCursor::setOverrideWasmCursor(QCursor *windowCursor, QScreen *screen) +{ + QWasmCursor *wCursor = static_cast<QWasmCursor *>(QWasmScreen::get(screen)->cursor()); + wCursor->setWasmCursor(screen, wCursor->cursorShapeToHtml(windowCursor->shape())); +} + +void QWasmCursor::clearOverrideWasmCursor(QScreen *screen) +{ + QWasmCursor *wCursor = static_cast<QWasmCursor *>(QWasmScreen::get(screen)->cursor()); + wCursor->setWasmCursor(screen, wCursor->htmlCursorName); +} diff --git a/src/plugins/platforms/wasm/qwasmcursor.h b/src/plugins/platforms/wasm/qwasmcursor.h index 516e07aa31..b8aef841b4 100644 --- a/src/plugins/platforms/wasm/qwasmcursor.h +++ b/src/plugins/platforms/wasm/qwasmcursor.h @@ -38,6 +38,11 @@ public: void changeCursor(QCursor *windowCursor, QWindow *window) override; QByteArray cursorShapeToHtml(Qt::CursorShape shape); + static void setOverrideWasmCursor(QCursor *windowCursor, QScreen *screen); + static void clearOverrideWasmCursor(QScreen *screen); +private: + QByteArray htmlCursorName; + void setWasmCursor(QScreen *screen, const QByteArray &name); }; #endif diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 598b77f541..34b1a7358a 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -33,7 +33,7 @@ #include "qwasmintegration.h" #include "qwasmclipboard.h" #include "qwasmstring.h" - +#include "qwasmcursor.h" #include <QtGui/qevent.h> #include <qpa/qwindowsysteminterface.h> #include <QtCore/qcoreapplication.h> @@ -499,7 +499,7 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven pressedWindow = nullptr; } - if (mouseEvent->button == 0) { + if (draggedWindow && pressedButtons.testFlag(Qt::NoButton)) { draggedWindow = nullptr; resizeMode = QWasmWindow::ResizeNone; } @@ -514,8 +514,22 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven { buttonEventType = QEvent::MouseMove; - if (htmlWindow && htmlWindow->isPointOnResizeRegion(globalPoint)) - window2->setCursor(cursorForMode(htmlWindow->resizeModeAtPoint(globalPoint))); + if (htmlWindow && pressedButtons.testFlag(Qt::NoButton)) { + + if (htmlWindow->isPointOnResizeRegion(globalPoint)) { + QCursor resizingCursor = cursorForMode(htmlWindow->resizeModeAtPoint(globalPoint)); + + if (resizingCursor != window2->cursor()) { + isCursorOverridden = true; + QWasmCursor::setOverrideWasmCursor(&resizingCursor, window2->screen()); + } + } else { // off resizing area + if (isCursorOverridden) { + isCursorOverridden = false; + QWasmCursor::clearOverrideWasmCursor(window2->screen()); + } + } + } if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) { if (resizeMode == QWasmWindow::ResizeNone && draggedWindow) { diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.h b/src/plugins/platforms/wasm/qwasmeventtranslator.h index 7a87c541de..0b579691c5 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.h +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.h @@ -100,6 +100,8 @@ private: Qt::Key m_emDeadKey = Qt::Key_unknown; bool m_emStickyDeadKey = false; QCursor cursorForMode(QWasmWindow::ResizeMode mode); + QCursor overriddenCursor; + bool isCursorOverridden = false; }; QT_END_NAMESPACE |