refactor: rename PlatformScreen::mapClientScrollDirection -> PlatformScreen::applyClientScrollModifier

prepare for horizontal scroll support by having it handle pairs of x and y values
This commit is contained in:
sithlord48 2026-02-04 23:08:31 -05:00 committed by Chris Rizzitello
parent 5e8a6f0bcb
commit 857326b274
7 changed files with 29 additions and 32 deletions

View file

@ -14,7 +14,7 @@ PlatformScreen::PlatformScreen(IEventQueue *events, bool invertScrolling)
: IPlatformScreen(events), : IPlatformScreen(events),
m_invertScrollDirection(invertScrolling) 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() void PlatformScreen::updateKeyMap()
@ -90,10 +90,11 @@ void PlatformScreen::clearStaleModifiers()
getKeyState()->clearStaleModifiers(); getKeyState()->clearStaleModifiers();
} }
int32_t PlatformScreen::mapClientScrollDirection(int32_t x) const PlatformScreen::ScrollDelta PlatformScreen::applyClientScrollModifier(const PlatformScreen::ScrollDelta rawDelta) const
{ {
x *= m_scrollScale; ScrollDelta correctedDelta = rawDelta;
return (m_invertScrollDirection ? -x : x); correctedDelta.yDelta *= m_invertScrollDirection ? -m_yScrollScale : m_yScrollScale;
return correctedDelta;
} }
std::string PlatformScreen::sidesMaskToString(uint32_t sides) std::string PlatformScreen::sidesMaskToString(uint32_t sides)

View file

@ -18,6 +18,11 @@ subclasses to implement the rest.
class PlatformScreen : public IPlatformScreen class PlatformScreen : public IPlatformScreen
{ {
public: public:
struct ScrollDelta
{
int32_t xDelta;
int32_t yDelta;
};
explicit PlatformScreen(IEventQueue *events, bool invertScrollDirection); explicit PlatformScreen(IEventQueue *events, bool invertScrollDirection);
~PlatformScreen() override = default; ~PlatformScreen() override = default;
@ -96,11 +101,11 @@ protected:
void handleSystemEvent(const Event &event) override = 0; void handleSystemEvent(const Event &event) override = 0;
/*! /*!
* \brief mapClientScrollDirection * \brief applyClientYScrollModifier
* Convert scroll according to client scroll directio * Convert scroll according to client's scroll modifiers
* \return converted value according to the client scroll direction * \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"). Converts a sides mask (e.g. LeftMask | RightMask) to a string representation (e.g. "LR").
@ -116,9 +121,9 @@ private:
bool m_invertScrollDirection = false; bool m_invertScrollDirection = false;
/** /**
* @brief m_scrollScale * @brief m_yScrollScale
* This member is used to scale the scroll speed * This member is used to scale the y scroll speed
* It is only used on the client side * It is only used on the client side
*/ */
double m_scrollScale = 1.0; double m_yScrollScale = 1.0;
}; };

View file

@ -318,12 +318,11 @@ void EiScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
if (!m_eiPointer) if (!m_eiPointer)
return; return;
xDelta = mapClientScrollDirection(xDelta); auto adjustedDeltas = applyClientScrollModifier({xDelta, yDelta});
yDelta = mapClientScrollDirection(yDelta);
// 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, -xDelta, -yDelta); ei_device_scroll_discrete(m_eiPointer, -adjustedDeltas.xDelta, -adjustedDeltas.yDelta);
ei_device_frame(m_eiPointer, ei_now(m_ei)); ei_device_frame(m_eiPointer, ei_now(m_ei));
} }

View file

@ -710,9 +710,8 @@ void MSWindowsScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
void MSWindowsScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const void MSWindowsScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
{ {
xDelta = mapClientScrollDirection(xDelta); auto adjustedDeltas = applyClientScrollModifier({xDelta, yDelta});
yDelta = mapClientScrollDirection(yDelta); m_desks->fakeMouseWheel(adjustedDeltas.xDelta, adjustedDeltas.yDelta);
m_desks->fakeMouseWheel(xDelta, yDelta);
} }
void MSWindowsScreen::updateKeys() void MSWindowsScreen::updateKeys()

View file

@ -139,9 +139,6 @@ private:
// map mac scroll wheel value to a deskflow scroll wheel value // map mac scroll wheel value to a deskflow scroll wheel value
int32_t mapScrollWheelToDeskflow(int32_t) const; 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 // get the current scroll wheel speed
double getScrollSpeed() const; double getScrollSpeed() const;

View file

@ -587,11 +587,15 @@ void OSXScreen::fakeMouseRelativeMove(int32_t dx, int32_t dy) const
void OSXScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const void OSXScreen::fakeMouseWheel(int32_t xDelta, int32_t yDelta) const
{ {
if (xDelta != 0 || yDelta != 0) { 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<int32_t>(3.0 * xDelta / 120.0), static_cast<int32_t>(3.0 * yDelta / 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 = CGEventCreateScrollWheelEvent( CGEventRef scrollEvent =
nullptr, kCGScrollEventUnitLine, 2, mapScrollWheelFromDeskflow(yDelta), mapScrollWheelFromDeskflow(xDelta) CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, adjustedDeltas.yDelta, adjustedDeltas.xDelta);
);
// Fix for sticky keys // Fix for sticky keys
CGEventFlags modifiers = m_keyState->getModifierStateAsOSXFlags(); CGEventFlags modifiers = m_keyState->getModifierStateAsOSXFlags();
@ -1219,14 +1223,6 @@ int32_t OSXScreen::mapScrollWheelToDeskflow(int32_t x) const
return static_cast<int32_t>(120.0 * d); return static_cast<int32_t>(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<int32_t>(3.0 * x / 120.0);
return mapClientScrollDirection(result);
}
double OSXScreen::getScrollSpeed() const double OSXScreen::getScrollSpeed() const
{ {
double scaling = 0.0; double scaling = 0.0;

View file

@ -797,7 +797,7 @@ void XWindowsScreen::fakeMouseWheel(int32_t, int32_t yDelta) const
return; return;
} }
yDelta = mapClientScrollDirection(yDelta); yDelta = applyClientScrollModifier({0, yDelta}).yDelta;
// 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(yDelta >= 0 ? kX11ScrollWheelUp : kX11ScrollWheelDown);