From fdf0b8b8f57ecc242c61f8882fa4a6d1a3c4b83d Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Mon, 24 Jul 2023 12:43:03 -0700 Subject: [PATCH] Mac: Fix firing MouseEnter/Leave when scrolling --- src/Eto.Mac/Forms/MacView.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Eto.Mac/Forms/MacView.cs b/src/Eto.Mac/Forms/MacView.cs index 5d1327a40..c3ff49eae 100644 --- a/src/Eto.Mac/Forms/MacView.cs +++ b/src/Eto.Mac/Forms/MacView.cs @@ -74,6 +74,28 @@ public void FireMouseLeaveIfNeeded(bool async) h.Callback.OnMouseLeave(h.Widget, MacConversions.GetMouseEvent(h, theEvent, false)); } } + + public void FireMouseEnterIfNeeded(bool async) + { + var h = Handler; + if (h == null || entered) return; + entered = true; + if (async) + { + Application.Instance.AsyncInvoke(() => + { + if (h.Widget.IsDisposed) + return; + var theEvent = NSApplication.SharedApplication.CurrentEvent; + h.Callback.OnMouseEnter(h.Widget, MacConversions.GetMouseEvent(h, theEvent, false)); + }); + } + else + { + var theEvent = NSApplication.SharedApplication.CurrentEvent; + h.Callback.OnMouseEnter(h.Widget, MacConversions.GetMouseEvent(h, theEvent, false)); + } + } } @@ -777,6 +799,16 @@ public virtual void UpdateTrackingAreas() tracking = new NSTrackingArea(frame, options, mouseDelegate, null); EventControl.AddTrackingArea(tracking); + + // when scrolling we need to fire the events manually + if (Widget.Loaded) + { + var mousePosition = PointFromScreen(Mouse.Position); + if (frame.Contains(mousePosition.ToNS())) + mouseDelegate.FireMouseEnterIfNeeded(false); + else + mouseDelegate.FireMouseLeaveIfNeeded(false); + } } }