Widget parent, oldparent; oldparent = w[0]; do { parent = oldparent; oldparent = XtParent(oldparent); } while (oldparent != NULL && parent != oldparent); fprintf(stderr, "widget %p is toplevel shell: %d\n", parent, XtIsTopLevelShell(parent));