mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-16 08:06:19 +00:00
Add native touch support
This commit is contained in:
parent
dbe0a54469
commit
babba295a9
46
input.cpp
46
input.cpp
@ -163,7 +163,53 @@ void MoonlightInstance::ReportMouseMovement() {
|
||||
}
|
||||
}
|
||||
|
||||
bool MoonlightInstance::TryHandleNativeTouchEvent(const pp::InputEvent& event) {
|
||||
// Check if the host supports native pen/touch events
|
||||
if (!(LiGetHostFeatureFlags() & LI_FF_PEN_TOUCH_EVENTS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t eventType;
|
||||
switch (event.GetType()) {
|
||||
case PP_INPUTEVENT_TYPE_TOUCHSTART:
|
||||
eventType = LI_TOUCH_EVENT_DOWN;
|
||||
break;
|
||||
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
|
||||
eventType = LI_TOUCH_EVENT_MOVE;
|
||||
break;
|
||||
case PP_INPUTEVENT_TYPE_TOUCHEND:
|
||||
eventType = LI_TOUCH_EVENT_UP;
|
||||
break;
|
||||
case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
|
||||
eventType = LI_TOUCH_EVENT_CANCEL;
|
||||
break;
|
||||
default:
|
||||
// Not a touch event
|
||||
return false;
|
||||
}
|
||||
|
||||
pp::TouchInputEvent touchEvent(event);
|
||||
uint32_t count = touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
pp::TouchPoint touchPoint = touchEvent.GetTouchByIndex(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, i);
|
||||
pp::FloatPoint touchPos = touchPoint.position();
|
||||
LiSendTouchEvent(eventType, touchPoint.id(),
|
||||
MIN(MAX(touchPos.x(), 0), m_PluginRect.width()),
|
||||
MIN(MAX(touchPos.y(), 0), m_PluginRect.height()),
|
||||
touchPoint.pressure(),
|
||||
0.0f, 0.0f,
|
||||
touchPoint.rotation_angle());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||
// If the host can handle native touch events, send them natively
|
||||
if (TryHandleNativeTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (event.GetType()) {
|
||||
case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
|
||||
// Lock the mouse cursor when the user clicks on the stream
|
||||
|
@ -103,6 +103,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
||||
void PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args);
|
||||
void STUNCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args);
|
||||
|
||||
bool TryHandleNativeTouchEvent(const pp::InputEvent& event);
|
||||
bool HandleInputEvent(const pp::InputEvent& event);
|
||||
void ReportMouseMovement();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user