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

# This is a virtually complete test of all of the protocol's features
# -- it was used by the author during development. It generates a lot
# of output to STDOUT, uses a bunch of memory, and messes with your
# display in various ways. (Though some of the most egregious have
# been commented out). Run it at your own risk.

use X11::Protocol 0.02;

use X11::Keysyms qw(%Keysyms MISCELLANY XKB_KEYS LATIN1);
%Keysyms_name = reverse %Keysyms;

sub pretty
{
    my($x) = @_;
    if (not ref $x)
    {
	if ($x == 0 and $x ne "0")
	{
	    $x = "..." if $x =~ /[\cA-\cZ]/;
	    print "`$x'";
	}
	else
	{
	    printf "$x=0x%x", $x;
	}
    }
    elsif (ref($x) eq "ARRAY")
    {
	my($i);
	print "[";
	for $i (@$x) { pretty($i); print ", ";}
	print "]";
    }
    elsif (ref($x) eq "HASH" or ref($x) eq "X11::Protocol")
    {
	my($k, $v);
	print "{";
	while (($k, $v) = each(%$x))
	{
	    print "$k =&gt; ";
	    pretty($v);
	    print ", ";
	}
	print "}";
    }
    else
    {
	print $x;
    }
}

sub my_sleep {
    my($secs) = @_;
    $x-&gt;flush();
    sleep($secs);
}

%opts = @ARGV;
$display = $opts{'-d'} || $opts{'-display'} || $ENV{'DISPLAY'} || ":0.0"; 

$x = X11::Protocol-&gt;new($display);
pretty $x;
print "\n";
$win = $x-&gt;new_rsrc;
print "$win\n";
$x-&gt;error_handler(sub {});
$x-&gt;error_handler(\&amp;X11::Protocol::default_error_handler);
sub print_event
{
    my(%e) = @_;
    my($i);
    $last_event_time = $e{'time'} if $e{'time'};
    exit if $e{'name'} eq "KeyPress" and ($e{'detail'} == 24 or $done);
    print delete($e{'name'}), ": ";
    print join(", ", map("$_ $e{$_}", keys %e)), "\n";
}
$x-&gt;{'event_handler'} = \&amp;print_event;
#$x-&gt;{'event_handler'} = 'queue';

$x-&gt;req('CreateWindow', $win, $x-&gt;{'root'}, "InputOutput",
	$x-&gt;{'root_depth'}, "CopyFromParent",
	(0, 0), 100, 100, 1, "backing_store" =&gt; "WhenMapped",
	'background_pixel' =&gt; $x-&gt;{'white_pixel'});
$x-&gt;req('ChangeProperty', $win,
	$x-&gt;req('InternAtom', "WM_NAME", 0), 
	$x-&gt;req('InternAtom', "STRING", 0), 8, "Replace", "Perl X11 Client");  
$x-&gt;req('ChangeWindowAttributes', $win, "event_mask" =&gt; #0x01ebffff);
	$x-&gt;pack_event_mask('KeyPress', 'KeyRelease', 'ButtonPress',
			    'ButtonRelease', 'EnterWindow', 'LeaveWindow',
			    'PointerMotion', 'ButtonMotion', 'KeymapState',
			    'Exposure', 'VisibilityChange', 'StuctureNotify',
			    'SubstructureNotify', 'FocusChange',
			    'PropertyChange', 'ColormapChange'));
print join " ", $x-&gt;req('GetWindowAttributes', $win), "\n";
$x-&gt;request('MapWindow', $win);
req $x 'ConfigureWindow', $win, "height" =&gt; 200, "width" =&gt; 200;
$kid1 = $x-&gt;new_rsrc;
$x-&gt;req('CreateWindow', $kid1, $win, 'InputOutput', $x-&gt;{'root_depth'},
	'CopyFromParent', (50, 50), 75, 75, 4);
$kid2 = $x-&gt;new_rsrc;
$x-&gt;req('CreateWindow', $kid2, $win, 'InputOutput', $x-&gt;{'root_depth'},
	'CopyFromParent', (100, 100), 75, 75, 4);
