<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use X11::Protocol;
use X11::Protocol::Constants qw(InputOutput CopyFromParent Replace Exposure_m);

use IO::Select;
use strict;

$| = 1;

my $big_size = 1000;
my $small_wd = 50;
my $small_ht = 20;

my $X = X11::Protocol-&gt;new;

my $cmap = $X-&gt;default_colormap;
my($bg_pixel,) = $X-&gt;AllocColor($cmap, (0xdddd, 0xdddd, 0xdddd));

my $main_win = $X-&gt;new_rsrc;
$X-&gt;CreateWindow($main_win, $X-&gt;root, InputOutput, CopyFromParent,
		 CopyFromParent, (0, 0), $big_size, $big_size, 0,
		 'background_pixel' =&gt; $bg_pixel);

$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_ICON_NAME'), $X-&gt;atom('STRING'),
                   8, Replace, "long run");
$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_NAME'), $X-&gt;atom('STRING'), 8,
                   Replace, "Long-running X11::Protocol test");
$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_CLASS'), $X-&gt;atom('STRING'), 8,
                   Replace, "longrun\0LongRun");
$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_NORMAL_HINTS'),
                   $X-&gt;atom('WM_SIZE_HINTS'), 32, Replace,
                   pack("Lx16llx16llllllx4", 8|16|128|256,
			$big_size, $big_size,
                        1, 1, 1, 1, $big_size, $big_size));
$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_HINTS'), $X-&gt;atom('WM_HINTS'),
                   32, Replace, pack("LLLx24", 1|2, 1, 1));
my $delete_atom = $X-&gt;atom('WM_DELETE_WINDOW');
$X-&gt;ChangeProperty($main_win, $X-&gt;atom('WM_PROTOCOLS'), $X-&gt;atom('ATOM'),
                   32, Replace, pack("L", $delete_atom));

my $text_gc = $X-&gt;new_rsrc;
my($text_pixel,) = $X-&gt;AllocColor($cmap, (0x0000, 0x0000, 0x0000));
my $font = $X-&gt;new_rsrc;
$X-&gt;OpenFont($font, "fixed");
$X-&gt;CreateGC($text_gc, $main_win, 'foreground' =&gt; $text_pixel,
	     'font' =&gt; $font);

$X-&gt;MapWindow($main_win);

my $fds = IO::Select-&gt;new($X-&gt;connection-&gt;fh);

my $num_cols = $big_size / $small_wd;
my @cols;

my %visible;

sub label {
    my($win) = @_;
    $X-&gt;PolyText8($win, $text_gc, 4, ($small_ht + 10) / 2,
		  [0, sprintf("%x", $win)]);
}

sub handle_event {
    my(%e) = @_;
    if ($e{'name'} eq "Expose") {
	my $win = $e{'window'};
	label($win) if $visible{$win};
    }
}

$X-&gt;{'event_handler'} = \&amp;handle_event;

my $last_id;
for (;;) {
    while ($fds-&gt;can_read(0)) {
	$X-&gt;handle_input;
    }
    for (my $x = 0; $x &lt; $big_size; $x += $small_wd) {
	my @column;
	for (my $y = 0; $y &lt; $big_size; $y += $small_ht) {
#  	    my($rand_pixel,) =
#  	      $X-&gt;AllocColor($cmap, (rand(65536), rand(65535), rand(65535)));
	    my $rand_pixel = rand(2**32);
	    my $win = $X-&gt;new_rsrc;
	    if ($win != $last_id + 1) {
		print "x";
	    }
	    $last_id = $win;
	    $X-&gt;CreateWindow($win, $main_win, InputOutput, CopyFromParent,
			     CopyFromParent, ($x, $y), $small_wd, $small_ht,
			     1, 'background_pixel' =&gt; $rand_pixel,
			     'event_mask' =&gt; Exposure_m);
	    if (rand() &lt; 0.001) {
		$X-&gt;MapWindow($win);
		push @column, $win if rand() &lt; 0.9;
		$visible{$win} = 1;
		label($win);
	    } else {
		$X-&gt;DestroyWindow($win);
	    }
	}
	push @cols, [@column];
	if (@cols &gt;= $num_cols) {
	    for my $win (@{shift @cols}) {
		delete $visible{$win};
		$X-&gt;DestroyWindow($win);
	    }
	}
    }
    print ".";
}
</pre></body></html>