2 # vim:ts=4:sw=4:expandtab
3 # renders the layout tree using asymptote
6 # will render the entire tree
8 # will render the tree starting from the node with the specified name,
9 # e.g. ./dump-asy.pl 2 will render workspace 2 and below
20 my $tree = $i3->get_tree->recv;
22 my $tmp = File::Temp->new(UNLINK => 0, SUFFIX => '.asy');
24 say $tmp "import drawtree;";
26 say $tmp "treeLevelStep = 2cm;";
29 my ($n, $parent) = @_;
31 my $o = ($n->{orientation} eq 'none' ? "u" : ($n->{orientation} eq 'horizontal' ? "h" : "v"));
32 my $w = (defined($n->{window}) ? $n->{window} : "N");
38 $na =~ s/~/\\textasciitilde{}/g;
40 if (!defined($n->{window})) {
41 $type = $n->{orientation} . '-split';
43 my $name = qq|``$na'' ($type)|;
45 print $tmp "TreeNode n" . $n->{id} . " = makeNode(";
47 print $tmp "n" . $parent->{id} . ", " if defined($parent);
48 print $tmp "\"" . $name . "\");\n";
50 dump_node($_, $n) for @{$n->{nodes}};
53 sub find_node_with_name {
54 my ($node, $name) = @_;
56 return $node if ($node->{name} eq $name);
57 for my $child (@{$node->{nodes}}) {
58 my $res = find_node_with_name($child, $name);
59 return $res if defined($res);
67 # Find the specified node in the tree
68 $root = find_node_with_name($tree, $start);
73 say $tmp "draw(n" . $root->{id} . ", (0, 0));";
78 system("cd /tmp && asy $tmp && gv --scale=-1000 --noresize --widgetless $rep && rm $rep");