From b7fee7745b84335a0e1b5375286f77377142c4a9 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 8 Dec 2021 16:27:58 +0600 Subject: [PATCH] Mouse event improvements * Only center the cursor when it leaves the emulator screen * Ignore the very first mouse event that appears after it is captured for the first time after starting --- src/qt/qt_rendererstack.cpp | 17 ++++++++++++++--- src/qt/qt_rendererstack.hpp | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 3df8c8ab2..8796d7415 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -103,7 +103,7 @@ void RendererStack::wheelEvent(QWheelEvent *event) } } -int ignoreNextMouseEvent = 0; +int ignoreNextMouseEvent = 1; void RendererStack::mouseMoveEvent(QMouseEvent *event) { if (QApplication::platformName().contains("wayland")) @@ -120,12 +120,23 @@ void RendererStack::mouseMoveEvent(QMouseEvent *event) if (ignoreNextMouseEvent) { oldPos = event->pos(); ignoreNextMouseEvent--; event->accept(); return; } mousedata.deltax += event->pos().x() - oldPos.x(); mousedata.deltay += event->pos().y() - oldPos.y(); - QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2))); oldPos = event->pos(); - ignoreNextMouseEvent = 1; #endif } +void RendererStack::leaveEvent(QEvent* event) +{ + if (QApplication::platformName().contains("wayland")) + { + event->accept(); + return; + } + if (!mouse_capture) return; + QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2))); + ignoreNextMouseEvent = 2; + event->accept(); +} + // called from blitter thread void RendererStack::blit(int x, int y, int w, int h) { diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 05dd5db5c..239bd5bef 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace Ui { class RendererStack; @@ -20,6 +21,7 @@ public: void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void wheelEvent(QWheelEvent *event) override; + void leaveEvent(QEvent *event) override; void keyPressEvent(QKeyEvent* event) override { event->ignore();