From d77da1ffc7da02a3a6a92d12d054d8bce29407d9 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 16 Jan 2021 23:28:44 -0500 Subject: [PATCH] [client] wayland: clip desired guest cursor position This avoids putting internal coordinates out of screen and causing cursor spasms while dragging beyond the edge. --- client/src/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 516dee5b..4fc1ceca 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1201,12 +1201,25 @@ void app_handleMouseBasic() if (g_cursor.guest.dpiScale == 0) return; + double px = g_cursor.pos.x; + double py = g_cursor.pos.y; + + if (px < g_state.dstRect.x) + px = g_state.dstRect.x; + else if (px > g_state.dstRect.x + g_state.dstRect.w) + px = g_state.dstRect.x + g_state.dstRect.w; + + if (py < g_state.dstRect.y) + py = g_state.dstRect.y; + else if (py > g_state.dstRect.y + g_state.dstRect.h) + py = g_state.dstRect.y + g_state.dstRect.h; + /* translate the guests position to our coordinate space */ struct DoublePoint local; guestCurToLocal(&local); - double lx = (g_cursor.pos.x - local.x) / g_cursor.dpiScale; - double ly = (g_cursor.pos.y - local.y) / g_cursor.dpiScale; + double lx = (px - local.x) / g_cursor.dpiScale; + double ly = (py - local.y) / g_cursor.dpiScale; int x, y; cursorToInt(lx, ly, &x, &y);