mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 14:11:35 +00:00
Improve scrolling behavior for discrete scroll input
This commit is contained in:
@@ -28,6 +28,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
NSInteger lastMouseButtonMask;
|
NSInteger lastMouseButtonMask;
|
||||||
float lastMouseX;
|
float lastMouseX;
|
||||||
float lastMouseY;
|
float lastMouseY;
|
||||||
|
CGPoint lastScrollTranslation;
|
||||||
|
|
||||||
// Citrix X1 mouse support
|
// Citrix X1 mouse support
|
||||||
X1Mouse* x1mouse;
|
X1Mouse* x1mouse;
|
||||||
@@ -91,11 +92,17 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
if (@available(iOS 13.4, *)) {
|
if (@available(iOS 13.4, *)) {
|
||||||
[self addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]];
|
[self addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]];
|
||||||
|
|
||||||
UIPanGestureRecognizer *mouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelMoved:)];
|
UIPanGestureRecognizer *discreteMouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelMovedDiscrete:)];
|
||||||
mouseWheelRecognizer.maximumNumberOfTouches = 0;
|
discreteMouseWheelRecognizer.maximumNumberOfTouches = 0;
|
||||||
mouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskAll;
|
discreteMouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskDiscrete;
|
||||||
mouseWheelRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirectPointer)];
|
discreteMouseWheelRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirectPointer)];
|
||||||
[self addGestureRecognizer:mouseWheelRecognizer];
|
[self addGestureRecognizer:discreteMouseWheelRecognizer];
|
||||||
|
|
||||||
|
UIPanGestureRecognizer *continuousMouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelMovedContinuous:)];
|
||||||
|
continuousMouseWheelRecognizer.maximumNumberOfTouches = 0;
|
||||||
|
continuousMouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskContinuous;
|
||||||
|
continuousMouseWheelRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirectPointer)];
|
||||||
|
[self addGestureRecognizer:continuousMouseWheelRecognizer];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -448,24 +455,48 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
return [UIPointerStyle hiddenPointerStyle];
|
return [UIPointerStyle hiddenPointerStyle];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseWheelMoved:(UIPanGestureRecognizer *)gesture {
|
- (void)mouseWheelMovedContinuous:(UIPanGestureRecognizer *)gesture {
|
||||||
switch (gesture.state) {
|
switch (gesture.state) {
|
||||||
case UIGestureRecognizerStateBegan:
|
case UIGestureRecognizerStateBegan:
|
||||||
case UIGestureRecognizerStateChanged:
|
case UIGestureRecognizerStateChanged:
|
||||||
case UIGestureRecognizerStateEnded:
|
case UIGestureRecognizerStateEnded:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Ignore recognition failure and other states
|
// Ignore recognition failure and other states
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPoint velocity = [gesture velocityInView:self];
|
short velocityY = [gesture velocityInView:self].y;
|
||||||
if ((short)velocity.y != 0) {
|
if (velocityY != 0) {
|
||||||
LiSendHighResScrollEvent((short)velocity.y);
|
LiSendHighResScrollEvent(velocityY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)mouseWheelMovedDiscrete:(UIPanGestureRecognizer *)gesture {
|
||||||
|
switch (gesture.state) {
|
||||||
|
case UIGestureRecognizerStateBegan:
|
||||||
|
case UIGestureRecognizerStateChanged:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIGestureRecognizerStateEnded:
|
||||||
|
default:
|
||||||
|
// Ignore recognition failure and other states
|
||||||
|
lastScrollTranslation = CGPointMake(0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using velocityInView is 0 for discrete scroll events
|
||||||
|
// when scrolling very slowly, but translationInView does work.
|
||||||
|
CGPoint currentScrollTranslation = [gesture translationInView:self];
|
||||||
|
short translationDeltaY = currentScrollTranslation.y - lastScrollTranslation.y;
|
||||||
|
if (translationDeltaY != 0) {
|
||||||
|
LiSendScrollEvent(translationDeltaY > 0 ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastScrollTranslation = currentScrollTranslation;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
|
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
|
||||||
|
|||||||
Reference in New Issue
Block a user