$x-&gt;req('MapSubwindows', $win);
my_sleep 2;
$x-&gt;req('CirculateWindow', $win, "LowerHighest");
my_sleep 2;
$x-&gt;req('DestroySubwindows', $win);
print join " ", $x-&gt;req('GetGeometry', $win), "\n";
print join " ", 
    $x-&gt;req('GetGeometry', $x-&gt;{'root'}), "\n";
($root, $parent, @kids) = $x-&gt;req('QueryTree', $x-&gt;{'root'});
for $kid (@kids) {
    print join " ", $x-&gt;req('GetGeometry', $kid), "\n";
}
print $x-&gt;req('InternAtom', "WM_NAME", 0), "\n";
for $atom (1 .. 90) {
    print "$atom: ", $x-&gt;req('GetAtomName', $atom), ", ";
}
print "\n\n";
for $atom ($x-&gt;req('ListProperties', $win)) {
    print $x-&gt;atom_name($atom), " =&gt; ";
    print join(",", $x-&gt;req('GetProperty', $win, $atom, "AnyPropertyType",
			    0, 200, 0)), "\n";
}
$root_wid = $x-&gt;{'root'};
for (1 .. 10)
{
    my($e) = $x-&gt;pack_event('code' =&gt; 2, 'detail' =&gt; 25, 'time' =&gt; 0,
			    'root' =&gt; $root_wid, 'event' =&gt; $win, 'child' =&gt; 0,
			    'root_x' =&gt; 100, 'root_y' =&gt; 100, 'event_x' =&gt; 5,
			    'event_y' =&gt; 5, 'state' =&gt; 0, 'same_screen' =&gt; 1,
			    'synthetic' =&gt; 0);
    $x-&gt;req('SendEvent', "PointerWindow", 0, 0, $e);
    $x-&gt;req('SendEvent', "PointerWindow", 0, 0,
	    $x-&gt;pack_event('name' =&gt; "KeyRelease", 'detail' =&gt; 25, 'time' =&gt; 0,
			   'root' =&gt; $root_wid, 'event' =&gt; $win, 'child' =&gt; 0,
			   'root_x' =&gt; 100, 'root_y' =&gt; 100, 'event_x' =&gt; 5,
			   'event_y' =&gt; 5, 'state' =&gt; 0, 'same_screen' =&gt; 1));
}
print "Grabbing...";
$x-&gt;req('GrabPointer', $win, 0, 0, 'Asynchronous', 'Asynchronous', $win, 0, 0);
my_sleep 2;
$x-&gt;req('UngrabPointer', 0);
print "done.\n";
my_sleep 2;
print "Grabbing server...";
$x-&gt;req('GrabServer');
my_sleep 2;
$x-&gt;req('UngrabServer');
print "done.\n";
print "-&gt;", join(" ", $x-&gt;req('QueryPointer', $win)), "\n";
for $motion ($x-&gt;req('GetMotionEvents', $last_event_time, 'CurrentTime', $win))
{
    print "$motion-&gt;[0]: ($motion-&gt;[1], $motion-&gt;[2])\n";
}
print "--&gt;", join(" ", $x-&gt;req('TranslateCoordinates',
				      $win =&gt; $root_wid, 50, 50)), "\n";
for (1 .. 10)
{
    $x-&gt;req('WarpPointer', 'None', $root_wid, 0, 0, 0, 0,
	    rand($x-&gt;{'width_in_pixels'} * .9),
	    rand($x-&gt;{'height_in_pixels'} * .9));
    my_sleep 1;
}
print "---&gt;", join(" ", $x-&gt;req('GetInputFocus')), "\n";
print "----&gt;", $x-&gt;req('QueryKeymap'), "\n";
$fid = $x-&gt;new_rsrc;
$x-&gt;req('OpenFont', $fid, 'fixed');
print "`fixed' = $fid\n";

