Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

In WindowBase.PositionChanged event handler Point value is wrong

Open sinatrocious opened this issue 4 months ago • 3 comments

Describe the bug

The value of PixelPointEvenArgs.Point inside event handler is wrong.

To Reproduce

Steps to reproduce the behavior:

  1. Create new Avalonia C# project.
  2. In MainWindow.axaml.cs add line in constructor to output argument value and actual value:
    public MainWindow()
    {
        InitializeComponent();
        PositionChanged += (s, e) => Debug.WriteLine($"Position={e.Point}, actual={Position}");
        //Position = new(666, 666); // optional
    }
  1. Run and observe debugger "Output" window.
  2. My outputs are
Position=190, 213, actual=188, 182
or
Position=668, 697, actual=666, 666

Expected behavior

I expect e.Point value to be equal to actual window Position.

Environment

  • OS: Windows 11
  • Avalonia-Version: 11.0.9

Additional context

I tried to use PositionChanged event to store position of window in normal state, see #14517 ,but unfortunately discovered a new frustrating bug in Avalonia.

sinatrocious avatar Feb 13 '24 10:02 sinatrocious

Looks like Position is considered the position of the client area in some places, and the position of the window frame in others.

TomEdwardsEnscape avatar Feb 13 '24 12:02 TomEdwardsEnscape

Maximising the window reveals that e.Point is the location of the client area, but Position is the location of the whole window including its frame.

Position=0, 23, actual=-1, -8

The raw value that comes from GetWindowRect is -8, -8. An attempt is being made to counteract the window's drop shadow, but it doesn't seem to be working very well.

What should the Position property really represent? The client area? The window frame? (I think we can discard the option of the window frame including drop shadow.)

TomEdwardsEnscape avatar Feb 23 '24 13:02 TomEdwardsEnscape

cc @emmauss

maxkatz6 avatar Feb 24 '24 00:02 maxkatz6