Skip to content

Commit

Permalink
Fix[input]: 2-finger scrolling is too fast
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Sep 15, 2023
1 parent bf7d2dc commit 1f67b22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Natives/SurfaceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ - (void)surfaceOnTouchesScroll:(UIPanGestureRecognizer *)sender {
sender.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [sender velocityInView:self.rootView];
if (velocity.x != 0.0f || velocity.y != 0.0f) {
CallbackBridge_nativeSendScroll(velocity.x/100.0, velocity.y/100.0);
CallbackBridge_nativeSendScroll(velocity.x/self.view.frame.size.width, velocity.y/self.view.frame.size.height);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions Natives/environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@

typedef struct {
short type;
short i1;
short i2;
union {
int i1;
float f1;
};
union {
int i2;
float f2;
};
short i3;
short i4;
} GLFWInputEvent;
Expand Down
19 changes: 16 additions & 3 deletions Natives/input_bridge_v3.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void pojavPumpEvents(void* window) {
if(GLFW_invoke_MouseButton) GLFW_invoke_MouseButton(window, event.i1, event.i2, event.i3);
break;
case EVENT_TYPE_SCROLL:
if(GLFW_invoke_Scroll) GLFW_invoke_Scroll(window, event.i1, event.i2);
if(GLFW_invoke_Scroll) GLFW_invoke_Scroll(window, event.f1, event.f2);
break;
case EVENT_TYPE_FRAMEBUFFER_SIZE:
handleFramebufferSizeJava(window, event.i1, event.i2);
Expand Down Expand Up @@ -314,7 +314,7 @@ void pojavRewindEvents() {
cLastY = cursorY = ypos;
}

void sendData(short type, short i1, short i2, short i3, short i4) {
void sendData(short type, int i1, int i2, short i3, short i4) {
size_t counter = atomic_load_explicit(&eventCounter, memory_order_acquire);
if (counter < 7999) {
GLFWInputEvent *event = &events[counter++];
Expand All @@ -327,6 +327,19 @@ void sendData(short type, short i1, short i2, short i3, short i4) {
atomic_store_explicit(&eventCounter, counter, memory_order_release);
}

void sendDataFloat(short type, float i1, float i2, short i3, short i4) {
size_t counter = atomic_load_explicit(&eventCounter, memory_order_acquire);
if (counter < 7999) {
GLFWInputEvent *event = &events[counter++];
event->type = type;
event->f1 = i1;
event->f2 = i2;
event->i3 = i3;
event->i4 = i4;
}
atomic_store_explicit(&eventCounter, counter, memory_order_release);
}

void closeGLFWWindow() {
NSLog(@"Closing GLFW window");

Expand Down Expand Up @@ -564,7 +577,7 @@ void CallbackBridge_nativeSendScreenSize(int width, int height) {
void CallbackBridge_nativeSendScroll(CGFloat xoffset, CGFloat yoffset) {
if (GLFW_invoke_Scroll && isInputReady) {
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_SCROLL, xoffset, yoffset, 0, 0);
sendDataFloat(EVENT_TYPE_SCROLL, xoffset, yoffset, 0, 0);
} else {
GLFW_invoke_Scroll((void*) showingWindow, (double) xoffset, (double) yoffset);
}
Expand Down

0 comments on commit 1f67b22

Please sign in to comment.