%fixed = $x-&gt;req('QueryFont', $fid);
print join(" ", %fixed), "\n";
print join(" ", @{$fixed{'min_bounds'}}), "\n";
print join(" ", @{$fixed{'max_bounds'}}), "\n";
%prop = %{$fixed{'properties'}};
foreach $atom (keys %prop)
{
    print $x-&gt;atom_name($atom), " =&gt; ", $prop{$atom}, "; ";
}
print "\n"; 
foreach $ci (@{$fixed{'char_infos'}})
{
    print join (" ", @$ci), "; ";
}
print "\n";
print join(" ", $x-&gt;req('QueryTextExtents', $fid, "\0H\0e\0l\0l\0o")), "\n";
print join("\n", $x-&gt;req('ListFonts', '-adobe-*', 50)), "\n";
foreach $font ($x-&gt;req('ListFontsWithInfo', '-adobe-*', 5))
{
    %info = %$font;
    print join(" ", %info), "\n";
    print join(" ", @{$info{'min_bounds'}}), "\n";
    print join(" ", @{$info{'max_bounds'}}), "\n";
    %prop = %{$info{'properties'}};
    foreach $atom (keys %prop)
    {
	print $x-&gt;atom_name($atom), " =&gt; ", $prop{$atom}, "; ";
    }
    print "\n"; 
}
print join(", ", $x-&gt;req('GetFontPath')), "\n";
#$x-&gt;req('SetFontPath', $x-&gt;req('GetFontPath'));
#print join(", ", $x-&gt;req('GetFontPath')), "\n";
$pixmap = $x-&gt;new_rsrc;
$x-&gt;req('CreatePixmap', $pixmap, $win, $x-&gt;{'root_depth'}, 50, 50); 
$x-&gt;req('FreePixmap', $pixmap);
$gc = $x-&gt;new_rsrc;
$x-&gt;req('CreateGC', $gc, $win, 'function' =&gt; 'Xor', 'line_width' =&gt; 2,
	'join_style' =&gt; 'Miter', 'font' =&gt; $fid, 'arc_mode' =&gt; 'PieSlice',
	'foreground' =&gt; $x-&gt;{'white_pixel'},
	'background' =&gt; $x-&gt;{'black_pixel'},
	'graphics_exposures' =&gt; 0);
$x-&gt;req('ChangeGC', $gc, 'join_style' =&gt; 'Round');
$fancy_gc = $x-&gt;new_rsrc;
$x-&gt;req('CreateGC', $fancy_gc, $win);
$x-&gt;req('CopyGC', $gc, $fancy_gc, 'function', 'line_width', 'join_style',
	'font', 'arc_mode', 'background', 'graphics_exposures');
$x-&gt;req('ChangeGC', $fancy_gc, 'line_style' =&gt; 'OnOffDash');
$x-&gt;req('SetDashes', $fancy_gc, 0, (1, 2, 1, 3, 1));
$x-&gt;req('SetClipRectangles', $fancy_gc, (0, 0), 'UnSorted', [0, 40, 100, 20],
	[40, 0, 20, 100]);
$x-&gt;req('ClearArea', $win, (0, 0), 200, 200, 0);
$white = $x-&gt;{'white_pixel'};
$black = $x-&gt;{'black_pixel'};
$x-&gt;req('ChangeGC', $gc, 'function' =&gt; 'Copy', 'background' =&gt; $white,
	'foreground' =&gt; $black);
for (1 .. 500)
{
    push @points, rand(200);
}
$x-&gt;PolyPoint($win, $gc, 'Origin', @points);
for $c (@points)
{
    $c = 200 - $c;
}
$x-&gt;PolySegment($win, $gc, @points);
for $c (@points)
{
    $c /= 10;
    $c -= 10;
}
$x-&gt;ClearArea($win, (0, 0), 200, 200, 0);
$x-&gt;PolyLine($win, $gc, 'Previous', (100, 100), @points);
$x-&gt;ChangeGC($gc, 'function' =&gt; "Xor");
for (1 .. 200)
{
    $x-&gt;req('CopyArea', $win, $win, $gc, (rand(160), rand(160)), 40, 40,
	    (rand(160), rand(160)));
}
$x-&gt;req('ChangeGC', $gc, 'function' =&gt; "Copy");
for (1 .. 200)
{
    $x-&gt;req('CopyPlane', $win, $win, $fancy_gc, (rand(160), rand(160)), 
	    40, 40, (rand(160), rand(160)), 1 &lt;&lt; 0);
}
$x-&gt;req('ClearArea', $win, (0, 0), 200, 200, 0);
for (1 .. 25)
{
    push @rects, [rand(100), rand(100), rand(100), rand(100)];
}
$x-&gt;req('PolyRectangle', $win, $gc, @rects);
for (1 .. 16)
{
    push @arcs, [rand(150), rand(150), 50, 50, 0, rand(360 * 64)];
}
$x-&gt;req('PolyArc', $win, $gc, @arcs);
$x-&gt;req('FillPoly', $win, $gc, 'Convex', 'Origin',
	(100,0)=&gt;(150,150)=&gt;(0,100));
