Added relative mouse move support to win32.

This commit is contained in:
crs 2004-05-02 08:04:15 +00:00
parent 0f45face21
commit 9c35a45a2c
4 changed files with 63 additions and 27 deletions

View File

@ -72,6 +72,8 @@
#define SYNERGY_MSG_SYNC_KEYS SYNERGY_HOOK_LAST_MSG + 9 #define SYNERGY_MSG_SYNC_KEYS SYNERGY_HOOK_LAST_MSG + 9
// install; <unused> // install; <unused>
#define SYNERGY_MSG_SCREENSAVER SYNERGY_HOOK_LAST_MSG + 10 #define SYNERGY_MSG_SCREENSAVER SYNERGY_HOOK_LAST_MSG + 10
// dx; dy
#define SYNERGY_MSG_FAKE_REL_MOVE SYNERGY_HOOK_LAST_MSG + 11
// //
// CMSWindowsDesks // CMSWindowsDesks
@ -293,6 +295,14 @@ CMSWindowsDesks::fakeMouseMove(SInt32 x, SInt32 y) const
static_cast<LPARAM>(y)); static_cast<LPARAM>(y));
} }
void
CMSWindowsDesks::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
{
sendMessage(SYNERGY_MSG_FAKE_REL_MOVE,
static_cast<WPARAM>(dx),
static_cast<LPARAM>(dy));
}
void void
CMSWindowsDesks::fakeMouseWheel(SInt32 delta) const CMSWindowsDesks::fakeMouseWheel(SInt32 delta) const
{ {
@ -492,40 +502,47 @@ CMSWindowsDesks::deskMouseMove(SInt32 x, SInt32 y) const
// the right place, the effect is disconcerting. // the right place, the effect is disconcerting.
// //
// instead we'll get the cursor's current position and do just a // instead we'll get the cursor's current position and do just a
// relative move from there to the desired position. relative // relative move from there to the desired position.
// moves are subject to cursor acceleration which we don't want. else {
// so we disable acceleration, do the relative move, then restore POINT pos;
// acceleration. there's a slight chance we'll end up in the GetCursorPos(&pos);
// wrong place if the user moves the cursor using this system's 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 // mouse while simultaneously moving the mouse on the server
// system. that defeats the purpose of synergy so we'll assume // system. that defeats the purpose of synergy so we'll assume
// that won't happen. even if it does, the next mouse move will // that won't happen. even if it does, the next mouse move will
// correct the position. // 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 // save mouse speed & acceleration
if (accelChanged) { int oldSpeed[4];
int newSpeed[4] = { 0, 0, 0, 1 }; bool accelChanged =
accelChanged = SystemParametersInfo(SPI_GETMOUSE,0, oldSpeed, 0) &&
SystemParametersInfo(SPI_SETMOUSE, 0, newSpeed, 0) || SystemParametersInfo(SPI_GETMOUSESPEED, 0, oldSpeed + 3, 0);
SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed + 3, 0);
}
// move relative to mouse position // use 1:1 motion
POINT pos; if (accelChanged) {
GetCursorPos(&pos); int newSpeed[4] = { 0, 0, 0, 1 };
mouse_event(MOUSEEVENTF_MOVE, x - pos.x, y - pos.y, 0, 0); accelChanged =
SystemParametersInfo(SPI_SETMOUSE, 0, newSpeed, 0) ||
SystemParametersInfo(SPI_SETMOUSESPEED, 0, newSpeed + 3, 0);
}
// restore mouse speed & acceleration // move relative to mouse position
if (accelChanged) { mouse_event(MOUSEEVENTF_MOVE, dx, dy, 0, 0);
SystemParametersInfo(SPI_SETMOUSE, 0, oldSpeed, 0);
SystemParametersInfo(SPI_SETMOUSESPEED, 0, oldSpeed + 3, 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<SInt32>(msg.lParam)); static_cast<SInt32>(msg.lParam));
break; break;
case SYNERGY_MSG_FAKE_REL_MOVE:
deskMouseRelativeMove(static_cast<SInt32>(msg.wParam),
static_cast<SInt32>(msg.lParam));
break;
case SYNERGY_MSG_FAKE_WHEEL: case SYNERGY_MSG_FAKE_WHEEL:
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, msg.wParam, 0); mouse_event(MOUSEEVENTF_WHEEL, 0, 0, msg.wParam, 0);
break; break;

View File

@ -144,6 +144,12 @@ public:
*/ */
void fakeMouseMove(SInt32 x, SInt32 y) const; 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 //! Fake mouse wheel
/*! /*!
Synthesize a mouse wheel event of amount \c delta. Synthesize a mouse wheel event of amount \c delta.
@ -176,6 +182,7 @@ private:
// message handlers // message handlers
void deskMouseMove(SInt32 x, SInt32 y) const; void deskMouseMove(SInt32 x, SInt32 y) const;
void deskMouseRelativeMove(SInt32 dx, SInt32 dy) const;
void deskEnter(CDesk* desk); void deskEnter(CDesk* desk);
void deskLeave(CDesk* desk, HKL keyLayout); void deskLeave(CDesk* desk, HKL keyLayout);
void deskThread(void* vdesk); void deskThread(void* vdesk);

View File

@ -507,6 +507,12 @@ CMSWindowsScreen::fakeMouseMove(SInt32 x, SInt32 y) const
m_desks->fakeMouseMove(x, y); m_desks->fakeMouseMove(x, y);
} }
void
CMSWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
{
m_desks->fakeMouseRelativeMove(dx, dy);
}
void void
CMSWindowsScreen::fakeMouseWheel(SInt32 delta) const CMSWindowsScreen::fakeMouseWheel(SInt32 delta) const
{ {

View File

@ -75,6 +75,7 @@ public:
// ISecondaryScreen overrides // ISecondaryScreen overrides
virtual void fakeMouseButton(ButtonID id, bool press) const; virtual void fakeMouseButton(ButtonID id, bool press) const;
virtual void fakeMouseMove(SInt32 x, SInt32 y) const; virtual void fakeMouseMove(SInt32 x, SInt32 y) const;
virtual void fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const;
virtual void fakeMouseWheel(SInt32 delta) const; virtual void fakeMouseWheel(SInt32 delta) const;
// IKeyState overrides // IKeyState overrides