diff --git a/src/lib/deskflow/PlatformScreen.cpp b/src/lib/deskflow/PlatformScreen.cpp index 4a3748169..cad0829ed 100644 --- a/src/lib/deskflow/PlatformScreen.cpp +++ b/src/lib/deskflow/PlatformScreen.cpp @@ -14,7 +14,7 @@ PlatformScreen::PlatformScreen(IEventQueue *events, bool invertScrolling) : IPlatformScreen(events), m_invertScrollDirection(invertScrolling) { - m_scrollScale = std::clamp(Settings::value(Settings::Client::YScrollScale).toDouble(), 0.1, 10.0); + m_yScrollScale = std::clamp(Settings::value(Settings::Client::YScrollScale).toDouble(), 0.1, 10.0); } void PlatformScreen::updateKeyMap() @@ -90,10 +90,11 @@ void PlatformScreen::clearStaleModifiers() getKeyState()->clearStaleModifiers(); } -int32_t PlatformScreen::mapClientScrollDirection(int32_t x) const +PlatformScreen::ScrollDelta PlatformScreen::applyClientScrollModifier(const PlatformScreen::ScrollDelta rawDelta) const { - x *= m_scrollScale; - return (m_invertScrollDirection ? -x : x); + ScrollDelta correctedDelta = rawDelta; + correctedDelta.yDelta *= m_invertScrollDirection ? -m_yScrollScale : m_yScrollScale; + return correctedDelta; } std::string PlatformScreen::sidesMaskToString(uint32_t sides) diff --git a/src/lib/deskflow/PlatformScreen.h b/src/lib/deskflow/PlatformScreen.h index 3b65ca627..3696301d0 100644 --- a/src/lib/deskflow/PlatformScreen.h +++ b/src/lib/deskflow/PlatformScreen.h @@ -18,6 +18,11 @@ subclasses to implement the rest. class PlatformScreen : public IPlatformScreen { public: + struct ScrollDelta + { + int32_t xDelta; + int32_t yDelta; + }; explicit PlatformScreen(IEventQueue *events, bool invertScrollDirection); ~PlatformScreen() override = default; @@ -96,11 +101,11 @@ protected: void handleSystemEvent(const Event &event) override = 0; /*! - * \brief mapClientScrollDirection - * Convert scroll according to client scroll directio - * \return converted value according to the client scroll direction + * \brief applyClientYScrollModifier + * Convert scroll according to client's scroll modifiers + * \return converted value according to the client's scroll modifiers */ - virtual int32_t mapClientScrollDirection(int32_t) const; + virtual ScrollDelta applyClientScrollModifier(const ScrollDelta rawDelta) const; /*! Converts a sides mask (e.g. LeftMask | RightMask) to a string representation (e.g. "LR"). @@ -116,9 +121,9 @@ private: bool m_invertScrollDirection = false; /** - * @brief m_scrollScale - * This member is used to scale the scroll speed + * @brief m_yScrollScale + * This member is used to scale the y scroll speed * It is only used on the client side */ - double m_scrollScale = 1.0; + double m_yScrollScale = 1.0; }; diff --git a/src/lib/platform/EiScreen.cpp b/src/lib/platform/EiScreen.cpp index 57b3e1ece..a55e7a60b 100644 --- a/src/lib/platform/EiScreen.cpp +++ b/src/lib/platform/EiScreen.cpp @@ -318,12 +318,11 @@ void EiScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const if (!m_eiPointer) return; - xDelta = mapClientScrollDirection(xDelta); - yDelta = mapClientScrollDirection(yDelta); + auto adjustedDeltas = applyClientScrollModifier({xDelta, yDelta}); // 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 // compatible with other platforms (including X11). - ei_device_scroll_discrete(m_eiPointer, -xDelta, -yDelta); + ei_device_scroll_discrete(m_eiPointer, -adjustedDeltas.xDelta, -adjustedDeltas.yDelta); ei_device_frame(m_eiPointer, ei_now(m_ei)); } diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 0a318abff..04cf9dd10 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -710,9 +710,8 @@ void MSWindowsScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const void MSWindowsScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const { - xDelta = mapClientScrollDirection(xDelta); - yDelta = mapClientScrollDirection(yDelta); - m_desks->fakeMouseWheel(xDelta, yDelta); + auto adjustedDeltas = applyClientScrollModifier({xDelta, yDelta}); + m_desks->fakeMouseWheel(adjustedDeltas.xDelta, adjustedDeltas.yDelta); } void MSWindowsScreen::updateKeys() diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 8a24bcfdb..a912a378f 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -139,9 +139,6 @@ private: // map mac scroll wheel value to a deskflow scroll wheel value int32_t mapScrollWheelToDeskflow(int32_t) const; - // map deskflow scroll wheel value to a mac scroll wheel value - int32_t mapScrollWheelFromDeskflow(int32_t) const; - // get the current scroll wheel speed double getScrollSpeed() const; diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 4d0b67757..e046dc71e 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -587,11 +587,15 @@ void OSXScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const void OSXScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const { if (xDelta != 0 || yDelta != 0) { + // use server's acceleration with a little boost since other platforms + // take one wheel step as a larger step than the mac does. + auto adjustedDeltas = applyClientScrollModifier( + {static_cast(3.0 * xDelta / 120.0), static_cast(3.0 * yDelta / 120.0)} + ); // create a scroll event, post it and release it. not sure if kCGScrollEventUnitLine // is the right choice here over kCGScrollEventUnitPixel - CGEventRef scrollEvent = CGEventCreateScrollWheelEvent( - nullptr, kCGScrollEventUnitLine, 2, mapScrollWheelFromDeskflow(yDelta), mapScrollWheelFromDeskflow(xDelta) - ); + CGEventRef scrollEvent = + CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, adjustedDeltas.yDelta, adjustedDeltas.xDelta); // Fix for sticky keys CGEventFlags modifiers = m_keyState->getModifierStateAsOSXFlags(); @@ -1219,14 +1223,6 @@ int32_t OSXScreen::mapScrollWheelToDeskflow(int32_t x) const return static_cast(120.0 * d); } -int32_t OSXScreen::mapScrollWheelFromDeskflow(int32_t x) const -{ - // use server's acceleration with a little boost since other platforms - // take one wheel step as a larger step than the mac does. - auto result = static_cast(3.0 * x / 120.0); - return mapClientScrollDirection(result); -} - double OSXScreen::getScrollSpeed() const { double scaling = 0.0; diff --git a/src/lib/platform/XWindowsScreen.cpp b/src/lib/platform/XWindowsScreen.cpp index 2fe48ba25..25e7df1da 100644 --- a/src/lib/platform/XWindowsScreen.cpp +++ b/src/lib/platform/XWindowsScreen.cpp @@ -797,7 +797,7 @@ void XWindowsScreen::fakeMouseWheel(int32_t, int32_t yDelta) const return; } - yDelta = mapClientScrollDirection(yDelta); + yDelta = applyClientScrollModifier({0, yDelta}).yDelta; // choose button depending on rotation direction const unsigned int xButton = mapButtonToX(yDelta >= 0 ? kX11ScrollWheelUp : kX11ScrollWheelDown);