Skip to content

Commit

Permalink
Merge pull request #6459 from frenzibyte/fix-touch-hold-toggle
Browse files Browse the repository at this point in the history
Fix disabling hold-to-right-click not cancelling in-progress actions
  • Loading branch information
peppy authored Dec 16, 2024
2 parents aa8e72e + 3300793 commit 3642268
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public partial class TestSceneTouchInput : ManualInputManagerTestScene
[SetUp]
public new void SetUp() => Schedule(() =>
{
InputManager.RightClickFromLongTouch = true;

Children = new Drawable[]
{
new Container
Expand Down Expand Up @@ -606,6 +608,25 @@ public void TestHoldTwoTouchesAndReleaseSecondBeforeRightClick()
AddAssert("no right click received", () => primaryReceptor.MouseEvents.Count == 0 && secondaryReceptor.MouseEvents.Count == 0);
}

[Test]
public void TestHoldTouchAndDisableHoldingBeforeRightClick()
{
InputReceptor primaryReceptor = null;

AddStep("retrieve primary receptor", () => primaryReceptor = receptors[(int)TouchSource.Touch1]);
AddStep("setup handlers to receive mouse-from-touch", () =>
{
primaryReceptor.HandleTouch = _ => false;
primaryReceptor.HandleMouse = e => e is MouseButtonEvent button && button.Button == MouseButton.Right;
});

AddStep("begin touch", () => InputManager.BeginTouch(new Touch(TouchSource.Touch1, getTouchDownPos(TouchSource.Touch1))));
AddWaitStep("hold shortly", 2);
AddStep("turn off hold-to-right-click", () => InputManager.RightClickFromLongTouch = false);
AddWaitStep("wait a bit", 4);
AddAssert("no right click received", () => primaryReceptor.MouseEvents.Count == 0);
}

private partial class InputReceptor : Container
{
public readonly TouchSource AssociatedSource;
Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ protected override void Update()
if (FocusedDrawable == null)
focusTopMostRequestingDrawable();

if (!AllowRightClickFromLongTouch && touchLongPressDelegate != null)
cancelTouchLongPress();

base.Update();
}

Expand Down

0 comments on commit 3642268

Please sign in to comment.