From 7c91c922e6a1542d817f8d3c52564720420b1feb Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 15 Jan 2022 00:00:34 -0500 Subject: [PATCH] [client] input: avoid reentrancy when realigning guest cursor This prevents LGMP_ERR_QUEUE_FULL from happening with high polling rate mice, which is caused by receiving many more mouse events while the guest cursor warps, triggering more warps. --- client/src/core.c | 14 +++++++++++--- client/src/main.h | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/src/core.c b/client/src/core.c index 6b14c7e7..b7671d7d 100644 --- a/client/src/core.c +++ b/client/src/core.c @@ -421,6 +421,9 @@ void core_handleMouseNormal(double ex, double ey) if (!g_cursor.guest.valid) return; + if (g_cursor.realigning) + return; + if (!core_inputEnabled()) return; @@ -478,11 +481,15 @@ void core_handleMouseNormal(double ex, double ey) else { /* wait for the move request to be processed */ + g_cursor.realigning = true; do { uint32_t hostSerial; if (lgmpClientGetSerial(g_state.pointerQueue, &hostSerial) != LGMP_OK) + { + g_cursor.realigning = false; return; + } if (hostSerial >= setPosSerial) break; @@ -491,9 +498,10 @@ void core_handleMouseNormal(double ex, double ey) } while(app_isRunning()); - g_cursor.guest.x = msg.x; - g_cursor.guest.y = msg.y; - g_cursor.realign = false; + g_cursor.guest.x = msg.x; + g_cursor.guest.y = msg.y; + g_cursor.realign = false; + g_cursor.realigning = false; if (!g_cursor.inWindow) return; diff --git a/client/src/main.h b/client/src/main.h index 2e5270ca..df922832 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -250,6 +250,9 @@ struct CursorState /* true if the guest should be realigned to the host when next drawn */ bool realign; + /* true if the guest is currently realigning to the host */ + bool realigning; + /* true if the cursor needs re-drawing/updating */ bool redraw;