From 4f6c547e476fd822d22a9634be6d010408796f8c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 26 Feb 2016 14:43:20 -0500 Subject: [PATCH] Fix scrolling behavior by accumulating partial ticks --- input.cpp | 15 +++++++++++++-- moonlight.hpp | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/input.cpp b/input.cpp index abb33da..e9ca6bc 100644 --- a/input.cpp +++ b/input.cpp @@ -112,14 +112,25 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { } case PP_INPUTEVENT_TYPE_WHEEL: { + signed char fullTicks; + if (!m_MouseLocked) { return false; } pp::WheelInputEvent wheelEvent(event); - // FIXME: Handle fractional scroll ticks - LiSendScrollEvent((signed char) wheelEvent.GetTicks().y()); + // Accumulate the current tick value + m_AccumulatedTicks += wheelEvent.GetTicks().y(); + + // Compute the number of full ticks + fullTicks = (signed char) m_AccumulatedTicks; + + // Send a scroll event if we've completed a full tick + if (fullTicks != 0) { + LiSendScrollEvent(fullTicks); + m_AccumulatedTicks -= fullTicks; + } return true; } diff --git a/moonlight.hpp b/moonlight.hpp index e35fd98..386fd09 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -44,7 +44,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { m_CallbackFactory(this), m_MouseLocked(false), m_KeyModifiers(0), - m_WaitingForAllModifiersUp(false) { + m_WaitingForAllModifiersUp(false), + m_AccumulatedTicks(0) { // This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!) nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface()); @@ -135,6 +136,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock { bool m_MouseLocked; char m_KeyModifiers; bool m_WaitingForAllModifiersUp; + float m_AccumulatedTicks; }; extern MoonlightInstance* g_Instance;