diff --git a/src/Eto.Mac/Forms/MacWindow.cs b/src/Eto.Mac/Forms/MacWindow.cs index 67f259a41..1643a1f58 100644 --- a/src/Eto.Mac/Forms/MacWindow.cs +++ b/src/Eto.Mac/Forms/MacWindow.cs @@ -401,13 +401,14 @@ public override void AttachEvent(string id) handler.Callback.OnSizeChanged(handler.Widget, EventArgs.Empty); oldSize = newSize; } - var old = handler.oldLocation; - handler.oldLocation = null; - var newLocation = handler.Location; - if (old != newLocation) + if (handler.Widget.Loaded) { - handler.oldLocation = newLocation; - handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); + var newLocation = handler.GetLocation(); + if (handler.oldLocation != newLocation) + { + handler.oldLocation = newLocation; + handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); + } } }); } @@ -419,10 +420,8 @@ public override void AttachEvent(string id) var handler = e.Handler as MacWindow; if (handler != null) { - var old = handler.oldLocation; - handler.oldLocation = null; - var newLocation = handler.Location; - if (old != newLocation) + var newLocation = handler.GetLocation(); + if (handler.oldLocation != newLocation) { handler.oldLocation = newLocation; handler.Callback.OnLocationChanged(handler.Widget, EventArgs.Empty); @@ -982,10 +981,7 @@ public virtual Point Location return oldLocation.Value; if (!Widget.Loaded && InitialLocation != null) return InitialLocation.Value; - // translate location relative to the top left corner of main screen - var mainFrame = NSScreen.Screens[0].Frame; - var frame = Control.Frame; - return new Point((int)frame.X, (int)(mainFrame.Height - frame.Y - frame.Height)); + return GetLocation(); } set { @@ -999,6 +995,14 @@ public virtual Point Location } } + private Point GetLocation() + { + // translate location relative to the top left corner of main screen + var mainFrame = NSScreen.Screens[0].Frame; + var frame = Control.Frame; + return new Point((int)frame.X, (int)(mainFrame.Height - frame.Y - frame.Height)); + } + void SetLocation(Point value) { // location is relative to the main screen, translate to bottom left, inversed