Protocol/Ext/SHAPE.pm untested

filter: Statementstmt 0.0% 0 / 108 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 118 CC 3 SCAR 18.4
CC
3
Cov
0%
new
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 #!/usr/bin/perl
2  
3 # The `X11 Nonrectangular Window Shape Extension'
4 package X11::Protocol::Ext::SHAPE;
5  
6 # Copyright (C) 1997 Stephen McCamant. All rights reserved. This program
7 # is free software; you can redistribute and/or modify it under the same
8 # terms as Perl itself.
9  
10 use X11::Protocol qw(pad padding padded make_num_hash);
11 use Carp;
12  
13 use strict;
14 use vars '$VERSION';
15  
16 $VERSION = 0.01;
17  
18 sub new
19 {
20 my($pkg, $x, $request_num, $event_num, $error_num) = @_;
21 my($self) = {};
22  
23 # Constants
24  
25 $x->{'ext_const'}{'ShapeKind'} = ['Bounding', 'Clip'];
26 $x->{'ext_const_num'}{'ShapeKind'} =
27 {make_num_hash($x->{'ext_const'}{'ShapeKind'})};
28  
29 $x->{'ext_const'}{'ShapeOp'} = ['Set', 'Union', 'Intersect', 'Subtract',
30 'Invert'];
31 $x->{'ext_const_num'}{'ShapeOp'} =
32 {make_num_hash($x->{'ext_const'}{'ShapeOp'})};
33  
34 # Events
35 $x->{'ext_const'}{'Events'}[$event_num] = "ShapeNotify";
36 $x->{'ext_events'}[$event_num] =
37 ["xCxxLssSSLCxxxxxxxxxxx", ['shape_kind', 'ShapeKind'], 'x', 'y',
38 'width', 'height', 'time', 'shaped'];
39  
40 # Requests
41 $x->{'ext_request'}{$request_num} =
42 [
43 ["ShapeQueryVersion", sub {
44 my($self) = shift;
45 return "";
46 }, sub {
47 my($self) = shift;
48 my($data) = @_;
49 my($major, $minor) = unpack("xxxxxxxxSSxxxxxxxxxxxxxxxxxxxx",
50 $data);
51 return ($major, $minor);
52 }],
53 ["ShapeRectangles", sub {
54 my($self) = shift;
55 my($dest, $kind, $op, $x, $y, $ordering, @rects) = @_;
56 $op = $self->num('ShapeOp', $op);
57 $kind = $self->num('ShapeKind', $kind);
58 $ordering = $self->num('ClipRectangleOrdering', $ordering);
59 my($r);
60 for $r (@rects) {
61 $r = pack("ssSS", @$r);
62 }
63 return pack("CCCxLss", $op, $kind, $ordering, $dest, $x, $y)
64 . join("", @rects);
65 }],
66 ["ShapeMask", sub {
67 my($self) = shift;
68 my($win, $kind, $op, $x, $y, $pixmap) = @_;
69 $op = $self->num('ShapeOp', $op);
70 $kind = $self->num('ShapeKind', $kind);
71 $pixmap = 0 if $pixmap eq "None";
72 return pack("CCxxLssL", $op, $kind, $win, $x, $y, $pixmap);
73 }],
74 ["ShapeCombine", sub {
75 my($self) = shift;
76 my($dst, $d_kind, $op, $x, $y, $src, $s_kind) = @_;
77 $op = $self->num('ShapeOp', $op);
78 $d_kind = $self->num('ShapeKind', $d_kind);
79 $s_kind = $self->num('ShapeKind', $s_kind);
80 return pack("CCCxLssL", $op, $d_kind, $s_kind, $dst, $x, $y, $src);
81 }],
82 ["ShapeOffset", sub {
83 my($self) = shift;
84 my($win, $kind, $x, $y) = @_;
85 $kind = $self->num('ShapeKind', $kind);
86 return pack("CxxxLss", $kind, $win, $x, $y);
87 }],
88 ["ShapeQueryExtents", sub {
89 my($self) = shift;
90 my($win) = @_;
91 return pack("L", $win);
92 }, sub {
93 my($self) = shift;
94 my($data) = @_;
95 my($b, $c, $b_x, $b_y, $b_w, $b_h, $c_x, $c_y, $c_w, $c_h)
96 = unpack("xxxxxxxxCCxxssSSssSSxxxx", $data);
97 return ($b, $c, $b_x, $b_y, $b_w, $b_h, $c_x, $c_y, $c_w, $c_h);
98 }],
99 ["ShapeSelectInput", sub {
100 my($self) = shift;
101 my($win, $enable) = @_;
102 return pack("LCxxx", $win, $enable);
103 }],
104 # The R6 documentation gets the next two minor opcodes wrong;
105 # this usage follows <X11/extensions/shape.h>.
106 ["ShapeInputSelected", sub {
107 my($self) = shift;
108 my($win) = @_;
109 return pack("L", $win);
110 }, sub {
111 my($self) = shift;
112 my($data) = @_;
113 return unpack("xCxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $data);
114 }],
115 ["ShapeGetRectangles", sub {
116 my($self) = shift;
117 my($win, $kind) = @_;
118 $kind = $self->num('ShapeKind', $kind);
119 return pack("LCxxx", $win, $kind);
120 }, sub {
121 my($self) = shift;
122 my($data) = @_;
123 my($ordering, $nrects) =
124 unpack("xCxxxxxxLxxxxxxxxxxxxxxxxxxxx", substr($data, 0, 32));
125 my($i, @rects);
126 for $i (0 .. $nrects - 1) {
127 push @rects, [unpack("ssSS", substr($data, 32 + 8 * $i, 8))];
128 }
129 return ($self->interp('ClipRectangleOrdering', $ordering), @rects);
130 }]
131 ];
132 my($i);
133 for $i (0 .. $#{$x->{'ext_request'}{$request_num}}) {
134 $x->{'ext_request_num'}{$x->{'ext_request'}{$request_num}[$i][0]} =
135 [$request_num, $i];
136 }
137 ($self->{'major'}, $self->{'minor'}) = $x->req('ShapeQueryVersion');
138 if ($self->{'major'} != 1) {
139 carp "Wrong SHAPE version ($self->{'major'} != 1)";
140 return 0;
141 }
142 return bless $self, $pkg;
143 }
144  
145 1;
146 __END__