mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Add a small touch deadzone for double clicking
This commit is contained in:
parent
37cdf16834
commit
66b435d9f9
29
input.cpp
29
input.cpp
@ -6,8 +6,13 @@
|
|||||||
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define KEY_PREFIX 0x80
|
#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 MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(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();
|
pp::FloatPoint touchPoint = touchEvent.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
|
||||||
|
|
||||||
// Scale the touch coordinates to the video rect
|
// Create a small deadzone for touch downs to allow more precise double-clicks
|
||||||
//
|
if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHMOVE ||
|
||||||
// For some reason, the x coordinate is already relative to the plugin rect,
|
event.GetTimeStamp() - m_LastTouchUpTime > TOUCH_DEAD_ZONE_DELAY ||
|
||||||
// while the y coordinate is not. No clue why that is the case but oh well...
|
sqrt(pow(m_LastTouchUpPoint.x() - touchPoint.x(), 2) +
|
||||||
short x = MIN(MAX(touchPoint.x(), 0), m_PluginRect.width());
|
pow(m_LastTouchUpPoint.y() - touchPoint.y(), 2)) > TOUCH_DEAD_ZONE_RADIUS) {
|
||||||
short y = MIN(MAX(touchPoint.y() - m_PluginRect.y(), 0), m_PluginRect.height());
|
// 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
|
// Update the mouse position prior to sending the button down
|
||||||
LiSendMousePositionEvent(x, y, m_PluginRect.width(), m_PluginRect.height());
|
LiSendMousePositionEvent(x, y, m_PluginRect.width(), m_PluginRect.height());
|
||||||
|
}
|
||||||
|
|
||||||
if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHSTART &&
|
if (event.GetType() == PP_INPUTEVENT_TYPE_TOUCHSTART &&
|
||||||
touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) {
|
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) {
|
if (touchEvent.GetTouchCount(PP_TOUCHLIST_TYPE_TARGETTOUCHES) == 1) {
|
||||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
|
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
|
||||||
|
m_LastTouchUpTime = event.GetTimeStamp();
|
||||||
|
m_LastTouchUpPoint = touchEvent.GetTouchByIndex(PP_TOUCHLIST_TYPE_TARGETTOUCHES, 0).position();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
m_AccumulatedTicks(0),
|
m_AccumulatedTicks(0),
|
||||||
m_MouseDeltaX(0),
|
m_MouseDeltaX(0),
|
||||||
m_MouseDeltaY(0),
|
m_MouseDeltaY(0),
|
||||||
|
m_LastTouchUpTime(0),
|
||||||
m_HttpThreadPoolSequence(0) {
|
m_HttpThreadPoolSequence(0) {
|
||||||
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
|
// 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());
|
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;
|
bool m_WaitingForAllModifiersUp;
|
||||||
float m_AccumulatedTicks;
|
float m_AccumulatedTicks;
|
||||||
int32_t m_MouseDeltaX, m_MouseDeltaY;
|
int32_t m_MouseDeltaX, m_MouseDeltaY;
|
||||||
|
PP_TimeTicks m_LastTouchUpTime;
|
||||||
|
pp::FloatPoint m_LastTouchUpPoint;
|
||||||
|
|
||||||
pp::SimpleThread* m_HttpThreadPool[HTTP_HANDLER_THREADS];
|
pp::SimpleThread* m_HttpThreadPool[HTTP_HANDLER_THREADS];
|
||||||
uint32_t m_HttpThreadPoolSequence;
|
uint32_t m_HttpThreadPoolSequence;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user