diff --git a/Makefile b/Makefile index a29110a..c2be7c4 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ SOURCES = \ $(COMMON_C_SOURCE) \ libchelper.c \ main.cpp \ + input.cpp \ # Build rules generated by macros from common.mk: diff --git a/input.cpp b/input.cpp new file mode 100644 index 0000000..89d953a --- /dev/null +++ b/input.cpp @@ -0,0 +1,58 @@ +#include "moonlight.hpp" + +#include "ppapi/c/ppb_input_event.h" + +#include "ppapi/cpp/input_event.h" + +#include + +static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) { + switch (ppButton) { + case PP_INPUTEVENT_MOUSEBUTTON_LEFT: + return BUTTON_LEFT; + case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE: + return BUTTON_MIDDLE; + case PP_INPUTEVENT_MOUSEBUTTON_RIGHT: + return BUTTON_RIGHT; + default: + return 0; + } +} + +bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { + switch (event.GetType()) { + case PP_INPUTEVENT_TYPE_MOUSEDOWN: { + pp::MouseInputEvent mouseEvent(event); + + LiSendMouseButtonEvent(ConvertPPButtonToLiButton(mouseEvent.GetButton()), BUTTON_ACTION_PRESS); + return true; + } + + case PP_INPUTEVENT_TYPE_MOUSEMOVE: { + pp::MouseInputEvent mouseEvent(event); + pp::Point posDelta = mouseEvent.GetMovement(); + + LiSendMouseMoveEvent(posDelta.x(), posDelta.y()); + return true; + } + + case PP_INPUTEVENT_TYPE_MOUSEUP: { + pp::MouseInputEvent mouseEvent(event); + + LiSendMouseButtonEvent(ConvertPPButtonToLiButton(mouseEvent.GetButton()), BUTTON_ACTION_RELEASE); + return true; + } + + case PP_INPUTEVENT_TYPE_WHEEL: { + pp::WheelInputEvent wheelEvent(event); + + // FIXME: Handle fractional scroll ticks + LiSendScrollEvent((signed char) wheelEvent.GetTicks().y()); + return true; + } + + default: { + return false; + } + } +} \ No newline at end of file diff --git a/moonlight.hpp b/moonlight.hpp index 5410d1d..4d1eadb 100644 --- a/moonlight.hpp +++ b/moonlight.hpp @@ -12,4 +12,6 @@ class MoonlightInstance : public pp::Instance { } virtual ~MoonlightInstance(); + + bool HandleInputEvent(const pp::InputEvent& event); }; \ No newline at end of file