[client] sync the mouse position on startup with the host

This commit is contained in:
Geoffrey McRae 2017-10-29 15:01:31 +11:00
parent 09ce136346
commit be792f33ce
2 changed files with 26 additions and 22 deletions

View File

@ -30,9 +30,9 @@ struct KVMGFXHeader
uint32_t width; // the width
uint32_t height; // the height
uint32_t stride; // the row stride
uint64_t frames; // total frame count
uint64_t clientFrame; // current client frame
uint32_t dataLen; // total lengh of the data after this header
int32_t mouseX; // the initial mouse X position
int32_t mouseY; // the initial mouse Y position
uint64_t dataLen; // total lengh of the data after this header
};
#pragma pack(push,1)

View File

@ -39,6 +39,7 @@ CopyJob;
struct KVMGFXState
{
bool running;
bool started;
SDL_Window * window;
SDL_Renderer * renderer;
struct KVMGFXHeader * shm;
@ -197,9 +198,6 @@ void drawFunc_XOR(CompFunc compFunc, SDL_Texture * texture, uint8_t * dst, const
ivshmem_kick_irq(state.shm->guestID, 0);
SDL_UnlockTexture(texture);
if (state.shm->frames == 1)
SDL_RenderClear(state.renderer);
SDL_RenderCopy(state.renderer, texture, NULL, NULL);
SDL_RenderPresent(state.renderer);
@ -238,7 +236,6 @@ int renderThread(void * unused)
format.width = 0;
format.height = 0;
format.stride = 0;
format.frames = 0;
while(state.running)
{
@ -321,13 +318,9 @@ int renderThread(void * unused)
memcpy(&format, state.shm, sizeof(format));
}
if (format.frames != state.shm->frames - 1)
DEBUG_INFO("dropped %lu", state.shm->frames - format.frames);
format.frames = state.shm->frames;
glDisable(GL_COLOR_LOGIC_OP);
drawFunc(compFunc, texture, texPixels, pixels);
state.shm->clientFrame = format.frames;
state.started = true;
}
SDL_DestroyTexture(texture);
@ -381,29 +374,40 @@ static inline const uint32_t mapScancode(SDL_Scancode scancode)
int eventThread(void * arg)
{
bool serverMode = false;
int mouseX = 0;
int mouseY = 0;
int repeatCount = 0;
bool init = false;
// ensure mouse acceleration is identical in server mode
SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
// default to server mode
bool serverMode = true;
spice_mouse_mode(true);
SDL_SetRelativeMouseMode(true);
SDL_Event event;
while(state.running)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
if (event.type == SDL_QUIT)
{
case SDL_QUIT:
state.running = false;
break;
}
if (!state.started)
continue;
if (!init)
{
mouseX = state.shm->mouseX;
mouseY = state.shm->mouseY;
spice_mouse_mode(false);
SDL_WarpMouseInWindow(state.window, mouseX, mouseY);
init = true;
}
switch(event.type)
{
case SDL_KEYDOWN:
{
SDL_Scancode sc = event.key.keysym.scancode;