@rects = ();
for (1 .. 100)
{
    push @rects, [rand(190), rand(190), rand(10), rand(10)];
}
$x-&gt;req('PolyFillRectangle', $win, $gc, @rects);
@arcs = ();
for (1 .. 25)
{
    push @arcs, [rand(175), rand(175), 25, 25, 90 * 64, rand(360 * 64)];
}
$x-&gt;req('PolyFillArc', $win, $gc, @arcs);
$x-&gt;req('ClearArea', $win, (0, 0), 200, 200, 0);
if ($x-&gt;{'bitmap_bit_order'} eq 'LeastSignificant' 
    and $x-&gt;{'bitmap_scanline_unit'} == 32
    and $x-&gt;{'bitmap_scanline_pad'} == 32)
{
    $bmap = 
	"\0\0\xff\xff\xff\xff\x0f\0" x 8 .
	"\0\0\xff\0\0\0\xff\0" x 8 .
	"\0\0\xff\xff\xff\xff\x0f\0" x 8 .
	"\0\0\xff\0\0\0\0\0" x 8 .
	"\0\0\xff\0\0\0\0\0" x 8;
    for $shift (0 .. 3)
    {
	$x-&gt;req('PutImage', $win, $gc, 1, 56, 40,
		(0, 2 + 42 * $shift), 8, 'Bitmap', $bmap);
    }
}

if (0) 
{
    $pixmap = 
#        1234567890123456789012345678
	"                            ".
	" ####  ##### ####  #        ".
	" #   # #     #   # #        ".
        " ####  ####  ####  #        ".
	" #     #     #   # #        ".
        " #     ##### #   # #####    ".
	"                            ";

    @pixels = unpack("C*", $pixmap);
    for $p (@pixels)
    {
	$p = 0 if $p == ord("#");
    }
    for (1 .. 50)
    {
	@p = @pixels;
	for $p (@p)
	{
	    $p = rand(256) if $p;
	}
	$x-&gt;req('PutImage', $win, $gc, 8, 25, 7,
		(rand(175), rand(193)), 0, 'ZPixmap', pack("C*", @p));
    }
}


($d, $v, $image) = $x-&gt;req('GetImage', $win, (0, 0), 79, 24, 0xff, 'ZPixmap');
$image =~ tr/\0/ /;
$image =~ tr/ -~/./c;
for $row (0 .. 23)
{
    print substr($image, $row * 80, 80), "\n";
}
$x-&gt;req('ClearArea', $win, (0, 0), 200, 200, 0);
$smallfid = $x-&gt;new_rsrc;
$x-&gt;req('OpenFont', $smallfid, '6x10');
$x-&gt;req('PolyText8', $win, $gc, 2, 20, [0, "Hello, "], 
	$smallfid, [-3, "world!"]);
