From 579be875970e53edb142c889afcc181263161821 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 9 Jan 2021 14:39:48 +1100 Subject: [PATCH] [client] spice: added basic mouse smoothing for non-capture mode Enabled by default, can be disabled with `input:mouseSmoothing` --- client/src/config.c | 8 ++++++++ client/src/main.c | 21 ++++++++++++++++++--- client/src/main.h | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/client/src/config.c b/client/src/config.c index 714212c3..ad6fde33 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -282,6 +282,13 @@ static struct Option options[] = .type = OPTION_TYPE_INT, .value.x_int = 0, }, + { + .module = "input", + .name = "mouseSmoothing", + .description = "Apply simple mouse smoothing when not in capture mode (helps reduce aliasing)", + .type = OPTION_TYPE_BOOL, + .value.x_bool = true, + }, { .module = "input", .name = "rawMouse", @@ -467,6 +474,7 @@ bool config_load(int argc, char * argv[]) params.ignoreWindowsKeys = option_get_bool("input", "ignoreWindowsKeys" ); params.hideMouse = option_get_bool("input", "hideCursor" ); params.mouseSens = option_get_int ("input", "mouseSens" ); + params.mouseSmoothing = option_get_bool("input", "mouseSmoothing" ); params.rawMouse = option_get_bool("input", "rawMouse" ); params.mouseRedraw = option_get_bool("input", "mouseRedraw" ); params.autoCapture = option_get_bool("input", "autoCapture" ); diff --git a/client/src/main.c b/client/src/main.c index e59b0790..1f50405d 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -877,15 +877,21 @@ static void cursorToInt(double ex, double ey, int *x, int *y) static void handleMouseGrabbed(double ex, double ey) { + int x, y; + /* apply sensitivity */ if (g_cursor.sens != 0) { ex = (ex / 10.0) * (g_cursor.sens + 10); ey = (ey / 10.0) * (g_cursor.sens + 10); + cursorToInt(ex, ey, &x, &y); + } + else + { + x = floor(ex); + y = floor(ey); } - int x, y; - cursorToInt(ex, ey, &x, &y); if (x == 0 && y == 0) return; @@ -1023,7 +1029,16 @@ static void handleMouseNormal(double ex, double ey) } int x, y; - cursorToInt(ex, ey, &x, &y); + if (params.mouseSmoothing) + { + static struct DoublePoint last = { 0 }; + last.x = (last.x + ex) / 2.0; + last.y = (last.y + ey) / 2.0; + cursorToInt(last.x, last.y, &x, &y); + } + else + cursorToInt(ex, ey, &x, &y); + if (x == 0 && y == 0) return; diff --git a/client/src/main.h b/client/src/main.h index 004858ad..dfce70d5 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -138,6 +138,7 @@ struct AppParams const char * windowTitle; bool mouseRedraw; int mouseSens; + bool mouseSmoothing; bool rawMouse; bool autoCapture; };