chiark / gitweb /
keystroke injection attempts
[ypp-sc-tools.web-live.git] / pctb / ls-xwindow-names
diff --git a/pctb/ls-xwindow-names b/pctb/ls-xwindow-names
new file mode 100755 (executable)
index 0000000..7fbbe40
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+use strict (qw(vars));
+
+use IO::File;
+
+our @pipes;
+
+sub reap_pipe () {
+    my ($child, $pipe) = @{ shift @pipes };
+    { local ($/) = undef; $_= <$pipe>; }
+    if (m/^WM_NAME: +not found/) {
+    } elsif (m/^WM_NAME\(STRING\) = $/) {
+    } elsif (m/^WM_NAME\(STRING\) = \"(.*)\"$/) {
+       print "$child $1\n" or die $!;
+    } else {
+       die "$child $_ ?";
+    }
+    $!=0; $pipe->close(); $? and die "$? $! ?";
+}
+
+open WI, "LC_ALL=C xwininfo -root -children |" or die $!;
+while (<WI>) {
+    next unless m/^\s+\d+ children:/..0;
+    next unless m/^\s+(0x[0-9a-f]+) /;
+    my $child= $1;
+
+    my $pipe= new IO::File "LC_ALL=C xprop -id $child WM_NAME |" or die $!;
+    push @pipes, [ $child, $pipe ];
+
+    while (@pipes > 40) { reap_pipe(); }
+}
+$!=0; close WI; $? and die "$? $! ?";
+
+while (@pipes) { reap_pipe(); }
+
+close STDOUT or die $!;