From 8365419262fe5a5536ad99810d79122ced10bd63 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 12 Jan 2021 11:48:29 +1100 Subject: [PATCH] [client] spice: use modf in `cursorToInt` for fractional tracking --- client/src/main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 4aee2b98..94d758d9 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -874,12 +874,13 @@ static void cursorToInt(double ex, double ey, int *x, int *y) } /* convert to int accumulating the fractional error */ - g_cursor.acc.x += ex; - g_cursor.acc.y += ey; - *x = floor(g_cursor.acc.x); - *y = floor(g_cursor.acc.y); - g_cursor.acc.x -= *x; - g_cursor.acc.y -= *y; + ex += g_cursor.acc.x; + ey += g_cursor.acc.y; + g_cursor.acc.x = modf(ex, &ex); + g_cursor.acc.y = modf(ey, &ey); + + *x = (int)ex; + *y = (int)ey; } static void handleMouseGrabbed(double ex, double ey)