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),
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)

View File

@ -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;
};

View File

@ -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));
}

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
{
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()

View File

@ -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;

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
{
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
// 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<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 scaling = 0.0;

View File

@ -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);