Add a small touch deadzone for double clicking

This commit is contained in:
Cameron Gutman 2020-04-22 19:44:46 -07:00
parent 37cdf16834
commit 66b435d9f9
2 changed files with 24 additions and 8 deletions

View File

@ -6,8 +6,13 @@
#include <Limelight.h>
#include <math.h>
#define KEY_PREFIX 0x80
#define TOUCH_DEAD_ZONE_DELAY 0.250
#define TOUCH_DEAD_ZONE_RADIUS 50
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@ -240,15 +245,21 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& 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());
// Create a small deadzone for touch downs to allow more precise double-clicks
if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHMOVE ||
event.GetTimeStamp() - m_LastTouchUpTime > TOUCH_DEAD_ZONE_DELAY ||
sqrt(pow(m_LastTouchUpPoint.x() - touchPoint.x(), 2) +
pow(m_LastTouchUpPoint.y() - touchPoint.y(), 2)) > TOUCH_DEAD_ZONE_RADIUS) {
// 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());
// 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) {
@ -263,6 +274,8 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
if (touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) {
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
m_LastTouchUpTime = event.GetTimeStamp();
m_LastTouchUpPoint = touchEvent.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
}
return true;
}

View File

@ -66,6 +66,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
m_AccumulatedTicks(0),
m_MouseDeltaX(0),
m_MouseDeltaY(0),
m_LastTouchUpTime(0),
m_HttpThreadPoolSequence(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());
@ -198,6 +199,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
bool m_WaitingForAllModifiersUp;
float m_AccumulatedTicks;
int32_t m_MouseDeltaX, m_MouseDeltaY;
PP_TimeTicks m_LastTouchUpTime;
pp::FloatPoint m_LastTouchUpPoint;
pp::SimpleThread* m_HttpThreadPool[HTTP_HANDLER_THREADS];
uint32_t m_HttpThreadPoolSequence;