From 17617cc4214462b158a57754a821f67d29f26fc1 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 19 Aug 2021 22:57:03 +1000 Subject: [PATCH] [client] core: realign in the enter/focus handlers if possible --- client/src/app.c | 4 +-- client/src/core.c | 83 +++++++++++++++++++++++++---------------------- client/src/core.h | 1 + 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/client/src/app.c b/client/src/app.c index 416433ef..c2b5e66f 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -112,7 +112,7 @@ void app_handleFocusEvent(bool focused) g_state.ds->minimize(); } - g_cursor.realign = true; + core_setGuestCursorPos(); g_state.ds->realignPointer(); } @@ -124,7 +124,7 @@ void app_handleEnterEvent(bool entered) if (!core_inputEnabled()) return; - g_cursor.realign = true; + core_setGuestCursorPos(); } else { diff --git a/client/src/core.c b/client/src/core.c index ab51a6ad..933da515 100644 --- a/client/src/core.c +++ b/client/src/core.c @@ -314,6 +314,46 @@ void core_stopFrameThread(void) g_state.frameThread = NULL; } +void core_setGuestCursorPos(void) +{ + struct DoublePoint guest; + util_localCurToGuest(&guest); + + if (!(g_state.kvmfrFeatures & KVMFR_FEATURE_SETCURSORPOS)) + { + g_cursor.realign = true; + return; + } + + const KVMFRSetCursorPos msg = { + .msg.type = KVMFR_MESSAGE_SETCURSORPOS, + .x = round(guest.x), + .y = round(guest.y) + }; + + uint32_t setPosSerial; + if (lgmpClientSendData(g_state.pointerQueue, + &msg, sizeof(msg), &setPosSerial) != LGMP_OK) + return; + + /* wait for the move request to be processed */ + do + { + uint32_t hostSerial; + if (lgmpClientGetSerial(g_state.pointerQueue, &hostSerial) != LGMP_OK) + return; + + if (hostSerial >= setPosSerial) + break; + + g_state.ds->wait(1); + } + while(app_isRunning()); + + g_cursor.guest.x = msg.x; + g_cursor.guest.y = msg.y; +} + void core_handleGuestMouseUpdate(void) { struct DoublePoint localPos; @@ -390,7 +430,7 @@ void core_handleMouseNormal(double ex, double ey) const bool inView = isInView(); core_setCursorInView(inView); if (inView) - g_cursor.realign = true; + core_setGuestCursorPos(); } /* nothing to do if we are outside the viewport */ @@ -411,44 +451,9 @@ void core_handleMouseNormal(double ex, double ey) struct DoublePoint guest; util_localCurToGuest(&guest); - if (g_state.kvmfrFeatures & KVMFR_FEATURE_SETCURSORPOS) - { - const KVMFRSetCursorPos msg = { - .msg.type = KVMFR_MESSAGE_SETCURSORPOS, - .x = round(guest.x), - .y = round(guest.y) - }; - - uint32_t setPosSerial; - if (lgmpClientSendData(g_state.pointerQueue, - &msg, sizeof(msg), &setPosSerial) == LGMP_OK) - { - /* wait for the move request to be processed */ - do - { - uint32_t hostSerial; - if (lgmpClientGetSerial(g_state.pointerQueue, &hostSerial) != LGMP_OK) - return; - - if (hostSerial >= setPosSerial) - break; - - g_state.ds->wait(1); - } - while(app_isRunning()); - - g_cursor.guest.x = msg.x; - g_cursor.guest.y = msg.y; - g_cursor.realign = false; - return; - } - } - else - { - /* add the difference to the offset */ - ex += guest.x - (g_cursor.guest.x + g_cursor.guest.hx); - ey += guest.y - (g_cursor.guest.y + g_cursor.guest.hy); - } + /* add the difference to the offset */ + ex += guest.x - (g_cursor.guest.x + g_cursor.guest.hx); + ey += guest.y - (g_cursor.guest.y + g_cursor.guest.hy); g_cursor.realign = false; diff --git a/client/src/core.h b/client/src/core.h index 5874b54c..cef63e75 100644 --- a/client/src/core.h +++ b/client/src/core.h @@ -33,6 +33,7 @@ void core_alignToGuest(void); bool core_isValidPointerPos(int x, int y); bool core_startFrameThread(void); void core_stopFrameThread(void); +void core_setGuestCursorPos(void); void core_handleGuestMouseUpdate(void); void core_handleMouseGrabbed(double ex, double ey); void core_handleMouseNormal(double ex, double ey);