chiark / gitweb /
keystroke injection attempts
[ypp-sc-tools.main.git] / pctb / ls-xwindow-names
1 #!/usr/bin/perl -w
2 use strict (qw(vars));
3
4 use IO::File;
5
6 our @pipes;
7
8 sub reap_pipe () {
9     my ($child, $pipe) = @{ shift @pipes };
10     { local ($/) = undef; $_= <$pipe>; }
11     if (m/^WM_NAME: +not found/) {
12     } elsif (m/^WM_NAME\(STRING\) = $/) {
13     } elsif (m/^WM_NAME\(STRING\) = \"(.*)\"$/) {
14         print "$child $1\n" or die $!;
15     } else {
16         die "$child $_ ?";
17     }
18     $!=0; $pipe->close(); $? and die "$? $! ?";
19 }
20
21 open WI, "LC_ALL=C xwininfo -root -children |" or die $!;
22 while (<WI>) {
23     next unless m/^\s+\d+ children:/..0;
24     next unless m/^\s+(0x[0-9a-f]+) /;
25     my $child= $1;
26
27     my $pipe= new IO::File "LC_ALL=C xprop -id $child WM_NAME |" or die $!;
28     push @pipes, [ $child, $pipe ];
29
30     while (@pipes > 40) { reap_pipe(); }
31 }
32 $!=0; close WI; $? and die "$? $! ?";
33
34 while (@pipes) { reap_pipe(); }
35
36 close STDOUT or die $!;