$x-&gt;req('PolyText8', $win, $gc, 2, 35, [0, "Perl " x 300]);
#$largefid = $x-&gt;new_rsrc;
#$x-&gt;req('OpenFont', $largefid, 
#	'-*-*-medium-r-normal--14-*-*-*-c-*-jisx0208.1983-0');
#$x-&gt;req('PolyText16', $win, $gc, 2, 50, $largefid, 
#    [0, "\061\101\061\104\061\106\061\110\061\112\061\113\061\114\061\115"
#     . "\061\116\061\117\061\122\061\125\061\130\061\133"]);
$x-&gt;req('ChangeGC', $gc, 'font' =&gt; $smallfid);
$x-&gt;req('ImageText8', $win, $gc, 2, 70, "Perl");
$x-&gt;req('ImageText16', $win, $gc, 2, 80, "\0P\0e\0r\0l");
if ($x-&gt;{'root_depth'} == 8) {
    $cmap = $x-&gt;new_rsrc;
    $x-&gt;req('CreateColormap', $cmap, $x-&gt;{'root_visual'}, $win, 'All');
    $new_cmap = $x-&gt;new_rsrc;
    $x-&gt;req('CopyColormapAndFree', $new_cmap, $cmap);
    $x-&gt;req('FreeColormap', $cmap);
}
$cmap = $x-&gt;{'default_colormap'};
print join(", ", $x-&gt;req('ListInstalledColormaps', $win)), "\n";
print join(", ", $x-&gt;req('ListInstalledColormaps', $root_wid)), "\n";
($color1, $r, $g, $b) = $x-&gt;req('AllocColor', $cmap, 
				1 * 65535, 0 * 65535, 0 * 65535); 
print "$color1 = ($r, $g, $b)\n";
($color2, $r1, $g1, $b1, $r2, $g2, $b2) = 
    $x-&gt;req('AllocNamedColor', $cmap, 'orange');
print "orange =~= $color2 =~= ($r1, $g1, $b1) =~= ($r2, $g2, $b2)\n";
if ($x-&gt;{'root_depth'} == 8) {
    ($pixels, $masks) = $x-&gt;req('AllocColorCells', $cmap, 1, 0, 0);
    $color3 = $pixels-&gt;[0];
    print "$color3\n";
    ($rm, $gm, $bm, @pixels) =
	$x-&gt;req('AllocColorPlanes', $cmap, 1, (0,0,1), 0);
    print "$rm|$gm|$bm = ", join(", ", @pixels), "\n";
    $x-&gt;req('StoreColors', $cmap, [$color3 =&gt; (65535, 0, 0)], 
	    [$pixels[0] =&gt; (0, 0, 0), 1]);
    $x-&gt;req('StoreNamedColor', $cmap, $color3, 'salmon', 7);
}
@colors = $x-&gt;req('QueryColors', $cmap, 0 .. 255);
for $c (@colors)
{
    printf "(0x%04x, 0x%04x, 0x%04x), ", @$c;
    print "\n" unless ++$i % 3;
}
print "\n";
($r1, $g1, $b1, $r2, $g2, $b2) = $x-&gt;req('LookupColor', $cmap, 'bisque');
print "bisque =~= ($r1, $g1, $b1) =~= ($r2, $g2, $b2)\n";

$fg_pm = $x-&gt;new_rsrc;
$x-&gt;send('CreatePixmap', $fg_pm, $win, 1, 16, 16); 
$mask_pm = $x-&gt;new_rsrc;
$x-&gt;send('CreatePixmap', $mask_pm, $win, 1, 16, 16);
$cursor_gc = $x-&gt;new_rsrc;
$x-&gt;send('CreateGC', $cursor_gc, $fg_pm, 'line_width' =&gt; 2,'foreground' =&gt; 0); 
$x-&gt;send('PolyFillRectangle', $fg_pm, $cursor_gc, [(0, 0), 16, 16]);
$x-&gt;send('PolyFillRectangle', $mask_pm, $cursor_gc, [(0, 0), 16, 16]);
$x-&gt;send('ChangeGC', $cursor_gc, 'foreground' =&gt; 1);
$x-&gt;send('PolyArc', $mask_pm, $cursor_gc, [1, 1, 13, 13, 0, 360*64]);
$x-&gt;send('ChangeGC', $cursor_gc, 'line_style' =&gt; 'OnOffDash');
$x-&gt;send('PolyArc', $fg_pm, $cursor_gc, [1, 1, 13, 13, 0, 360*64]);
$cursor = $x-&gt;new_rsrc;
$x-&gt;send('CreateCursor', $cursor, $fg_pm, $mask_pm, (65535, 0, 0), 
	 (45000, 45000, 45000), (8, 8));
