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>
This commit is contained in:
parent
b48364d49b
commit
f35e5a44b0
@ -581,9 +581,10 @@ bool QWasmCompositor::processPointer(const PointerEvent& event)
|
|||||||
const QPoint targetPointInScreenCoords = screen()->geometry().topLeft() + event.point;
|
const QPoint targetPointInScreenCoords = screen()->geometry().topLeft() + event.point;
|
||||||
|
|
||||||
QWindow *const targetWindow = ([this, &targetPointInScreenCoords]() -> QWindow * {
|
QWindow *const targetWindow = ([this, &targetPointInScreenCoords]() -> QWindow * {
|
||||||
auto *targetWindow =
|
auto *targetWindow = m_mouseCaptureWindow != nullptr ? m_mouseCaptureWindow.get()
|
||||||
m_windowManipulation.operation() == WindowManipulation::Operation::None ?
|
: m_windowManipulation.operation() == WindowManipulation::Operation::None
|
||||||
screen()->compositor()->windowAt(targetPointInScreenCoords, 5) : nullptr;
|
? screen()->compositor()->windowAt(targetPointInScreenCoords, 5)
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
return targetWindow ? targetWindow : m_lastMouseTargetWindow.get();
|
return targetWindow ? targetWindow : m_lastMouseTargetWindow.get();
|
||||||
})();
|
})();
|
||||||
@ -679,6 +680,8 @@ bool QWasmCompositor::processPointer(const PointerEvent& event)
|
|||||||
|
|
||||||
bool QWasmCompositor::deliverEventToTarget(const PointerEvent &event, QWindow *eventTarget)
|
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 pointInScreenCoords = screen()->geometry().topLeft() + event.point;
|
||||||
const QPoint targetPointClippedToScreen(
|
const QPoint targetPointClippedToScreen(
|
||||||
std::max(screen()->geometry().left(),
|
std::max(screen()->geometry().left(),
|
||||||
@ -698,8 +701,8 @@ bool QWasmCompositor::deliverEventToTarget(const PointerEvent &event, QWindow *e
|
|||||||
}
|
}
|
||||||
|
|
||||||
WindowArea windowArea = WindowArea::Client;
|
WindowArea windowArea = WindowArea::Client;
|
||||||
if (!eventTarget->geometry().contains(targetPointClippedToScreen)
|
if (!deliveringToPreviouslyClickedWindow && !m_mouseCaptureWindow
|
||||||
&& !deliveringToPreviouslyClickedWindow) {
|
&& !eventTarget->geometry().contains(targetPointClippedToScreen)) {
|
||||||
if (!eventTarget->frameGeometry().contains(targetPointClippedToScreen))
|
if (!eventTarget->frameGeometry().contains(targetPointClippedToScreen))
|
||||||
return false;
|
return false;
|
||||||
windowArea = WindowArea::NonClient;
|
windowArea = WindowArea::NonClient;
|
||||||
@ -972,6 +975,17 @@ int QWasmCompositor::handleTouch(int eventType, const EmscriptenTouchEvent *touc
|
|||||||
return static_cast<int>(accepted);
|
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)
|
void QWasmCompositor::leaveWindow(QWindow *window)
|
||||||
{
|
{
|
||||||
m_windowUnderMouse = nullptr;
|
m_windowUnderMouse = nullptr;
|
||||||
|
@ -82,6 +82,8 @@ public:
|
|||||||
bool processKeyboard(int eventType, const EmscriptenKeyboardEvent *keyEvent);
|
bool processKeyboard(int eventType, const EmscriptenKeyboardEvent *keyEvent);
|
||||||
bool processWheel(int eventType, const EmscriptenWheelEvent *wheelEvent);
|
bool processWheel(int eventType, const EmscriptenWheelEvent *wheelEvent);
|
||||||
int handleTouch(int eventType, const EmscriptenTouchEvent *touchEvent);
|
int handleTouch(int eventType, const EmscriptenTouchEvent *touchEvent);
|
||||||
|
void setCapture(QWasmWindow *window);
|
||||||
|
void releaseCapture();
|
||||||
|
|
||||||
bool processMouseEnter(const EmscriptenMouseEvent *mouseEvent);
|
bool processMouseEnter(const EmscriptenMouseEvent *mouseEvent);
|
||||||
bool processMouseLeave();
|
bool processMouseLeave();
|
||||||
@ -173,6 +175,7 @@ private:
|
|||||||
|
|
||||||
QPointer<QWindow> m_pressedWindow;
|
QPointer<QWindow> m_pressedWindow;
|
||||||
QPointer<QWindow> m_lastMouseTargetWindow;
|
QPointer<QWindow> m_lastMouseTargetWindow;
|
||||||
|
QPointer<QWindow> m_mouseCaptureWindow;
|
||||||
|
|
||||||
std::unique_ptr<qstdweb::EventCallback> m_pointerDownCallback;
|
std::unique_ptr<qstdweb::EventCallback> m_pointerDownCallback;
|
||||||
std::unique_ptr<qstdweb::EventCallback> m_pointerMoveCallback;
|
std::unique_ptr<qstdweb::EventCallback> m_pointerMoveCallback;
|
||||||
|
@ -605,4 +605,13 @@ void QWasmWindow::requestActivateWindow()
|
|||||||
QPlatformWindow::requestActivateWindow();
|
QPlatformWindow::requestActivateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QWasmWindow::setMouseGrabEnabled(bool grab)
|
||||||
|
{
|
||||||
|
if (grab)
|
||||||
|
m_compositor->setCapture(this);
|
||||||
|
else
|
||||||
|
m_compositor->releaseCapture();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
void setWindowState(Qt::WindowStates state) override;
|
void setWindowState(Qt::WindowStates state) override;
|
||||||
void applyWindowState();
|
void applyWindowState();
|
||||||
bool setKeyboardGrabEnabled(bool) override { return false; }
|
bool setKeyboardGrabEnabled(bool) override { return false; }
|
||||||
bool setMouseGrabEnabled(bool) override { return false; }
|
bool setMouseGrabEnabled(bool grab) final;
|
||||||
|
|
||||||
void drawTitleBar(QPainter *painter) const;
|
void drawTitleBar(QPainter *painter) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user