diff --git a/lib/platform/CMSWindowsDesks.cpp b/lib/platform/CMSWindowsDesks.cpp index 2b62ba70..b6319bc7 100644 --- a/lib/platform/CMSWindowsDesks.cpp +++ b/lib/platform/CMSWindowsDesks.cpp @@ -72,6 +72,8 @@ #define SYNERGY_MSG_SYNC_KEYS SYNERGY_HOOK_LAST_MSG + 9 // install; #define SYNERGY_MSG_SCREENSAVER SYNERGY_HOOK_LAST_MSG + 10 +// dx; dy +#define SYNERGY_MSG_FAKE_REL_MOVE SYNERGY_HOOK_LAST_MSG + 11 // // CMSWindowsDesks @@ -293,6 +295,14 @@ CMSWindowsDesks::fakeMouseMove(SInt32 x, SInt32 y) const static_cast(y)); } +void +CMSWindowsDesks::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const +{ + sendMessage(SYNERGY_MSG_FAKE_REL_MOVE, + static_cast(dx), + static_cast(dy)); +} + void CMSWindowsDesks::fakeMouseWheel(SInt32 delta) const { @@ -492,40 +502,47 @@ CMSWindowsDesks::deskMouseMove(SInt32 x, SInt32 y) const // the right place, the effect is disconcerting. // // instead we'll get the cursor's current position and do just a - // relative move from there to the desired position. relative - // moves are subject to cursor acceleration which we don't want. - // so we disable acceleration, do the relative move, then restore - // acceleration. there's a slight chance we'll end up in the - // wrong place if the user moves the cursor using this system's + // relative move from there to the desired position. + else { + POINT pos; + GetCursorPos(&pos); + deskMouseRelativeMove(x - pos.x, y - pos.y); + } +} + +void +CMSWindowsDesks::deskMouseRelativeMove(SInt32 dx, SInt32 dy) const +{ + // relative moves are subject to cursor acceleration which we don't + // want.so we disable acceleration, do the relative move, then + // restore acceleration. there's a slight chance we'll end up in + // the wrong place if the user moves the cursor using this system's // mouse while simultaneously moving the mouse on the server // system. that defeats the purpose of synergy so we'll assume // that won't happen. even if it does, the next mouse move will // correct the position. - else { - // save mouse speed & acceleration - int oldSpeed[4]; - bool accelChanged = - SystemParametersInfo(SPI_GETMOUSE,0, oldSpeed, 0) && - SystemParametersInfo(SPI_GETMOUSESPEED, 0, oldSpeed + 3, 0); - // use 1:1 motion - if (accelChanged) { - int newSpeed[4] = { 0, 0, 0, 1 }; - accelChanged = - SystemParametersInfo(SPI_SETMOUSE, 0, newSpeed, 0) || - SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed + 3, 0); - } + // save mouse speed & acceleration + int oldSpeed[4]; + bool accelChanged = + SystemParametersInfo(SPI_GETMOUSE,0, oldSpeed, 0) && + SystemParametersInfo(SPI_GETMOUSESPEED, 0, oldSpeed + 3, 0); - // move relative to mouse position - POINT pos; - GetCursorPos(&pos); - mouse_event(MOUSEEVENTF_MOVE, x - pos.x, y - pos.y, 0, 0); + // use 1:1 motion + if (accelChanged) { + int newSpeed[4] = { 0, 0, 0, 1 }; + accelChanged = + SystemParametersInfo(SPI_SETMOUSE, 0, newSpeed, 0) || + SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed + 3, 0); + } - // restore mouse speed & acceleration - if (accelChanged) { - SystemParametersInfo(SPI_SETMOUSE, 0, oldSpeed, 0); - SystemParametersInfo(SPI_SETMOUSESPEED, 0, oldSpeed + 3, 0); - } + // move relative to mouse position + mouse_event(MOUSEEVENTF_MOVE, dx, dy, 0, 0); + + // restore mouse speed & acceleration + if (accelChanged) { + SystemParametersInfo(SPI_SETMOUSE, 0, oldSpeed, 0); + SystemParametersInfo(SPI_SETMOUSESPEED, 0, oldSpeed + 3, 0); } } @@ -693,6 +710,11 @@ CMSWindowsDesks::deskThread(void* vdesk) static_cast(msg.lParam)); break; + case SYNERGY_MSG_FAKE_REL_MOVE: + deskMouseRelativeMove(static_cast(msg.wParam), + static_cast(msg.lParam)); + break; + case SYNERGY_MSG_FAKE_WHEEL: mouse_event(MOUSEEVENTF_WHEEL, 0, 0, msg.wParam, 0); break; diff --git a/lib/platform/CMSWindowsDesks.h b/lib/platform/CMSWindowsDesks.h index 774fad5d..9b966416 100644 --- a/lib/platform/CMSWindowsDesks.h +++ b/lib/platform/CMSWindowsDesks.h @@ -144,6 +144,12 @@ public: */ void fakeMouseMove(SInt32 x, SInt32 y) const; + //! Fake mouse move + /*! + Synthesize a mouse move to the relative coordinates \c dx,dy. + */ + void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const; + //! Fake mouse wheel /*! Synthesize a mouse wheel event of amount \c delta. @@ -176,6 +182,7 @@ private: // message handlers void deskMouseMove(SInt32 x, SInt32 y) const; + void deskMouseRelativeMove(SInt32 dx, SInt32 dy) const; void deskEnter(CDesk* desk); void deskLeave(CDesk* desk, HKL keyLayout); void deskThread(void* vdesk); diff --git a/lib/platform/CMSWindowsScreen.cpp b/lib/platform/CMSWindowsScreen.cpp index 39d40dc1..5af88523 100644 --- a/lib/platform/CMSWindowsScreen.cpp +++ b/lib/platform/CMSWindowsScreen.cpp @@ -507,6 +507,12 @@ CMSWindowsScreen::fakeMouseMove(SInt32 x, SInt32 y) const m_desks->fakeMouseMove(x, y); } +void +CMSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const +{ + m_desks->fakeMouseRelativeMove(dx, dy); +} + void CMSWindowsScreen::fakeMouseWheel(SInt32 delta) const { diff --git a/lib/platform/CMSWindowsScreen.h b/lib/platform/CMSWindowsScreen.h index 5dc64f73..5bb3d587 100644 --- a/lib/platform/CMSWindowsScreen.h +++ b/lib/platform/CMSWindowsScreen.h @@ -75,6 +75,7 @@ public: // ISecondaryScreen overrides virtual void fakeMouseButton(ButtonID id, bool press) const; virtual void fakeMouseMove(SInt32 x, SInt32 y) const; + virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const; virtual void fakeMouseWheel(SInt32 delta) const; // IKeyState overrides