[client] spice: calculate the entry point delta correctly

This commit is contained in:
Geoffrey McRae 2020-12-06 11:07:05 +11:00
parent d61d7699e5
commit 5802bfb5eb

View file

@ -77,7 +77,6 @@ struct AppState state;
struct AppParams params = { 0 }; struct AppParams params = { 0 };
static void handleMouseMoveEvent(int ex, int ey); static void handleMouseMoveEvent(int ex, int ey);
static void alignMouseWithHost();
static void lgInit() static void lgInit()
{ {
@ -818,7 +817,7 @@ static void handleMouseMoveEvent(int ex, int ey)
return; return;
state.curLastX = state.curLocalX = ex; state.curLastX = state.curLocalX = ex;
state.curLastY = state.curLocalX = ey; state.curLastY = state.curLocalY = ey;
state.haveCurLocal = true; state.haveCurLocal = true;
if (state.warpState == WARP_STATE_ACTIVE && if (state.warpState == WARP_STATE_ACTIVE &&
@ -834,42 +833,61 @@ static void handleMouseMoveEvent(int ex, int ey)
/* if we don't have the current cursor pos just send cursor movements */ /* if we don't have the current cursor pos just send cursor movements */
if (!state.haveCursorPos) if (!state.haveCursorPos)
{ {
state.cursorInView = true; if (state.grabMouse)
spice_mouse_motion(delta.x, delta.y);
if ((state.haveCursorPos || state.grabMouse) &&
(ex < 100 || ex > state.windowW - 100 ||
ey < 100 || ey > state.windowH - 100))
{ {
warpMouse(state.windowW / 2, state.windowH / 2); state.cursorInView = true;
spice_mouse_motion(delta.x, delta.y);
if (ex < 100 || ex > state.windowW - 100 ||
ey < 100 || ey > state.windowH - 100)
warpMouse(state.windowW / 2, state.windowH / 2);
} }
return; return;
} }
if (ex < state.dstRect.x || const bool inView = !(
ex > state.dstRect.x + state.dstRect.w || ex < state.dstRect.x ||
ey < state.dstRect.y || ex >= state.dstRect.x + state.dstRect.w ||
ey > state.dstRect.y + state.dstRect.h) ey < state.dstRect.y ||
{ ey >= state.dstRect.y + state.dstRect.h);
SDL_ShowCursor(SDL_ENABLE);
state.cursorInView = false;
state.updateCursor = true;
if (params.useSpiceInput && !params.alwaysShowCursor) /* if the cursor is to move in/outside the display area */
state.drawCursor = false; if (state.cursorInView != inView)
return; {
state.cursorInView = inView;
if (inView)
{
/* cursor moved in */
if (params.hideMouse)
SDL_ShowCursor(SDL_DISABLE);
state.updateCursor = true;
state.drawCursor = true;
if (state.warpState == WARP_STATE_OFF)
state.warpState = WARP_STATE_ON;
/* convert guest to local and calculate the delta */
const int lx = (state.cursor.x / state.scaleX) + state.dstRect.x;
const int ly = (state.cursor.y / state.scaleY) + state.dstRect.y;
delta.x = ex - lx;
delta.y = ey - ly;
}
else
{
/* cursor moved out */
SDL_ShowCursor(SDL_ENABLE);
state.updateCursor = true;
if (params.useSpiceInput && !params.alwaysShowCursor)
state.drawCursor = false;
}
} }
else if (inView)
if (!state.cursorInView)
{ {
if (params.hideMouse) if (ex < 100 || ex > state.windowW - 100 ||
SDL_ShowCursor(SDL_DISABLE); ey < 100 || ey > state.windowH - 100)
warpMouse(state.windowW / 2, state.windowH / 2);
state.cursorInView = true;
state.updateCursor = true;
state.drawCursor = true;
if (state.warpState == WARP_STATE_OFF)
state.warpState = WARP_STATE_ON;
} }
if (state.scale && params.scaleMouseInput && !state.grabMouse) if (state.scale && params.scaleMouseInput && !state.grabMouse)
@ -892,14 +910,6 @@ static void handleMouseMoveEvent(int ex, int ey)
state.sensY -= delta.y; state.sensY -= delta.y;
} }
if ((state.haveCursorPos || state.grabMouse) &&
(ex < 100 || ex > state.windowW - 100 ||
ey < 100 || ey > state.windowH - 100))
{
warpMouse(state.windowW / 2, state.windowH / 2);
return;
}
if (!state.grabMouse && state.warpState == WARP_STATE_ON) if (!state.grabMouse && state.warpState == WARP_STATE_ON)
{ {
const SDL_Point newPos = { const SDL_Point newPos = {
@ -929,23 +939,6 @@ static void handleMouseMoveEvent(int ex, int ey)
DEBUG_ERROR("failed to send mouse motion message"); DEBUG_ERROR("failed to send mouse motion message");
} }
static void alignMouseWithHost()
{
if (state.ignoreInput || !params.useSpiceInput)
return;
if (!state.haveCursorPos)
return;
const int dx = round((state.curLocalX - state.dstRect.x) * state.scaleX) -
state.cursor.x;
const int dy = round((state.curLocalY - state.dstRect.y) * state.scaleY) -
state.cursor.y;
spice_mouse_motion(dx, dy);
}
static void handleResizeEvent(unsigned int w, unsigned int h) static void handleResizeEvent(unsigned int w, unsigned int h)
{ {
if (state.windowW == w && state.windowH == h) if (state.windowW == w && state.windowH == h)
@ -980,6 +973,8 @@ static void handleWindowLeave()
static void handleWindowEnter() static void handleWindowEnter()
{ {
state.cursorInWindow = true; state.cursorInWindow = true;
return;
if (state.warpState == WARP_STATE_OFF) if (state.warpState == WARP_STATE_OFF)
state.warpState = WARP_STATE_ON; state.warpState = WARP_STATE_ON;
@ -989,7 +984,6 @@ static void handleWindowEnter()
if (!state.haveCursorPos) if (!state.haveCursorPos)
return; return;
alignMouseWithHost();
state.drawCursor = true; state.drawCursor = true;
state.updateCursor = true; state.updateCursor = true;
} }