public IElement GetElementFromHandle (IntPtr handle)
{
var win = Gdk.Window.ForeignNew ((uint) handle);
if (win == null)
return null;
int x, y, width, height, depth;
win.GetGeometry (out x, out y, out width, out height, out depth);
win.GetOrigin (out x, out y);
foreach (IElement element in GetRootElements ()) {
Component component = ((Element)element).Accessible.QueryComponent ();
if (component != null) {
BoundingBox extents = component.GetExtents (CoordType.Screen);
if (SizeFits (extents, x, y, width, height)) {
Accessible ret = component.GetAccessibleAtPoint (x, y, CoordType.Screen);
if (ret == null)
return element;
return Element.GetElement (ret);
}
}
}
return null;
}