Relative mouse motion for OS X.
This commit is contained in:
parent
a1bd77f91a
commit
500362d5c0
|
@ -29,6 +29,7 @@
|
|||
COSXScreen::COSXScreen(bool isPrimary) :
|
||||
m_isPrimary(isPrimary),
|
||||
m_isOnScreen(m_isPrimary),
|
||||
m_cursorPosValid(false),
|
||||
m_cursorHidden(false),
|
||||
m_keyState(NULL),
|
||||
m_sequenceNumber(0),
|
||||
|
@ -96,6 +97,9 @@ COSXScreen::getCursorPos(SInt32& x, SInt32& y) const
|
|||
GetGlobalMouse(&mouse);
|
||||
x = mouse.h;
|
||||
y = mouse.v;
|
||||
m_cursorPosValid = true;
|
||||
m_xCursor = x;
|
||||
m_yCursor = y;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -117,6 +121,7 @@ COSXScreen::warpCursor(SInt32 x, SInt32 y)
|
|||
// save new cursor position
|
||||
m_xCursor = x;
|
||||
m_yCursor = y;
|
||||
m_cursorPosValid = true;
|
||||
}
|
||||
|
||||
SInt32
|
||||
|
@ -157,6 +162,10 @@ COSXScreen::fakeMouseButton(ButtonID id, bool press) const
|
|||
// use this API and if we want to support more buttons we have
|
||||
// to recompile.
|
||||
CGPoint pos;
|
||||
if (!m_cursorPosValid) {
|
||||
SInt32 x, y;
|
||||
getCursorPos(x, y);
|
||||
}
|
||||
pos.x = m_xCursor;
|
||||
pos.y = m_yCursor;
|
||||
CGPostMouseEvent(pos, false, sizeof(m_buttons) / sizeof(m_buttons[0]),
|
||||
|
@ -180,6 +189,30 @@ COSXScreen::fakeMouseMove(SInt32 x, SInt32 y) const
|
|||
// save new cursor position
|
||||
m_xCursor = x;
|
||||
m_yCursor = y;
|
||||
m_cursorPosValid = true;
|
||||
}
|
||||
|
||||
void
|
||||
COSXScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
|
||||
{
|
||||
// OS X does not appear to have a fake relative mouse move function.
|
||||
// simulate it by getting the current mouse position and adding to
|
||||
// that. this can yield the wrong answer but there's not much else
|
||||
// we can do.
|
||||
|
||||
// get current position
|
||||
Point oldPos;
|
||||
GetGlobalMouse(&oldPos);
|
||||
|
||||
// synthesize event
|
||||
CGPoint pos;
|
||||
pos.x = oldPos.h + dx;
|
||||
pos.y = oldPos.v + dy;
|
||||
// FIXME -- is it okay to pass no buttons here?
|
||||
CGPostMouseEvent(pos, true, 0, m_buttons[0]);
|
||||
|
||||
// we now assume we don't know the current cursor position
|
||||
m_cursorPosValid = false;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -50,6 +50,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;
|
||||
|
||||
// IPlatformScreen overrides
|
||||
|
@ -93,6 +94,7 @@ private:
|
|||
|
||||
// mouse state
|
||||
mutable SInt32 m_xCursor, m_yCursor;
|
||||
mutable bool m_cursorPosValid;
|
||||
mutable boolean_t m_buttons[5];
|
||||
bool m_cursorHidden;
|
||||
|
||||
|
|
Loading…
Reference in New Issue