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
This commit is contained in:
@@ -103,7 +103,7 @@ void RendererStack::wheelEvent(QWheelEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ignoreNextMouseEvent = 0;
|
int ignoreNextMouseEvent = 1;
|
||||||
void RendererStack::mouseMoveEvent(QMouseEvent *event)
|
void RendererStack::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (QApplication::platformName().contains("wayland"))
|
if (QApplication::platformName().contains("wayland"))
|
||||||
@@ -120,12 +120,23 @@ void RendererStack::mouseMoveEvent(QMouseEvent *event)
|
|||||||
if (ignoreNextMouseEvent) { oldPos = event->pos(); ignoreNextMouseEvent--; event->accept(); return; }
|
if (ignoreNextMouseEvent) { oldPos = event->pos(); ignoreNextMouseEvent--; event->accept(); return; }
|
||||||
mousedata.deltax += event->pos().x() - oldPos.x();
|
mousedata.deltax += event->pos().x() - oldPos.x();
|
||||||
mousedata.deltay += event->pos().y() - oldPos.y();
|
mousedata.deltay += event->pos().y() - oldPos.y();
|
||||||
QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2)));
|
|
||||||
oldPos = event->pos();
|
oldPos = event->pos();
|
||||||
ignoreNextMouseEvent = 1;
|
|
||||||
#endif
|
#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
|
// called from blitter thread
|
||||||
void RendererStack::blit(int x, int y, int w, int h)
|
void RendererStack::blit(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RendererStack;
|
class RendererStack;
|
||||||
@@ -20,6 +21,7 @@ public:
|
|||||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
void mouseMoveEvent(QMouseEvent* event) override;
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
void wheelEvent(QWheelEvent *event) override;
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
void leaveEvent(QEvent *event) override;
|
||||||
void keyPressEvent(QKeyEvent* event) override
|
void keyPressEvent(QKeyEvent* event) override
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
|
Reference in New Issue
Block a user