Skip to content

Commit

Permalink
Fix ghost touching under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jul 3, 2024
1 parent f507b9b commit 5432d30
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions library/include/borealis/core/touch/pan_gesture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class PanGestureRecognizer : public GestureRecognizer
// Get pan gesture event
PanGestureEvent getPanGestureEvent() const { return panEvent; }

static inline float panFactor{1.0f};

private:
int lastFingerId = 0;
PanGestureEvent panEvent;
Expand Down
4 changes: 4 additions & 0 deletions library/lib/core/touch/pan_gesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ GestureState PanGestureRecognizer::recognitionLoop(TouchState touch, MouseState

float velocityX = distanceX / time;
float velocityY = distanceY / time;
if (panFactor > 0.0f) {
velocityX *= panFactor;
velocityY *= panFactor;
}

acceleration.time.x = -fabs(velocityX) / PAN_SCROLL_ACCELERATION;
acceleration.time.y = -fabs(velocityY) / PAN_SCROLL_ACCELERATION;
Expand Down
2 changes: 1 addition & 1 deletion library/lib/extern/glfw
Submodule glfw updated 1 files
+7 −0 src/win32_window.c
30 changes: 26 additions & 4 deletions library/lib/platforms/glfw/glfw_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,36 @@ static void glfwJoystickCallback(int jid, int event)
Application::setActiveEvent(true);
}

#define GLFW_STICKY 4
static RawTouchState touchState = { 0, 0, { 0, 0 } };
static int touchStateStatus = GLFW_RELEASE;
static bool touchUpdate = false;

static inline int getTouchState()
{
if (touchStateStatus == GLFW_STICKY)
{
touchStateStatus = GLFW_RELEASE;
// Try to ignore the touch end event as this can lead to a smaller calculation of scrolling acceleration
int res = touchUpdate ? GLFW_PRESS : GLFW_RELEASE;
touchUpdate = false;
return res;
}
else
{
touchUpdate = false;
return touchStateStatus;
}
}

static void glfwTouchCallback(GLFWwindow* window, int touch, int action, double xpos, double ypos)
{
touchState.fingerId = 0;
touchState.pressed = true;
touchState.pressed = action != GLFW_RELEASE;
touchState.position.x = xpos / Application::windowScale;
touchState.position.y = ypos / Application::windowScale;
touchStateStatus = touchState.pressed ? GLFW_PRESS : GLFW_STICKY;
touchUpdate |= touchState.pressed;
Application::setActiveEvent(true);
}

Expand Down Expand Up @@ -320,10 +342,10 @@ bool sameSign(int a, int b)

void GLFWInputManager::updateTouchStates(std::vector<RawTouchState>* states)
{
if (touchState.pressed)
if (getTouchState()) {
touchState.pressed = true;
states->push_back(touchState);

touchState.pressed = false;
}
}

void GLFWInputManager::updateMouseStates(RawMouseState* state)
Expand Down

0 comments on commit 5432d30

Please sign in to comment.