Skip to content

Commit

Permalink
Merge pull request ppy#6347 from frenzibyte/fix-ptim-not-always-relea…
Browse files Browse the repository at this point in the history
…sing

Fix `PassThroughInputManager` not always releasing input
  • Loading branch information
smoogipoo authored Aug 2, 2024
2 parents 2772619 + 1a71e0c commit 4779e1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ public void TestPressKeyThenReleaseWhileDisabled()
AddStep("UseParentInput = true", () => testInputManager.UseParentInput = true);
AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddAssert("key released", () => !testInputManager.CurrentState.Keyboard.Keys.HasAnyButtonPressed);

AddStep("press key", () => InputManager.PressKey(Key.A));
AddStep("UseParentInput = false", () => testInputManager.UseParentInput = false);

AddStep("add blocking layer", () => Add(new HandlingBox
{
RelativeSizeAxes = Axes.Both,
OnHandle = _ => true,
}));

// with a blocking layer existing, the next key press will not be seen by PassThroughInputManager...
AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddStep("press key again", () => InputManager.PressKey(Key.A));

AddStep("UseParentInput = true", () => testInputManager.UseParentInput = true);

// ...but ensure it'll still release the key regardless of not seeing the corresponding press event (it does that by syncing releases every frame).
AddStep("release key", () => InputManager.ReleaseKey(Key.A));
AddAssert("key released", () => !testInputManager.CurrentState.Keyboard.Keys.HasAnyButtonPressed);
}

[Test]
Expand Down
12 changes: 12 additions & 0 deletions osu.Framework/Input/PassThroughInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ protected override bool Handle(UIEvent e)
return false;
}

protected override void Update()
{
base.Update();

// There are scenarios wherein we cannot receive the release events of pressed inputs. For simplicity, sync every frame.
if (UseParentInput)
{
syncReleasedInputs();
syncJoystickAxes();
}
}

/// <summary>
/// Updates state of any buttons that have been released by parent while <see cref="UseParentInput"/> was disabled.
/// </summary>
Expand Down

0 comments on commit 4779e1b

Please sign in to comment.