#!perl

require "./xbase.pl";
require "./xatomhash.pl";

$xopen = &xlib::x_open_display($ENV{"DISPLAY"});
die $xlib::status if not defined $xopen;
tie %xatom, XATOM, $xopen;

sub printatoms {
    my ($d, $w) = @_;
    my @atoms = xlib::x_listproperties($d,$w);
    for $i (@atoms) {
	my $n = $xatom{$i};
	my @x = xlib::x_getproperty($d,$X::defines{"xFalse"}, $w, $i,
				    $X::defines{"AnyPropertyType"}, 0,255);
	my $ptn = ($x[2]==0)?"*none*":($xatom{$x[2]});
	printf " 0x%x (%s)[$ptn]<%s>", $i, $n, $x[1];
    }
    print "\n";
}

sub query {
    my ($d,$w,$n)=@_;
    my @lf = &xlib::x_querytree($d, $w);
    shift @lf;			# lose the rep, we just want the kids
    my $i;
    for $i (@lf) {
	printf("%s%x", " " x $n, $i);
	printatoms($d,$i);
	query($d,$i,$n+1);
    }
}
print "root: ";
printatoms($xopen,xlib::defaultroot($xopen));
query($xopen,undef,0);


close $xopen->{"XFD"};