$x-&gt;send('ChangeWindowAttributes', $win, 'cursor' =&gt; $cursor);
$x-&gt;send('FreePixmap', $fg_pm);
$x-&gt;send('FreePixmap', $mask_pm);
$x-&gt;send('FreeGC', $cursor_gc);

my_sleep 5;
$cursor_fnt = $x-&gt;new_rsrc;
$x-&gt;req('OpenFont', $cursor_fnt, 'cursor');
$new_cursor = $x-&gt;new_rsrc;
$x-&gt;req('CreateGlyphCursor', $new_cursor, $cursor_fnt, $cursor_fnt, 0, 1,
	(65535, 65535, 65535), (0, 0, 0));
$x-&gt;req('CloseFont', $cursor_fnt);
$x-&gt;req('ChangeWindowAttributes', $win, 'cursor' =&gt; $new_cursor);
$x-&gt;req('FreeCursor', $cursor);
$cursor = $new_cursor;
for $p (0 .. 10)
{
    $x-&gt;req('RecolorCursor', $cursor,
	    (65535, 65535 - $p*6553.5, 65535- $p*6553.5), (0, 0, 0));
    my_sleep 1;
}
($w, $h) = $x-&gt;req('QueryBestSize', 'Cursor', $root_wid, 16, 16);
print "$w x $h is a good size for a cursor.\n";

for $ext ($x-&gt;req('ListExtensions'))
{
    ($major, $event, $error) = $x-&gt;req('QueryExtension', $ext);
    print "$ext: request $major, event $event, error $error\n";
}

($old) = $x-&gt;req('GetKeyboardMapping', $x-&gt;{'max_keycode'}, 1);
#$x-&gt;req('ChangeKeyboardMapping', $x-&gt;{'max_keycode'} - 1, 4, 
#	[$Keysyms{"a"}, $Keysyms{"A"}, 0, 0],);

$i = $x-&gt;min_keycode;
for $ar ($x-&gt;req('GetKeyboardMapping', $x-&gt;{'min_keycode'}, 
		 $x-&gt;{'max_keycode'} - $x-&gt;{'min_keycode'} + 1))
#		 10))
{
    print "$i: ", join(", ", map($Keysyms_name{$_} || 'NoSymbol',
					@$ar)), "\n";
    $i++;
}

#$x-&gt;req('ChangeKeyboardMapping', $x-&gt;{'max_keycode'}, scalar(@$old), $old);

%kc = $x-&gt;req('GetKeyboardControl');
print join(" ", %kc), "\n";
$bp = $kc{'bell_pitch'};

$x-&gt;req('Bell', 100);
$x-&gt;req('ChangeKeyboardControl', 'bell_pitch' =&gt; 2 * $bp);
my_sleep 1;
$x-&gt;req('Bell', 100);
$x-&gt;req('ChangeKeyboardControl', 'bell_pitch' =&gt; $bp);

($num, $denom, $thresh) = $x-&gt;req('GetPointerControl');
print "Acceleration: $num/$denom; Threshold: $thresh\n";
$x-&gt;req('ChangePointerControl', 1, 0, $num * 2, $denom, $thresh);
my_sleep 2;
$x-&gt;req('ChangePointerControl', 1, 0, $num, $denom, $thresh);

($t_out, $interv, $pb, $allow_exp) = $x-&gt;req('GetScreenSaver');
print "Timeout: $t_out, Interval: $interv, Blanking: $pb, ";
print "Exposures: $allow_exp\n";
$x-&gt;req('SetScreenSaver', $t_out, $interv, $pb, $allow_exp);
($t_out, $interv, $pb, $allow_exp) = $x-&gt;req('GetScreenSaver');
print "Timeout: $t_out, Interval: $interv, Blanking: $pb, ";
print "Exposures: $allow_exp\n";

