Browse Source

Fixes/windows back requested (#21207)

* feat: Add test verifyig BackRequested not working

* fix: Use InputRoot not this when checking for back requested
pull/21219/head
Mike Goatly 6 months ago
committed by GitHub
parent
commit
8f64677152
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      src/Avalonia.Controls/TopLevel.cs
  2. 30
      tests/Avalonia.Controls.UnitTests/TopLevelTests.cs

2
src/Avalonia.Controls/TopLevel.cs

@ -286,7 +286,7 @@ namespace Avalonia.Controls
_backGestureSubscription = _inputManager?.PreProcess.Subscribe(e =>
{
if (e.Root != this)
if (e.Root != InputRoot)
return;
bool backRequested = false;

30
tests/Avalonia.Controls.UnitTests/TopLevelTests.cs

@ -253,6 +253,36 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void XButton1Down_Should_Raise_BackRequested()
{
// Regression test: prior to this fix, the PreProcess subscription compared
// e.Root against 'this' (the TopLevel/Window), but e.Root is set to the
// PresentationSource (the IInputRoot), not the Window itself. The comparison
// always failed so BackRequested was never raised for XButton1Down.
var services = TestServices.StyledWindow.With(inputManager: new InputManager());
using (UnitTestApplication.Start(services))
{
var impl = CreateMockTopLevelImpl(true);
var target = new TestTopLevel(impl.Object);
var raised = false;
target.BackRequested += (_, _) => raised = true;
var mouseDevice = new MouseDevice(new Pointer(0, PointerType.Mouse, true));
impl.Object.Input!(new RawPointerEventArgs(
mouseDevice,
timestamp: 0,
target.InputRoot,
RawPointerEventType.XButton1Down,
new RawPointerPoint { Position = default },
RawInputModifiers.None));
Assert.True(raised);
}
}
[Fact]
public void TopLevel_Should_Unfocus_When_Impl_Focus_Is_Lost()
{

Loading…
Cancel
Save