Skip to content

Commit 3642268

Browse files
authored
Merge pull request #6459 from frenzibyte/fix-touch-hold-toggle
Fix disabling hold-to-right-click not cancelling in-progress actions
2 parents aa8e72e + 3300793 commit 3642268

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs

+21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public partial class TestSceneTouchInput : ManualInputManagerTestScene
3232
[SetUp]
3333
public new void SetUp() => Schedule(() =>
3434
{
35+
InputManager.RightClickFromLongTouch = true;
36+
3537
Children = new Drawable[]
3638
{
3739
new Container
@@ -606,6 +608,25 @@ public void TestHoldTwoTouchesAndReleaseSecondBeforeRightClick()
606608
AddAssert("no right click received", () => primaryReceptor.MouseEvents.Count == 0 && secondaryReceptor.MouseEvents.Count == 0);
607609
}
608610

611+
[Test]
612+
public void TestHoldTouchAndDisableHoldingBeforeRightClick()
613+
{
614+
InputReceptor primaryReceptor = null;
615+
616+
AddStep("retrieve primary receptor", () => primaryReceptor = receptors[(int)TouchSource.Touch1]);
617+
AddStep("setup handlers to receive mouse-from-touch", () =>
618+
{
619+
primaryReceptor.HandleTouch = _ => false;
620+
primaryReceptor.HandleMouse = e => e is MouseButtonEvent button && button.Button == MouseButton.Right;
621+
});
622+
623+
AddStep("begin touch", () => InputManager.BeginTouch(new Touch(TouchSource.Touch1, getTouchDownPos(TouchSource.Touch1))));
624+
AddWaitStep("hold shortly", 2);
625+
AddStep("turn off hold-to-right-click", () => InputManager.RightClickFromLongTouch = false);
626+
AddWaitStep("wait a bit", 4);
627+
AddAssert("no right click received", () => primaryReceptor.MouseEvents.Count == 0);
628+
}
629+
609630
private partial class InputReceptor : Container
610631
{
611632
public readonly TouchSource AssociatedSource;

osu.Framework/Input/InputManager.cs

+3
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ protected override void Update()
507507
if (FocusedDrawable == null)
508508
focusTopMostRequestingDrawable();
509509

510+
if (!AllowRightClickFromLongTouch && touchLongPressDelegate != null)
511+
cancelTouchLongPress();
512+
510513
base.Update();
511514
}
512515

0 commit comments

Comments
 (0)