mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[guest] reworked mouse sync to better handle resolution changes
This commit is contained in:
parent
12617479d4
commit
f75d5b7f54
@ -299,9 +299,7 @@ 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)
|
||||||
|
{
|
||||||
|
x = event.motion.x - state.shm->mouseX;
|
||||||
|
y = event.motion.y - state.shm->mouseY;
|
||||||
|
realignGuest = false;
|
||||||
|
state.windowChanged = false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ok = spice_mouse_motion(
|
{
|
||||||
(int)event.motion.x - mouseX,
|
x = event.motion.xrel;
|
||||||
(int)event.motion.y - mouseY
|
y = event.motion.yrel;
|
||||||
);
|
}
|
||||||
|
|
||||||
if (!ok)
|
if (x != 0 || y != 0)
|
||||||
|
if (!spice_mouse_motion(x, y))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("SDL_MOUSEMOTION: failed to send message");
|
DEBUG_ERROR("SDL_MOUSEMOTION: failed to send message");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseX = event.motion.x;
|
|
||||||
mouseY = event.motion.y;
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user