[host] send the latest cusror information when a new client connects

This commit is contained in:
Geoffrey McRae 2020-05-25 14:37:02 +10:00
parent bc7871f630
commit 667ab981ba
2 changed files with 53 additions and 21 deletions

View File

@ -1 +1 @@
B2-rc2-0-gd579705b10+1 B2-rc2-1-gbc7871f630+1

View File

@ -66,6 +66,8 @@ struct app
PLGMPHostQueue pointerQueue; PLGMPHostQueue pointerQueue;
PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN]; PLGMPMemory pointerMemory[LGMP_Q_POINTER_LEN];
LG_Lock pointerLock;
CapturePointer pointerInfo;
PLGMPMemory pointerShape; PLGMPMemory pointerShape;
bool pointerShapeValid; bool pointerShapeValid;
unsigned int pointerIndex; unsigned int pointerIndex;
@ -279,7 +281,7 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size)
// spin until there is room // spin until there is room
while(lgmpHostQueuePending(app.pointerQueue) == LGMP_Q_POINTER_LEN) while(lgmpHostQueuePending(app.pointerQueue) == LGMP_Q_POINTER_LEN)
{ {
DEBUG_INFO("pending"); usleep(1);
if (!app.running) if (!app.running)
return false; return false;
} }
@ -290,14 +292,13 @@ bool captureGetPointerBuffer(void ** data, uint32_t * size)
return true; return true;
} }
void capturePostPointerBuffer(CapturePointer pointer) static void sendPointer(bool newClient)
{ {
PLGMPMemory mem; PLGMPMemory mem;
const bool newClient = lgmpHostQueueNewSubs(app.pointerQueue) > 0;
if (pointer.shapeUpdate || newClient) if (app.pointerInfo.shapeUpdate || newClient)
{ {
if (pointer.shapeUpdate) if (app.pointerInfo.shapeUpdate)
{ {
// swap the latest shape buffer out of rotation // swap the latest shape buffer out of rotation
PLGMPMemory tmp = app.pointerShape; PLGMPMemory tmp = app.pointerShape;
@ -309,32 +310,31 @@ void capturePostPointerBuffer(CapturePointer pointer)
mem = app.pointerShape; mem = app.pointerShape;
} }
else else
{
mem = app.pointerMemory[app.pointerIndex]; mem = app.pointerMemory[app.pointerIndex];
if (++app.pointerIndex == LGMP_Q_POINTER_LEN)
app.pointerIndex = 0; if (++app.pointerIndex == LGMP_Q_POINTER_LEN)
} app.pointerIndex = 0;
uint32_t flags = 0; uint32_t flags = 0;
KVMFRCursor *cursor = lgmpHostMemPtr(mem); KVMFRCursor *cursor = lgmpHostMemPtr(mem);
if (pointer.positionUpdate) if (app.pointerInfo.positionUpdate || newClient)
{ {
flags |= CURSOR_FLAG_POSITION; flags |= CURSOR_FLAG_POSITION;
cursor->x = pointer.x; cursor->x = app.pointerInfo.x;
cursor->y = pointer.y; cursor->y = app.pointerInfo.y;
} }
if (pointer.visible) if (app.pointerInfo.visible)
flags |= CURSOR_FLAG_VISIBLE; flags |= CURSOR_FLAG_VISIBLE;
if (pointer.shapeUpdate) if (app.pointerInfo.shapeUpdate)
{ {
// remember which slot has the latest shape // remember which slot has the latest shape
cursor->width = pointer.width; cursor->width = app.pointerInfo.width;
cursor->height = pointer.height; cursor->height = app.pointerInfo.height;
cursor->pitch = pointer.pitch; cursor->pitch = app.pointerInfo.pitch;
switch(pointer.format) switch(app.pointerInfo.format)
{ {
case CAPTURE_FMT_COLOR : cursor->type = CURSOR_TYPE_COLOR ; break; case CAPTURE_FMT_COLOR : cursor->type = CURSOR_TYPE_COLOR ; break;
case CAPTURE_FMT_MONO : cursor->type = CURSOR_TYPE_MONOCHROME ; break; case CAPTURE_FMT_MONO : cursor->type = CURSOR_TYPE_MONOCHROME ; break;
@ -348,7 +348,7 @@ void capturePostPointerBuffer(CapturePointer pointer)
app.pointerShapeValid = true; app.pointerShapeValid = true;
} }
if ((pointer.shapeUpdate || newClient) && app.pointerShapeValid) if ((app.pointerInfo.shapeUpdate || newClient) && app.pointerShapeValid)
flags |= CURSOR_FLAG_SHAPE; flags |= CURSOR_FLAG_SHAPE;
LGMP_STATUS status; LGMP_STATUS status;
@ -361,10 +361,31 @@ void capturePostPointerBuffer(CapturePointer pointer)
} }
DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status));
return; break;
} }
} }
void capturePostPointerBuffer(CapturePointer pointer)
{
LG_LOCK(app.pointerLock);
int x = app.pointerInfo.x;
int y = app.pointerInfo.y;
memcpy(&app.pointerInfo, &pointer, sizeof(CapturePointer));
/* if there was not a position update, restore the x & y */
if (!pointer.positionUpdate)
{
app.pointerInfo.x = x;
app.pointerInfo.y = y;
}
sendPointer(false);
LG_UNLOCK(app.pointerLock);
}
// this is called from the platform specific startup routine // this is called from the platform specific startup routine
int app_main(int argc, char * argv[]) int app_main(int argc, char * argv[])
{ {
@ -498,6 +519,8 @@ int app_main(int argc, char * argv[])
app.iface = iface; app.iface = iface;
LG_LOCK_INIT(app.pointerLock);
if (!captureStart()) if (!captureStart())
{ {
exitcode = -1; exitcode = -1;
@ -513,6 +536,13 @@ int app_main(int argc, char * argv[])
} }
app.reinit = false; app.reinit = false;
if (lgmpHostQueueNewSubs(app.pointerQueue) > 0)
{
LG_LOCK(app.pointerLock);
sendPointer(true);
LG_UNLOCK(app.pointerLock);
}
switch(iface->capture()) switch(iface->capture())
{ {
case CAPTURE_RESULT_OK: case CAPTURE_RESULT_OK:
@ -541,6 +571,8 @@ finish:
stopThreads(); stopThreads();
exit: exit:
LG_LOCK_FREE(app.pointerLock);
iface->deinit(); iface->deinit();
iface->free(); iface->free();
fail: fail: