From 2d24b0ec7b7c8ad01cc601bd6d43effc1fb72a56 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 17 Sep 2020 18:59:18 -0500 Subject: [PATCH] Fix mouse support on iOS 14 --- Limelight/Input/StreamView.m | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index 96892dd6..1572c2b3 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -189,7 +189,23 @@ static const int REFERENCE_HEIGHT = 720; if (@available(iOS 13.4, *)) { UITouch* touch = [touches anyObject]; if (touch.type == UITouchTypeIndirectPointer) { - UIEventButtonMask changedButtons = lastMouseButtonMask ^ event.buttonMask; + UIEventButtonMask normalizedButtonMask; + + // iOS 14 includes the released button in the buttonMask for the release + // event, while iOS 13 does not. Normalize that behavior here. + if (@available(iOS 14.0, *)) { + if (buttonAction == BUTTON_ACTION_RELEASE) { + normalizedButtonMask = lastMouseButtonMask & ~event.buttonMask; + } + else { + normalizedButtonMask = event.buttonMask; + } + } + else { + normalizedButtonMask = event.buttonMask; + } + + UIEventButtonMask changedButtons = lastMouseButtonMask ^ normalizedButtonMask; for (int i = BUTTON_LEFT; i <= BUTTON_X2; i++) { UIEventButtonMask buttonFlag; @@ -213,7 +229,7 @@ static const int REFERENCE_HEIGHT = 720; } } - lastMouseButtonMask = event.buttonMask; + lastMouseButtonMask = normalizedButtonMask; return YES; } }