can i enumerate all windows?



I thought that by traversing up the chain of windows to the root window I
would then be able to enumerate all GdkWindows on the current X display.
Unfortunately, that seems not to be the case.  The following script

    #!/usr/bin/env python

    import sys
    import gtk

    def print_hierarchy(b):
        win = b.window
        print "starting from:", win
        # get root window
        parent = win.get_parent()
        while parent:
            win = parent
            parent = win.get_parent()
        print "root looks like:", win
        print_win(win)

    def print_win(win, indent=0):
        sys.stdout.write("%s%s @ %s" % ("  "*indent, win, win.get_origin()))
        for win in win.get_children():
            print_win(win, indent+2)

    win = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
    b = gtk.GtkButton(label="print hierarchy")
    b.connect("clicked", print_hierarchy)
    b.connect("clicked", gtk.mainquit)
    win.add(b)
    win.show_all()
    gtk.mainloop()

displays this output:

    starting from: <GdkWindow at 0x8240b90>
    root looks like: <GdkWindow at 0x8132828>
    <GdkWindow at 0x8132828> @ (0, 0)
        <GdkWindow at 0x81ed038> @ (442, 370)
            <GdkWindow at 0x8240b90> @ (442, 370)

which makes it appear that the root window has only a single child.  In some
circumstances I can get GdkWindow handles to windows in other processes.
For example, if I drop a drag source onto another application.
Unfortunately, such windows return NULL queried for their parent.  Is this
the expected behavior?

-- 
Skip Montanaro (skip pobox com)
(847)971-7098




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]