[client] more cursor tweaks for better integration with the WM

This commit is contained in:
Geoffrey McRae 2020-01-11 06:03:16 +11:00
parent 80f3c7934a
commit 05dc713dac
3 changed files with 65 additions and 13 deletions

View file

@ -1 +1 @@
B1-76-g1341bf8fbd+1
B1-77-g80f3c7934a+1

View file

@ -271,6 +271,18 @@ static int cursorThread(void * unused)
{
if (status == LGMP_ERR_QUEUE_EMPTY)
{
if (state.updateCursor)
{
state.updateCursor = false;
state.lgr->on_mouse_event
(
state.lgrData,
state.cursorVisible && state.drawCursor,
state.cursor.x,
state.cursor.y
);
}
usleep(params.cursorPollInterval);
continue;
}
@ -284,11 +296,12 @@ static int cursorThread(void * unused)
state.cursor.x = cursor->x;
state.cursor.y = cursor->y;
state.cursorVisible = cursor->visible;
state.haveCursorPos = true;
if (!state.haveCursorPos)
if (!state.haveAligned && state.haveSrcSize && state.haveCurLocal)
{
state.haveCursorPos = true;
alignMouseWithHost();
state.haveAligned = true;
}
if (msg.udata == 1)
@ -321,10 +334,11 @@ static int cursorThread(void * unused)
}
lgmpClientMessageDone(queue);
state.updateCursor = false;
state.lgr->on_mouse_event
(
state.lgrData,
state.cursorVisible,
state.cursorVisible && state.drawCursor,
state.cursor.x,
state.cursor.y
);
@ -424,7 +438,6 @@ static int frameThread(void * unused)
SDL_SetWindowSize(state.window, frame->width, frame->height);
updatePositionInfo();
alignMouseWithGuest();
}
FrameBuffer fb = (FrameBuffer)(frame + 1);
@ -636,12 +649,13 @@ static void handleMouseMoveEvent(int ex, int ey)
static bool wrapping = false;
static int wrapX, wrapY;
state.curLocalX = ex;
state.curLocalY = ey;
state.haveCurLocal = true;
if (state.ignoreInput || !params.useSpiceInput)
return;
state.curlocalX = ex;
state.curlocalY = ey;
if (state.serverMode)
{
if (wrapping)
@ -727,12 +741,12 @@ static void alignMouseWithHost()
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);
handleMouseMoveEvent(state.curLocalX, state.curLocalY);
}
static void handleResizeEvent(unsigned int w, unsigned int h)
{
if (state.windowW == w || state.windowH == w)
if (state.windowW == w && state.windowH == h)
return;
state.windowW = w;
@ -740,6 +754,25 @@ static void handleResizeEvent(unsigned int w, unsigned int h)
updatePositionInfo();
}
static void handleWindowLeave()
{
if (!params.useSpiceInput)
return;
state.drawCursor = false;
state.updateCursor = true;
}
static void handleWindowEnter()
{
if (!params.useSpiceInput)
return;
alignMouseWithHost();
state.drawCursor = true;
state.updateCursor = true;
}
int eventFilter(void * userdata, SDL_Event * event)
{
switch(event->type)
@ -759,7 +792,13 @@ int eventFilter(void * userdata, SDL_Event * event)
switch(event->window.event)
{
case SDL_WINDOWEVENT_ENTER:
alignMouseWithHost();
if (state.wminfo.subsystem != SDL_SYSWM_X11)
handleWindowEnter();
break;
case SDL_WINDOWEVENT_LEAVE:
if (state.wminfo.subsystem != SDL_SYSWM_X11)
handleWindowLeave();
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
@ -793,6 +832,14 @@ int eventFilter(void * userdata, SDL_Event * event)
case MotionNotify:
handleMouseMoveEvent(xe.xmotion.x, xe.xmotion.y);
break;
case EnterNotify:
handleWindowEnter();
break;
case LeaveNotify:
handleWindowLeave();
break;
}
}
@ -1083,6 +1130,7 @@ static int lg_run()
state.scaleX = 1.0f;
state.scaleY = 1.0f;
state.resizeDone = true;
state.drawCursor = true;
state.mouseSens = params.mouseSens;
if (state.mouseSens < -9) state.mouseSens = -9;

View file

@ -46,12 +46,16 @@ struct AppState
bool serverMode;
bool haveCursorPos;
bool drawCursor;
bool updateCursor;
float scaleX, scaleY;
float accX, accY;
int curLastX;
int curLastY;
int curlocalX;
int curlocalY;
bool haveCurLocal;
int curLocalX;
int curLocalY;
bool haveAligned;
const LG_Renderer * lgr;
void * lgrData;