private void QueryPointer (IntPtr display, IntPtr w, out IntPtr root, out IntPtr child,
out int root_x, out int root_y, out int child_x, out int child_y,
out int mask)
{
/* this code was written with the help of
glance at gdk. I never would have realized we
needed a loop in order to traverse down in the
hierarchy. I would have assumed you'd get the
most deeply nested child and have to do
XQueryTree to move back up the hierarchy..
stupid me, of course. */
IntPtr c;
XGrabServer (display);
XQueryPointer(display, w, out root, out c,
out root_x, out root_y, out child_x, out child_y,
out mask);
if (root != w)
c = root;
IntPtr child_last = IntPtr.Zero;
while (c != IntPtr.Zero) {
child_last = c;
XQueryPointer(display, c, out root, out c,
out root_x, out root_y, out child_x, out child_y,
out mask);
}
XUngrabServer (display);
XFlush (display);
child = child_last;
}