Repository: AvaloniaUI/Avalonia
File: src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs (C#)

Code before:
                movePointCopy.time = 0; // empty "time" as otherwise WinAPI will always fail
                int pointsCount = GetMouseMovePointsEx(
                    (uint)(Marshal.SizeOf(movePointCopy)),
                    &movePointCopy, movePoints, s_mouseHistoryInfos.Length,
                    1);

                // GetMouseMovePointsEx can return -1 if point wasn't found or there is so beeg delay that original points were erased from the buffer.
                if (pointsCount <= 1)
                {
                    return Array.Empty<RawPointerPoint>();
                }

                s_intermediatePointsPooledList.Clear();
                s_intermediatePointsPooledList.Capacity = pointsCount;
                for (int i = pointsCount - 1; i >= 1; i--)
                {
                    var historyInfo = s_mouseHistoryInfos[i];
                    // Skip points newer than current point.
                    if (historyInfo.time > movePoint.time ||
                        (historyInfo.time == movePoint.time &&
                         historyInfo.x == movePoint.x &&
                         historyInfo.y == movePoint.y))
                    {
                        continue;
                    }
                    // Skip points older from previous WM_MOUSEMOVE point.
                    if (historyInfo.time < prevMovePoint.time ||
                        (historyInfo.time == prevMovePoint.time &&
                            historyInfo.x == prevMovePoint.x &&
                            historyInfo.y == prevMovePoint.y))
                    {
                        continue;
                    }

                    // To support multiple screens.
                    if (historyInfo.x > 32767)
                        historyInfo.x -= 65536;

                    if (historyInfo.y > 32767)
                        historyInfo.y -= 65536;

                    var point = PointToClient(new PixelPoint(historyInfo.x, historyInfo.y));
                    s_intermediatePointsPooledList.Add(new RawPointerPoint
                    {
                        Position = point
                    });
                }
                return s_intermediatePointsPooledList;
            }
        }


Review comment (suggestion):
Note: the previous and current point are now ignored. This matches what we do in `WM_POINTER` so that's good.

Code after:
            {
                var movePointCopy = movePoint;
                movePointCopy.time = 0; // empty "time" as otherwise WinAPI will always fail

                int pointsCount = GetMouseMovePointsEx(
                    (uint)(Marshal.SizeOf(movePointCopy)),
                    &movePointCopy, movePoints, s_mouseHistoryInfos.Length,
                    1);

                // GetMouseMovePointsEx can return -1 if point wasn't found or there is so beeg delay that original points were erased from the buffer.
                if (pointsCount <= 1)
                    return Array.Empty<RawPointerPoint>();

                s_intermediatePointsPooledList.Clear();
                s_sortedPoints.Clear();

                s_sortedPoints.Capacity = pointsCount;

                for (int i = 0; i < pointsCount; i++)
                {
                    var mp = movePoints[i];

                    var x = mp.x > 32767 ? mp.x - 65536 : mp.x;
                    var y = mp.y > 32767 ? mp.y - 65536 : mp.y;

                    if(mp.time <= prevMovePoint.time || mp.time >= movePoint.time)
                        continue;

                    s_sortedPoints.Add(new InternalPoint
                    {
                        Time = mp.time,
                        Pt = new PixelPoint(x, y)
                    });
                }

                // sorting is required to ensure points are in order from oldest to newest
                s_sortedPoints.Sort(static (a, b) => a.Time.CompareTo(b.Time));

                foreach (var p in s_sortedPoints)
                {
                    var client = PointToClient(p.Pt);

                    s_intermediatePointsPooledList.Add(new RawPointerPoint
                    {
                        Position = client
                    });
                }

                return s_intermediatePointsPooledList;
            }