[guest] reworked mouse sync to better handle resolution changes

This commit is contained in:
Geoffrey McRae 2017-11-17 19:57:13 +11:00
parent 12617479d4
commit f75d5b7f54

View File

@ -298,10 +298,8 @@ static inline const uint32_t mapScancode(SDL_Scancode scancode)
int eventThread(void * arg) int eventThread(void * arg)
{ {
bool serverMode = false; bool serverMode = false;
int mouseX = 0; bool realignGuest = true;
int mouseY = 0;
bool init = false;
// ensure mouse acceleration is identical in server mode // ensure mouse acceleration is identical in server mode
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE); SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
@ -320,23 +318,6 @@ int eventThread(void * arg)
if (!state.started) if (!state.started)
continue; continue;
if (!init)
{
mouseX = state.shm->mouseX;
mouseY = state.shm->mouseY;
spice_mouse_mode(false);
SDL_WarpMouseInWindow(state.window, mouseX, mouseY);
init = true;
}
if (state.windowChanged)
{
mouseX = state.shm->mouseX;
mouseY = state.shm->mouseY;
SDL_WarpMouseInWindow(state.window, mouseX, mouseY);
state.windowChanged = false;
}
switch(event.type) switch(event.type)
{ {
case SDL_KEYDOWN: case SDL_KEYDOWN:
@ -352,11 +333,7 @@ int eventThread(void * arg)
SDL_SetRelativeMouseMode(serverMode); SDL_SetRelativeMouseMode(serverMode);
if (!serverMode) if (!serverMode)
{ realignGuest = true;
mouseX = state.shm->mouseX;
mouseY = state.shm->mouseY;
SDL_WarpMouseInWindow(state.window, mouseX, mouseY);
}
break; break;
} }
@ -404,23 +381,27 @@ int eventThread(void * arg)
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
{ {
bool ok; int x = 0;
if (serverMode) int y = 0;
ok = spice_mouse_motion(event.motion.xrel, event.motion.yrel); if (realignGuest || state.windowChanged)
else
ok = spice_mouse_motion(
(int)event.motion.x - mouseX,
(int)event.motion.y - mouseY
);
if (!ok)
{ {
DEBUG_ERROR("SDL_MOUSEMOTION: failed to send message"); x = event.motion.x - state.shm->mouseX;
break; y = event.motion.y - state.shm->mouseY;
realignGuest = false;
state.windowChanged = false;
}
else
{
x = event.motion.xrel;
y = event.motion.yrel;
} }
mouseX = event.motion.x; if (x != 0 || y != 0)
mouseY = event.motion.y; if (!spice_mouse_motion(x, y))
{
DEBUG_ERROR("SDL_MOUSEMOTION: failed to send message");
break;
}
break; break;
} }
@ -433,9 +414,6 @@ int eventThread(void * arg)
DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message"); DEBUG_ERROR("SDL_MOUSEBUTTONDOWN: failed to send message");
break; break;
} }
mouseX = event.motion.x;
mouseY = event.motion.y;
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
@ -447,11 +425,19 @@ int eventThread(void * arg)
DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message"); DEBUG_ERROR("SDL_MOUSEBUTTONUP: failed to send message");
break; break;
} }
mouseX = event.motion.x;
mouseY = event.motion.y;
break; break;
case SDL_WINDOWEVENT:
{
switch(event.window.event)
{
case SDL_WINDOWEVENT_ENTER:
realignGuest = true;
break;
}
break;
}
default: default:
break; break;
} }