Add direct touchscreen mouse support

This commit is contained in:
Cameron Gutman 2020-04-22 19:22:32 -07:00
parent d9a09fe450
commit 37cdf16834
5 changed files with 50 additions and 4 deletions

View File

@ -8,6 +8,9 @@
#define KEY_PREFIX 0x80
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
switch (ppButton) {
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
@ -210,7 +213,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
return true;
}
case PP_INPUTEVENT_TYPE_KEYUP: {
case PP_INPUTEVENT_TYPE_KEYUP: {
if (!m_MouseLocked) {
return false;
}
@ -230,6 +233,39 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
KEY_ACTION_UP, modifiers);
return true;
}
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
case PP_INPUTEVENT_TYPE_TOUCHSTART: {
pp::TouchInputEvent touchEvent(event);
pp::FloatPoint touchPoint = touchEvent.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
// Scale the touch coordinates to the video rect
//
// For some reason, the x coordinate is already relative to the plugin rect,
// while the y coordinate is not. No clue why that is the case but oh well...
short x = MIN(MAX(touchPoint.x(), 0), m_PluginRect.width());
short y = MIN(MAX(touchPoint.y() - m_PluginRect.y(), 0), m_PluginRect.height());
// Update the mouse position prior to sending the button down
LiSendMousePositionEvent(x, y, m_PluginRect.width(), m_PluginRect.height());
if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHSTART &&
touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) {
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
}
return true;
}
case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
case PP_INPUTEVENT_TYPE_TOUCHEND: {
pp::TouchInputEvent touchEvent(event);
if (touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
}
return true;
}
default: {
return false;

View File

@ -40,7 +40,7 @@ void MoonlightInstance::OnConnectionStarted(uint32_t unused) {
PostMessage(response);
// Start receiving input events
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL);
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_TOUCH);
// Filtering is suboptimal but it ensures that we can pass keyboard events
// to the browser when mouse lock is disabled. This is neccessary for Esc
@ -53,7 +53,10 @@ void MoonlightInstance::OnConnectionStopped(uint32_t error) {
m_Running = false;
// Stop receiving input events
ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE |
PP_INPUTEVENT_CLASS_WHEEL |
PP_INPUTEVENT_CLASS_KEYBOARD |
PP_INPUTEVENT_CLASS_TOUCH);
// Unlock the mouse
UnlockMouse();

@ -1 +1 @@
Subproject commit f489c9d725d22517d3b3a017f6bbb0a22ed43707
Subproject commit 247b1fe0e32d80ce02ede4c2b4a835b9c085abe4

View File

@ -143,6 +143,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
void PaintPicture(void);
bool InitializeRenderingSurface(int width, int height);
void DidChangeFocus(bool got_focus);
void DidChangeView(const pp::View& view);
static int VidDecSetup(int videoFormat, int width, int height, int redrawRate, void* context, int drFlags);
static void VidDecCleanup(void);
@ -184,6 +185,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
PP_VideoPicture m_CurrentPicture;
bool m_IsPainting;
bool m_RequestIdrFrame;
pp::Rect m_PluginRect;
OpusMSDecoder* m_OpusDecoder;
pp::Audio m_AudioPlayer;

View File

@ -66,6 +66,10 @@ void MoonlightInstance::DidChangeFocus(bool got_focus) {
}
}
void MoonlightInstance::DidChangeView(const pp::View& view) {
m_PluginRect = view.GetRect();
}
bool MoonlightInstance::InitializeRenderingSurface(int width, int height) {
if (!glInitializePPAPI(pp::Module::Get()->get_browser_interface())) {
return false;