Skip to content

Commit

Permalink
Merge pull request #6340 from frenzibyte/revert-some-ptim-changes
Browse files Browse the repository at this point in the history
Keep `PassThroughInputManager` in input queue even while parent input is disabled
  • Loading branch information
peppy authored Jul 20, 2024
2 parents d58dd3c + b9a47a0 commit 891e4ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
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

0 comments on commit 891e4ff

Please sign in to comment.