diff --git a/client/src/app.c b/client/src/app.c index c2b5e66f..416433ef 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -112,7 +112,7 @@ void app_handleFocusEvent(bool focused) g_state.ds->minimize(); } - core_setGuestCursorPos(); + g_cursor.realign = true; g_state.ds->realignPointer(); } @@ -124,7 +124,7 @@ void app_handleEnterEvent(bool entered) if (!core_inputEnabled()) return; - core_setGuestCursorPos(); + g_cursor.realign = true; } else { diff --git a/client/src/core.c b/client/src/core.c index 933da515..ab51a6ad 100644 --- a/client/src/core.c +++ b/client/src/core.c @@ -314,46 +314,6 @@ 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; @@ -430,7 +390,7 @@ void core_handleMouseNormal(double ex, double ey) const bool inView = isInView(); core_setCursorInView(inView); if (inView) - core_setGuestCursorPos(); + g_cursor.realign = true; } /* nothing to do if we are outside the viewport */ @@ -451,9 +411,44 @@ void core_handleMouseNormal(double ex, double ey) struct DoublePoint guest; util_localCurToGuest(&guest); - /* 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); + 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); + } g_cursor.realign = false; diff --git a/client/src/core.h b/client/src/core.h index cef63e75..5874b54c 100644 --- a/client/src/core.h +++ b/client/src/core.h @@ -33,7 +33,6 @@ 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);