From b2ac2980d52db7e929194a511843c4c98aae3b98 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 19 Jan 2021 05:56:40 +1100 Subject: [PATCH] [client] don't attempt to align to the guest with invalid pos data --- client/src/main.c | 18 +++++++++++++++--- client/src/main.h | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 701f80fd..373fcfc8 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -132,6 +132,7 @@ void app_updateCursorPos(double x, double y) { g_cursor.pos.x = x; g_cursor.pos.y = y; + g_cursor.valid = true; } void app_handleFocusEvent(bool focused) @@ -258,6 +259,12 @@ static void updatePositionInfo(void) g_cursor.scale.y = (float)srcW / (float)g_state.dstRect.w; g_cursor.dpiScale = g_cursor.guest.dpiScale / 100.0f; + if (!g_state.posInfoValid) + { + g_state.posInfoValid = true; + alignToGuest(); + } + done: atomic_fetch_add(&g_state.lgrResize, 1); } @@ -1166,8 +1173,11 @@ static void rotatePoint(struct DoublePoint *point) } } -static void guestCurToLocal(struct DoublePoint *local) +static bool guestCurToLocal(struct DoublePoint *local) { + if (!g_cursor.guest.valid || !g_state.posInfoValid) + return false; + const struct DoublePoint point = { .x = g_cursor.guest.x + g_cursor.guest.hx, @@ -1200,6 +1210,8 @@ static void guestCurToLocal(struct DoublePoint *local) point.x / g_cursor.scale.x; break; } + + return true; } inline static void localCurToGuest(struct DoublePoint *guest) @@ -1561,8 +1573,8 @@ int eventFilter(void * userdata, SDL_Event * event) break; struct DoublePoint local; - guestCurToLocal(&local); - warpPointer(round(local.x), round(local.y), false); + if (guestCurToLocal(&local)) + warpPointer(round(local.x), round(local.y), false); break; } } diff --git a/client/src/main.h b/client/src/main.h index 564db336..e2f3f625 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -59,6 +59,8 @@ struct AppState SDL_Rect border; SDL_Point srcSize; LG_RendererRect dstRect; + bool posInfoValid; + bool alignToGuest; const LG_Renderer * lgr; void * lgrData; @@ -229,6 +231,9 @@ struct CursorState /* the local position */ struct DoublePoint pos; + /* true if the position is valid */ + bool valid; + /* the button state */ unsigned int buttons;