2026-09-13 03:47:52

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie
2026-09-13 03:47:53 +00:00
parent 466769f18a
commit ae246aa03d
2 changed files with 12 additions and 8 deletions
+10 -8
View File
@@ -73,6 +73,7 @@ class QPaintEngine;
class QSurface; class QSurface;
constexpr int default_mouse_constrain_timeout = 10; constexpr int default_mouse_constrain_timeout = 10;
constexpr int default_mouse_update_timeout = 10;
class RenderWidget : public QWidget { class RenderWidget : public QWidget {
public: public:
@@ -138,6 +139,10 @@ GRenderWindow::GRenderWindow(MainWindow* parent,
mouse_constrain_timer.setInterval(default_mouse_constrain_timeout); mouse_constrain_timer.setInterval(default_mouse_constrain_timeout);
connect(&mouse_constrain_timer, &QTimer::timeout, this, &GRenderWindow::ConstrainMouse); connect(&mouse_constrain_timer, &QTimer::timeout, this, &GRenderWindow::ConstrainMouse);
mouse_update_timer.setInterval(default_mouse_update_timeout);
connect(&mouse_update_timer, &QTimer::timeout, this, &GRenderWindow::UpdateMouse);
mouse_update_timer.start();
} }
void GRenderWindow::ExecuteProgram(std::size_t program_index) { void GRenderWindow::ExecuteProgram(std::size_t program_index) {
@@ -518,8 +523,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
// Constrain mouse for mouse emulation with mouse panning // Constrain mouse for mouse emulation with mouse panning
if (Settings::values.mouse_panning && Settings::values.mouse_enabled) { if (Settings::values.mouse_panning && Settings::values.mouse_enabled) {
const auto [clamped_mouse_x, clamped_mouse_y] = ClipToTouchScreen(x, y); const auto [clamped_mouse_x, clamped_mouse_y] = ClipToTouchScreen(x, y);
QCursor::setPos(mapToGlobal( QCursor::setPos(mapToGlobal(QPoint{int(clamped_mouse_x), int(clamped_mouse_y)}));
QPoint{static_cast<int>(clamped_mouse_x), static_cast<int>(clamped_mouse_y)}));
} }
mouse_constrain_timer.stop(); mouse_constrain_timer.stop();
@@ -538,12 +542,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
} }
void GRenderWindow::ConstrainMouse() { void GRenderWindow::ConstrainMouse() {
if (QtCommon::emu_thread == nullptr || !Settings::values.mouse_panning) { if (QtCommon::emu_thread == nullptr || Settings::values.mouse_panning || !this->isActiveWindow()) {
mouse_constrain_timer.stop();
return;
}
if (!this->isActiveWindow()) {
mouse_constrain_timer.stop(); mouse_constrain_timer.stop();
return; return;
} }
@@ -558,6 +557,9 @@ void GRenderWindow::ConstrainMouse() {
const int center_y = height() / 2; const int center_y = height() / 2;
QCursor::setPos(mapToGlobal(QPoint{center_x, center_y})); QCursor::setPos(mapToGlobal(QPoint{center_x, center_y}));
} }
}
void GRenderWindow::UpdateMouse() {
input_subsystem->GetMouse()->NotifyChanged(); // required to reset mouse once it's no longer moved input_subsystem->GetMouse()->NotifyChanged(); // required to reset mouse once it's no longer moved
} }
+2
View File
@@ -144,6 +144,7 @@ private:
void TouchUpdateEvent(const QTouchEvent* event); void TouchUpdateEvent(const QTouchEvent* event);
void TouchEndEvent(); void TouchEndEvent();
void ConstrainMouse(); void ConstrainMouse();
void UpdateMouse();
void RequestCameraCapture(); void RequestCameraCapture();
void OnCameraCapture(int requestId, const QImage& img); void OnCameraCapture(int requestId, const QImage& img);
@@ -184,6 +185,7 @@ private:
#endif #endif
QTimer mouse_constrain_timer; QTimer mouse_constrain_timer;
QTimer mouse_update_timer;
protected: protected:
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;