File: random-win.pl

package info (click to toggle)
libx11-protocol-perl 0.53-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 556 kB
  • ctags: 869
  • sloc: perl: 8,298; makefile: 595; ansic: 580
file content (39 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl

# Overwrite a bunch of randomly chosen windows on the screen with
# random-colored rectangles. You might want to learn about the
# "xrefresh" program before trying this one.

# Demonstrates the use of "robust_req"

use X11::Protocol;

$X = X11::Protocol->new;

my $gc = $X->new_rsrc;
$X->req('CreateGC', $gc, $X->root);

for (1 .. 2500) {
    my $client = rand(50);
    my $client_id = rand(200);
    my $id = $client << 21 | $client_id;
    printf "XID %x ", $id;
    my($result,) = $X->robust_req('GetGeometry', $id);
    my %geom;
    if (ref $result) {
	print "exists\n";
	%geom = @$result;
    } else {
	print "does not exist\n";
	next;
    }
    # Make sure we've got a Window rather than a Pixmap, since overwriting
    # Pixmaps is more permanent and therefore less amusing.
    next unless ref $X->robust_req('GetWindowAttributes', $id);
    $X->req('ChangeGC', $gc, 'foreground' => rand(2**32));
    my($result,) = $X->robust_req('PolyFillRectangle', $id, $gc,
				  [5, 5, $geom{width}-10, $geom{height}-10]);
    if (not ref $result) {
	print "Ignoring $result error\n";
    }
}