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

Code before:
                    }

                case WindowsMessage.WM_MOUSELEAVE:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        _trackingMouse = false;
                        e = new RawPointerEventArgs(
                            _mouseDevice,
                            timestamp,
                            Owner,
                            RawPointerEventType.LeaveWindow,
                            new Point(-1, -1),
                            WindowsKeyboardDevice.Instance.Modifiers);
                        break;
                    }

                case WindowsMessage.WM_CAPTURECHANGED:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        if (!IsOurWindow(lParam))
                        {
                            _trackingMouse = false;
                            e = new RawPointerEventArgs(
                                _mouseDevice,
                                timestamp,
                                Owner,
                                RawPointerEventType.CancelCapture,
                                new Point(-1, -1),
                                WindowsKeyboardDevice.Instance.Modifiers);
                        }
                        break;
                    }

                case WindowsMessage.WM_NCLBUTTONDOWN:
                case WindowsMessage.WM_NCRBUTTONDOWN:
                case WindowsMessage.WM_NCMBUTTONDOWN:
                case WindowsMessage.WM_NCXBUTTONDOWN:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        e = new RawPointerEventArgs(
                            _mouseDevice,
                            timestamp,

Review comment (suggestion):
There's a different instance of `IMouseDevice` (and associated `IPointer`) per window.
Consequently, we should probably not check other windows, or pointers from them will keep the capture even though they don't have it anymore.

(Note that having a mouse device per window causes other problems but this isn't the right PR to change that.)

Code after:

                case WindowsMessage.WM_MOUSELEAVE:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        _trackingMouse = false;
                        e = new RawPointerEventArgs(
                            _mouseDevice,
                            timestamp,
                            Owner,
                            RawPointerEventType.LeaveWindow,
                            new Point(-1, -1),
                            WindowsKeyboardDevice.Instance.Modifiers);
                        break;
                    }

                case WindowsMessage.WM_CAPTURECHANGED:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        if (_hwnd != lParam)
                        {
                            _trackingMouse = false;
                            e = new RawPointerEventArgs(
                                _mouseDevice,
                                timestamp,
                                Owner,
                                RawPointerEventType.CancelCapture,
                                new Point(-1, -1),
                                WindowsKeyboardDevice.Instance.Modifiers);
                        }
                        break;
                    }

                case WindowsMessage.WM_NCLBUTTONDOWN:
                case WindowsMessage.WM_NCRBUTTONDOWN:
                case WindowsMessage.WM_NCMBUTTONDOWN:
                case WindowsMessage.WM_NCXBUTTONDOWN:
                    {
                        if (IsMouseInPointerEnabled)
                        {
                            break;
                        }
                        e = new RawPointerEventArgs(
                            _mouseDevice,
                            timestamp,
                            Owner,