refactor: use ScrollDelta for fakeMouseWheel
This commit is contained in:
parent
5612e99f1d
commit
050cb649c2
11 changed files with 28 additions and 30 deletions
|
|
@ -50,11 +50,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Synthesize a mouse wheel event of amount
|
* @brief Synthesize a mouse wheel event of amount
|
||||||
* This method should include the use of `applyScrollModifier` before sending the delta
|
* This Implmentation for this method should call `applyScrollModifier` before sending the final delta to the system
|
||||||
* @param xDelta
|
* @param delta the raw delta to fake
|
||||||
* @param yDelta
|
|
||||||
*/
|
*/
|
||||||
virtual void fakeMouseWheel(int32_t xDelta, int32_t yDelta) const = 0;
|
virtual void fakeMouseWheel(ScrollDelta delta) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Applies any scroll modfifers to the provided delta, This should only be done inside the subclasses
|
* @brief Applies any scroll modfifers to the provided delta, This should only be done inside the subclasses
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
||||||
void fakeMouseButton(ButtonID id, bool press) override = 0;
|
void fakeMouseButton(ButtonID id, bool press) override = 0;
|
||||||
void fakeMouseMove(int32_t x, int32_t y) override = 0;
|
void fakeMouseMove(int32_t x, int32_t y) override = 0;
|
||||||
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override = 0;
|
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override = 0;
|
||||||
void fakeMouseWheel(int32_t xDelta, int32_t yDelta) const override = 0;
|
void fakeMouseWheel(ScrollDelta delta) const override = 0;
|
||||||
|
|
||||||
// IKeyState overrides
|
// IKeyState overrides
|
||||||
void updateKeyMap() override;
|
void updateKeyMap() override;
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ void Screen::mouseRelativeMove(int32_t dx, int32_t dy) const
|
||||||
void Screen::mouseWheel(int32_t xDelta, int32_t yDelta) const
|
void Screen::mouseWheel(int32_t xDelta, int32_t yDelta) const
|
||||||
{
|
{
|
||||||
assert(!m_isPrimary);
|
assert(!m_isPrimary);
|
||||||
m_screen->fakeMouseWheel(xDelta, yDelta);
|
m_screen->fakeMouseWheel({xDelta, yDelta});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::resetOptions()
|
void Screen::resetOptions()
|
||||||
|
|
|
||||||
|
|
@ -313,16 +313,16 @@ void EiScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
|
||||||
ei_device_frame(m_eiPointer, ei_now(m_ei));
|
ei_device_frame(m_eiPointer, ei_now(m_ei));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EiScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
|
void EiScreen::fakeMouseWheel(ScrollDelta delta) const
|
||||||
{
|
{
|
||||||
if (!m_eiPointer)
|
if (!m_eiPointer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto adjustedDeltas = applyScrollModifier({xDelta, yDelta});
|
delta = applyScrollModifier(delta);
|
||||||
// libei and deskflow seem to use opposite directions, so we have
|
// libei and deskflow seem to use opposite directions, so we have
|
||||||
// to send EI the opposite of the value received if we want to remain
|
// to send EI the opposite of the value received if we want to remain
|
||||||
// compatible with other platforms (including X11).
|
// compatible with other platforms (including X11).
|
||||||
ei_device_scroll_discrete(m_eiPointer, -adjustedDeltas.x, -adjustedDeltas.y);
|
ei_device_scroll_discrete(m_eiPointer, -delta.x, -delta.y);
|
||||||
ei_device_frame(m_eiPointer, ei_now(m_ei));
|
ei_device_frame(m_eiPointer, ei_now(m_ei));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public:
|
||||||
void fakeMouseButton(ButtonID id, bool press) override;
|
void fakeMouseButton(ButtonID id, bool press) override;
|
||||||
void fakeMouseMove(std::int32_t x, std::int32_t y) override;
|
void fakeMouseMove(std::int32_t x, std::int32_t y) override;
|
||||||
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
|
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
|
||||||
void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override;
|
void fakeMouseWheel(ScrollDelta delta) const override;
|
||||||
void fakeKey(std::uint32_t keycode, bool isDown) const;
|
void fakeKey(std::uint32_t keycode, bool isDown) const;
|
||||||
|
|
||||||
// IPlatformScreen overrides
|
// IPlatformScreen overrides
|
||||||
|
|
|
||||||
|
|
@ -706,10 +706,10 @@ void MSWindowsScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
|
||||||
m_desks->fakeMouseRelativeMove(dx, dy);
|
m_desks->fakeMouseRelativeMove(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
|
void MSWindowsScreen::fakeMouseWheel(ScrollDelta delta) const
|
||||||
{
|
{
|
||||||
auto adjustedDeltas = applyScrollModifier({xDelta, yDelta});
|
delta = applyScrollModifier(delta);
|
||||||
m_desks->fakeMouseWheel(adjustedDeltas.x, adjustedDeltas.y);
|
m_desks->fakeMouseWheel(delta.x, delta.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsScreen::updateKeys()
|
void MSWindowsScreen::updateKeys()
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ public:
|
||||||
void fakeMouseButton(ButtonID id, bool press) override;
|
void fakeMouseButton(ButtonID id, bool press) override;
|
||||||
void fakeMouseMove(int32_t x, int32_t y) override;
|
void fakeMouseMove(int32_t x, int32_t y) override;
|
||||||
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
||||||
void fakeMouseWheel(int32_t xDelta, int32_t yDelta) const override;
|
void fakeMouseWheel(ScrollDelta delta) const override;
|
||||||
|
|
||||||
// IKeyState overrides
|
// IKeyState overrides
|
||||||
virtual void updateKeys();
|
virtual void updateKeys();
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public:
|
||||||
void fakeMouseButton(ButtonID id, bool press) override;
|
void fakeMouseButton(ButtonID id, bool press) override;
|
||||||
void fakeMouseMove(int32_t x, int32_t y) override;
|
void fakeMouseMove(int32_t x, int32_t y) override;
|
||||||
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
||||||
void fakeMouseWheel(int32_t xDelta, int32_t yDelta) const override;
|
void fakeMouseWheel(ScrollDelta delta) const override;
|
||||||
|
|
||||||
// IPlatformScreen overrides
|
// IPlatformScreen overrides
|
||||||
void enable() override;
|
void enable() override;
|
||||||
|
|
|
||||||
|
|
@ -584,17 +584,16 @@ void OSXScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
|
||||||
m_cursorPosValid = false;
|
m_cursorPosValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
|
void OSXScreen::fakeMouseWheel(ScrollDelta delta) const
|
||||||
{
|
{
|
||||||
if (xDelta != 0 || yDelta != 0) {
|
if (delta.x != 0 || delta.y != 0) {
|
||||||
// use server's acceleration with a little boost since other platforms
|
// use server's acceleration with a little boost since other platforms
|
||||||
// take one wheel step as a larger step than the mac does.
|
// take one wheel step as a larger step than the mac does.
|
||||||
auto adjustedDeltas =
|
delta =
|
||||||
applyScrollModifier({static_cast<int32_t>(3.0 * xDelta / 120.0), static_cast<int32_t>(3.0 * y / 120.0)});
|
applyScrollModifier({static_cast<int32_t>(3.0 * delta.x / 120.0), static_cast<int32_t>(3.0 * delta.y / 120.0)});
|
||||||
// create a scroll event, post it and release it. not sure if kCGScrollEventUnitLine
|
// create a scroll event, post it and release it. not sure if kCGScrollEventUnitLine
|
||||||
// is the right choice here over kCGScrollEventUnitPixel
|
// is the right choice here over kCGScrollEventUnitPixel
|
||||||
CGEventRef scrollEvent =
|
CGEventRef scrollEvent = CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, delta.y, delta.x);
|
||||||
CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, adjustedDeltas.y, adjustedDeltas.x);
|
|
||||||
|
|
||||||
// Fix for sticky keys
|
// Fix for sticky keys
|
||||||
CGEventFlags modifiers = m_keyState->getModifierStateAsOSXFlags();
|
CGEventFlags modifiers = m_keyState->getModifierStateAsOSXFlags();
|
||||||
|
|
|
||||||
|
|
@ -784,23 +784,23 @@ void XWindowsScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
|
||||||
XFlush(m_display);
|
XFlush(m_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XWindowsScreen::fakeMouseWheel(int32_t, int32_t yDelta) const
|
void XWindowsScreen::fakeMouseWheel(ScrollDelta delta) const
|
||||||
{
|
{
|
||||||
// XXX -- support x-axis scrolling
|
// XXX -- support x-axis scrolling
|
||||||
if (yDelta == 0) {
|
if (delta.y == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yDelta = applyScrollModifier({0, yDelta}).y;
|
delta = applyScrollModifier(delta);
|
||||||
|
|
||||||
// choose button depending on rotation direction
|
// choose button depending on rotation direction
|
||||||
const unsigned int xButton = mapButtonToX(yDelta >= 0 ? kX11ScrollWheelUp : kX11ScrollWheelDown);
|
const unsigned int xButton = mapButtonToX(delta.y >= 0 ? kX11ScrollWheelUp : kX11ScrollWheelDown);
|
||||||
if (xButton == 0) {
|
if (xButton == 0) {
|
||||||
// If we get here, then the XServer does not support the scroll
|
// If we get here, then the XServer does not support the scroll
|
||||||
// wheel buttons, so send PageUp/PageDown keystrokes instead.
|
// wheel buttons, so send PageUp/PageDown keystrokes instead.
|
||||||
// Patch by Tom Chadwick.
|
// Patch by Tom Chadwick.
|
||||||
KeyCode keycode = 0;
|
KeyCode keycode = 0;
|
||||||
if (yDelta >= 0) {
|
if (delta.y >= 0) {
|
||||||
keycode = XKeysymToKeycode(m_display, XK_Page_Up);
|
keycode = XKeysymToKeycode(m_display, XK_Page_Up);
|
||||||
} else {
|
} else {
|
||||||
keycode = XKeysymToKeycode(m_display, XK_Page_Down);
|
keycode = XKeysymToKeycode(m_display, XK_Page_Down);
|
||||||
|
|
@ -813,15 +813,15 @@ void XWindowsScreen::fakeMouseWheel(int32_t, int32_t yDelta) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// now use absolute value of delta
|
// now use absolute value of delta
|
||||||
if (yDelta < 0) {
|
if (delta.y < 0) {
|
||||||
yDelta = -yDelta;
|
delta.y = -delta.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delta for a "click"
|
// Delta for a "click"
|
||||||
static const auto s_mouseDelta = 120;
|
static const auto s_mouseDelta = 120;
|
||||||
|
|
||||||
// send as many clicks as necessary
|
// send as many clicks as necessary
|
||||||
for (; yDelta >= 0; yDelta -= s_mouseDelta) {
|
for (; delta.y >= 0; delta.y -= s_mouseDelta) {
|
||||||
XTestFakeButtonEvent(m_display, xButton, True, CurrentTime);
|
XTestFakeButtonEvent(m_display, xButton, True, CurrentTime);
|
||||||
XTestFakeButtonEvent(m_display, xButton, False, CurrentTime);
|
XTestFakeButtonEvent(m_display, xButton, False, CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public:
|
||||||
void fakeMouseButton(ButtonID id, bool press) override;
|
void fakeMouseButton(ButtonID id, bool press) override;
|
||||||
void fakeMouseMove(int32_t x, int32_t y) override;
|
void fakeMouseMove(int32_t x, int32_t y) override;
|
||||||
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
void fakeMouseRelativeMove(int32_t dx, int32_t dy) const override;
|
||||||
void fakeMouseWheel(int32_t xDelta, int32_t yDelta) const override;
|
void fakeMouseWheel(ScrollDelta delta) const override;
|
||||||
|
|
||||||
// IPlatformScreen overrides
|
// IPlatformScreen overrides
|
||||||
void enable() override;
|
void enable() override;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue