Skip to content

Commit

Permalink
Merge pull request #2377 from cwensley/curtis/mac-order-front-with-owner
Browse files Browse the repository at this point in the history
Mac: Non-activating forms with an owner should not show overtop existing windows
  • Loading branch information
cwensley committed Jan 9, 2023
2 parents 6eb7332 + c12db10 commit f573f25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Eto.Mac/Forms/FormHandler.cs
Expand Up @@ -70,14 +70,15 @@ public virtual void Show()
Control.MakeKeyWindow();
else
Control.MakeKeyAndOrderFront(ApplicationHandler.Instance.AppDelegate);

// setting the owner shows the window, so we have to do this after making the window key
EnsureOwner();
}
else
else if (!EnsureOwner())
{
// only order front when there is no owner as it'll bring the owner above any existing non-child windows
Control.OrderFront(ApplicationHandler.Instance.AppDelegate);
}

// setting the owner shows the window, so we have to do this here.
EnsureOwner();

if (!visible)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Eto.Mac/Forms/MacWindow.cs
Expand Up @@ -1247,10 +1247,13 @@ public bool SetAsChildWindow
set => Widget.Properties.Set(MacWindow.SetAsChildWindow_Key, value, DefaultSetAsChildWindow);
}

protected void EnsureOwner() => SetOwner(Widget.Owner);
protected bool EnsureOwner() => InternalSetOwner(Widget.Owner);

public virtual void SetOwner(Window owner)
public virtual void SetOwner(Window owner) => InternalSetOwner(owner);

bool InternalSetOwner(Window owner)
{
bool result = false;
if (SetAsChildWindow && Widget.Loaded)
{
if (owner != null)
Expand All @@ -1260,6 +1263,7 @@ public virtual void SetOwner(Window owner)
{
macWindow.Control.AddChildWindow(Control, NSWindowOrderingMode.Above);
OnSetAsChildWindow();
result = true;
}
Widget.GotFocus += HandleGotFocusAsChild;
}
Expand All @@ -1271,6 +1275,7 @@ public virtual void SetOwner(Window owner)
parentWindow.RemoveChildWindow(Control);
}
}
return result;
}

void HandleGotFocusAsChild(object sender, EventArgs e)
Expand Down

0 comments on commit f573f25

Please sign in to comment.