Merge pull request #6347 from frenzibyte/fix-ptim-not-always-releasing

Fix `PassThroughInputManager` not always releasing input
This commit is contained in:
Dan Balasescu
2024-08-02 18:50:47 +09:00
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@@ -132,6 +132,25 @@ namespace osu.Framework.Tests.Visual.Input
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]

View File

@@ -173,6 +173,18 @@ namespace osu.Framework.Input
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>