Skip to content

Commit

Permalink
Mac: Only fire location changed when size changes and form is loaded.
Browse files Browse the repository at this point in the history
Follow up to picoe#2622
  • Loading branch information
cwensley committed Feb 27, 2024
1 parent 44bd4aa commit fa24d00
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Eto.Mac/Forms/MacWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
Expand All @@ -419,10 +420,8 @@ public override void AttachEvent(string id)
var handler = e.Handler as MacWindow<TControl, TWidget, TCallback>;
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);
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit fa24d00

Please sign in to comment.