in src/Desktop/Utility/ExtensionMethods.cs [115:142]
public static A11yElement GetParentWindow(this A11yElement el)
{
A11yElement prev = null;
A11yElement curr = el;
while (curr != null && curr.Parent != null && curr.ControlTypeId != ControlType.UIA_WindowControlTypeId && !curr.IsRootElement())
{
prev = curr;
curr = curr.Parent;
}
if (curr.ControlTypeId != ControlType.UIA_WindowControlTypeId && prev != null)
{
curr = prev;
while (curr.UniqueId < -1 && curr.Children?[0].BoundingRectangle == null)
{
if (curr.Children.Count > 0)
{
curr = curr.Children[0];
}
else
{
// if no elements have bounding rectangles, give up
break;
}
}
}
return curr;
}