All pastes #34352 Raw Edit

Anonymous

public text v1 · immutable
#34352 ·published 2005-12-20 17:47 UTC
rendered paste body
Bool
foo(void)
{
    int i;
    unsigned n_children;
    Window root_return, parent_return, *children_return;

    if (XQueryTree(display,          /* Connection to the X server                  */
                   root,             /* The window of interest                      */
                   &root_return,     /* Not very usefull in this case               */
                   &parent_return,   /* Not very usefull in this case               */
                   &children_return, /* What we are interested in                   */
                   &n_children       /* The number of entries for `children_return' */
                  ) == 0)
    {
        return False;
    }

    /*
        For all children window of the root window (top-level
        windows).
    */
    for (i = 0; i < n_children; ++i)
    {
        char *name;
        Window w = children_return[i];
        XWindowAttributes window_attr;

        #ifndef NDEBUG
        printf("Window id 0x%lx (%ld)... ", w, w);
        #endif

        /*
            Manage the window.
        */
        if (XFetchName(display, w, &name) != 0) /* If (Success) */
        {
            if (name != NULL)
            {
                puts(name);
            }
            else
            {
                puts("nameless");
            }

            if (name != NULL)
            {
                XFree(name);
            }
        }
        else /* Failure */
        {
            #ifndef NDEBUG
            puts("Failed");
            #endif
        }
    }

    /*
        Do not fogget to free the memory Xlib allocates for you!
    */
    if (children_return != NULL)
    {
        XFree(children_return);
    }

    return True;
}