Skip to content

Commit

Permalink
Add mouse event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Feb 13, 2016
1 parent b5b6329 commit 4db53bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOURCES = \
$(COMMON_C_SOURCE) \
libchelper.c \
main.cpp \
input.cpp \

# Build rules generated by macros from common.mk:

Expand Down
58 changes: 58 additions & 0 deletions input.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "moonlight.hpp"

#include "ppapi/c/ppb_input_event.h"

#include "ppapi/cpp/input_event.h"

#include <Limelight.h>

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;
}
}
}
2 changes: 2 additions & 0 deletions moonlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ class MoonlightInstance : public pp::Instance {
}

virtual ~MoonlightInstance();

bool HandleInputEvent(const pp::InputEvent& event);
};

0 comments on commit 4db53bd

Please sign in to comment.