[client] more cursor tweaks and some cleanup

This commit is contained in:
Geoffrey McRae 2020-01-11 05:22:12 +11:00
parent 1341bf8fbd
commit 80f3c7934a
3 changed files with 55 additions and 31 deletions

View File

@ -1 +1 @@
B1-75-g5b163063c3+1 B1-76-g1341bf8fbd+1

View File

@ -67,17 +67,9 @@ struct AppState state;
// this structure is initialized in config.c // this structure is initialized in config.c
struct AppParams params = { 0 }; struct AppParams params = { 0 };
static int lastX = 0; static void handleMouseMoveEvent(int ex, int ey);
static int lastY = 0; static void alignMouseWithGuest();
static void alignMouseWithGuest() static void alignMouseWithHost();
{
if (state.ignoreInput || !params.useSpiceInput)
return;
lastX = (int)round((float)state.cursor.x / state.scaleX) + state.dstRect.x;
lastY = (int)round((float)state.cursor.y / state.scaleY) + state.dstRect.y;
SDL_WarpMouseInWindow(state.window, lastX, lastY);
}
static void updatePositionInfo() static void updatePositionInfo()
{ {
@ -292,7 +284,12 @@ static int cursorThread(void * unused)
state.cursor.x = cursor->x; state.cursor.x = cursor->x;
state.cursor.y = cursor->y; state.cursor.y = cursor->y;
state.cursorVisible = cursor->visible; state.cursorVisible = cursor->visible;
if (!state.haveCursorPos)
{
state.haveCursorPos = true; state.haveCursorPos = true;
alignMouseWithHost();
}
if (msg.udata == 1) if (msg.udata == 1)
{ {
@ -331,14 +328,6 @@ static int cursorThread(void * unused)
state.cursor.x, state.cursor.x,
state.cursor.y state.cursor.y
); );
const uint64_t now = microtime();
static uint64_t nextAlign = 0;
if (!state.serverMode && now > nextAlign)
{
nextAlign = now + 100000;
alignMouseWithGuest();
}
} }
lgmpClientUnsubscribe(&queue); lgmpClientUnsubscribe(&queue);
@ -650,14 +639,17 @@ static void handleMouseMoveEvent(int ex, int ey)
if (state.ignoreInput || !params.useSpiceInput) if (state.ignoreInput || !params.useSpiceInput)
return; return;
state.curlocalX = ex;
state.curlocalY = ey;
if (state.serverMode) if (state.serverMode)
{ {
if (wrapping) if (wrapping)
{ {
if (ex == state.windowW / 2 && ey == state.windowH / 2) if (ex == state.windowW / 2 && ey == state.windowH / 2)
{ {
lastX += (state.windowW / 2) - wrapX; state.curLastX += (state.windowW / 2) - wrapX;
lastY += (state.windowH / 2) - wrapY; state.curLastY += (state.windowH / 2) - wrapY;
wrapping = false; wrapping = false;
} }
} }
@ -683,10 +675,10 @@ static void handleMouseMoveEvent(int ex, int ey)
return; return;
} }
int rx = ex - lastX; int rx = ex - state.curLastX;
int ry = ey - lastY; int ry = ey - state.curLastY;
lastX = ex; state.curLastX = ex;
lastY = ey; state.curLastY = ey;
if (rx == 0 && ry == 0) if (rx == 0 && ry == 0)
return; return;
@ -715,6 +707,29 @@ 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 alignMouseWithGuest()
{
if (state.ignoreInput || !params.useSpiceInput)
return;
state.curLastX = (int)round((float)state.cursor.x / state.scaleX) + state.dstRect.x;
state.curLastY = (int)round((float)state.cursor.y / state.scaleY) + state.dstRect.y;
SDL_WarpMouseInWindow(state.window, state.curLastX, state.curLastY);
}
static void alignMouseWithHost()
{
if (state.ignoreInput || !params.useSpiceInput)
return;
if (!state.haveCursorPos || state.serverMode)
return;
state.curLastX = (int)round((float)state.cursor.x / state.scaleX) + state.dstRect.x;
state.curLastY = (int)round((float)state.cursor.y / state.scaleY) + state.dstRect.y;
handleMouseMoveEvent(state.curlocalX, state.curlocalY);
}
static void handleResizeEvent(unsigned int w, unsigned int h) static void handleResizeEvent(unsigned int w, unsigned int h)
{ {
if (state.windowW == w || state.windowH == w) if (state.windowW == w || state.windowH == w)
@ -743,6 +758,10 @@ int eventFilter(void * userdata, SDL_Event * event)
{ {
switch(event->window.event) switch(event->window.event)
{ {
case SDL_WINDOWEVENT_ENTER:
alignMouseWithHost();
break;
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
if (state.wminfo.subsystem != SDL_SYSWM_X11) if (state.wminfo.subsystem != SDL_SYSWM_X11)

View File

@ -43,10 +43,15 @@ struct AppState
LG_RendererRect dstRect; LG_RendererRect dstRect;
SDL_Point cursor; SDL_Point cursor;
bool cursorVisible; bool cursorVisible;
bool serverMode;
bool haveCursorPos; bool haveCursorPos;
float scaleX, scaleY; float scaleX, scaleY;
float accX, accY; float accX, accY;
bool serverMode; int curLastX;
int curLastY;
int curlocalX;
int curlocalY;
const LG_Renderer * lgr; const LG_Renderer * lgr;
void * lgrData; void * lgrData;