#$addr = pack("C4", (127, 0, 0, 1));
#sen('ChangeHosts', 'Insert', 'Internet', $addr);
($mode, @hosts) = $x-&gt;req('ListHosts');
for $ar (@hosts)
{
    print "$ar-&gt;[0]: ", join(".", unpack("C4", $ar-&gt;[1])), "\n";
}

$x-&gt;req('SetAccessControl', $mode);
$x-&gt;req('SetCloseDownMode', 'Destroy');
#$x-&gt;req('KillClient', 0x200004b);
$x-&gt;req('RotateProperties', $win, 1, ($x-&gt;req('InternAtom', 'WM_NAME', 1)));
$x-&gt;req('ForceScreenSaver', 'Activate');
@map = $x-&gt;req('GetPointerMapping');
print join(", ", @map), "\n";
$x-&gt;req('SetPointerMapping', @map);
@map = $x-&gt;req('GetModifierMapping');
for $ar (@map)
{
    print "[", join(",", @$ar), "]\n";
}
#$x-&gt;req('SetModifierMapping', @map);

$x-&gt;req('NoOperation', 4);

if ($x-&gt;{'root_depth'} == 8) {
    $x-&gt;req('FreeColors', $cmap, 0, $color1, $color2, $color3, @pixels);
} else {
    $x-&gt;FreeColors($cmap, 0, $color1, $color2);
}
$x-&gt;req('FreeGC', $fancy_gc);
$x-&gt;req('CloseFont', $fid);
$x-&gt;req('CloseFont', $smallfid);
#$x-&gt;req('CloseFont', $largefid);

$x-&gt;init_extensions;

if ($x-&gt;{'ext'}{"SHAPE"})
{
    $x-&gt;req('ShapeSelectInput', $win, 1);
    $x-&gt;req('ShapeRectangles', $win, 'Bounding', 'Set', (0, 0), 'UnSorted',
	    [(0, 0), 50, 50], [(50, 50), 50, 50]);
    $shape_pm = $x-&gt;new_rsrc;
    $x-&gt;req('CreatePixmap', $shape_pm, $win, 1, 100, 100);
    $shape_gc = $x-&gt;new_rsrc;
    $x-&gt;req('CreateGC', $shape_gc, $shape_pm, 'foreground' =&gt; 0);
    $x-&gt;req('PolyFillRectangle', $shape_pm, $shape_gc, [0, 0, 100, 100]);
    $x-&gt;req('ChangeGC', $shape_gc, 'foreground' =&gt; 1);
    $x-&gt;req('PolyFillArc', $shape_pm, $shape_gc, [0, 0, 100, 100, 0, 360*64]);
    $x-&gt;req('ShapeMask', $win, 'Bounding', 'Union', 100, 100, $shape_pm);
    $x-&gt;req('ShapeCombine', $win, 'Bounding', 'Invert', 0, 0, $x-&gt;{'root'},
	    'Bounding');
    $x-&gt;req('ShapeOffset', $win, 'Bounding', 25, 25);
    print join(", ", $x-&gt;req('ShapeQueryExtents', $win)), "\n";
    print $x-&gt;req('ShapeInputSelected', $win), "\n";
    ($ordering, @rects) = $x-&gt;req('ShapeGetRectangles', $win, 'Bounding');
    print "Ordering: $ordering\n";
    for $rr (@rects)
    {
	print "[", join(", ", @$rr), "], ";
    }
    print "\n";
}

# This should be last, since it's a REAL memory hog.
if ($x-&gt;{'ext'}{'BIG_REQUESTS'})
{
    print "Maximum request length: ", $x-&gt;maximum_request_length * 4, "\n";
    for $i (1 .. 65536)
    {
        push @points, int(rand(200)), int(rand(200));
    }
    $x-&gt;PolyPoint($win, $gc, 'Origin', @points);
}

#print_event(%e) while %e = $x-&gt;dequeue_event;
#$x-&gt;{'event_handler'} = \&amp;print_event; 

$x-&gt;req('FreeGC', $gc);

$done = 1;
$x-&gt;handle_input while 1;
#print_event(%e) while %e = $x-&gt;next_event
</pre></body></html>