Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep PassThroughInputManager in input queue even while parent input is disabled #6340

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ public void TestKeyInput()
AddAssert("key released", () => !testInputManager.CurrentState.Keyboard.Keys.HasAnyButtonPressed);
}

[Test]
public void TestPressKeyThenReleaseWhileDisabled()
{
addTestInputManagerStep();
AddStep("press key", () => InputManager.PressKey(Key.A));
AddStep("UseParentInput = false", () => testInputManager.UseParentInput = false);
AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddStep("press key again", () => InputManager.PressKey(Key.A));
AddStep("UseParentInput = true", () => testInputManager.UseParentInput = true);
AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddAssert("key released", () => !testInputManager.CurrentState.Keyboard.Keys.HasAnyButtonPressed);
}

[Test]
public void TestTouchInput()
{
Expand Down Expand Up @@ -240,46 +253,6 @@ public void TestMouseTouchProductionOnPassThrough()
AddAssert("pass-through handled mouse", () => testInputManager.CurrentState.Mouse.Buttons.Single() == MouseButton.Left);
}

/// <summary>
/// Ensures that <see cref="PassThroughInputManager"/> does not handle input within the frame that <see cref="PassThroughInputManager.UseParentInput"/> is enabled.
/// </summary>
[Test]
public void TestInputPropagation()
{
addTestInputManagerStep();
AddStep("setup hierarchy", () =>
{
Add(new HandlingBox
{
Alpha = 0.5f,
RelativeSizeAxes = Axes.Both,
OnHandle = e =>
{
if (e is KeyDownEvent keyDown && !keyDown.Repeat)
testInputManager.UseParentInput = true;

return false;
}
});
});

AddStep("turn off parent input", () => testInputManager.UseParentInput = false);
AddStep("press key", () => InputManager.PressKey(Key.A));
AddAssert("key not pressed in pass-through", () => !keyboard.IsPressed(Key.A));
AddAssert("no key down event inside pass-through", () => testInputManager.Status.KeyDownCount == 0);

// parent input should be turned on by the box handler above.
AddAssert("parent input turned on", () => testInputManager.UseParentInput);
AddStep("release key", () => InputManager.ReleaseKey(Key.A));

AddStep("press key", () => InputManager.PressKey(Key.A));
AddStep("turn off parent input", () => testInputManager.UseParentInput = false);
AddAssert("key pressed in pass-through", () => keyboard.IsPressed(Key.A));

AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddAssert("key still pressed in pass-through", () => keyboard.IsPressed(Key.A));
}

public partial class TestInputManager : ManualInputManager
{
public readonly TestSceneInputManager.ContainingInputManagerStatusText Status;
Expand Down
3 changes: 0 additions & 3 deletions osu.Framework/Input/PassThroughInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ protected override void LoadComplete()
parentInputManager = GetContainingInputManager();
}

public override bool PropagateNonPositionalInputSubTree => UseParentInput;
public override bool PropagatePositionalInputSubTree => UseParentInput;

public override bool HandleHoverEvents => parentInputManager != null && UseParentInput ? parentInputManager.HandleHoverEvents : base.HandleHoverEvents;

internal override bool BuildNonPositionalInputQueue(List<Drawable> queue, bool allowBlocking = true)
Expand Down
Loading