X11/Protocol/Ext/XTEST.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 104 CC 4 SCAR 12.8
CC
4
Cov
0%
_fake_input_pack
6.0
_num_time
6.0
_num_none
6.0
CRAP 3.6
1 # Copyright 2011, 2012, 2013, 2014, 2017 Kevin Ryde
2  
3 # This file is part of X11-Protocol-Other.
4 #
5 # X11-Protocol-Other is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # X11-Protocol-Other is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
17  
18 BEGIN { require 5 }
19 package X11::Protocol::Ext::XTEST;
20 use strict;
21 use X11::Protocol;
22  
23 use vars '$VERSION', '@CARP_NOT';
24 $VERSION = 31;
25 @CARP_NOT = ('X11::Protocol');
26  
27 # uncomment this to run the ### lines
28 #use Smart::Comments;
29  
30  
31 # /usr/share/doc/x11proto-xext-dev/xtest.txt.gz
32 #
33 # /usr/include/X11/extensions/xtestproto.h
34 # /usr/include/X11/extensions/xtestconst.h
35 #
36 # /usr/include/X11/extensions/xtestext1proto.h
37 # /usr/include/X11/extensions/xtestext1const.h
38 # /usr/include/X11/extensions/xtestext1.h
39 #
40 # /usr/include/X11/extensions/XTest.h
41 # /usr/share/doc/libxext-dev/xtest1.txt.gz
42 # lib/Xext/XTestExt1.c
43 # Xlib
44 #
45 # Server side xtest.c
46 #
47 # /usr/share/doc/x11proto-core-dev/x11protocol.txt.gz
48 # /usr/share/doc/x11proto-input-dev/XIproto.txt.gz
49 # /usr/share/doc/x11proto-input-dev/XI2proto.txt.gz
50 # /usr/include/X11/extensions/XIproto.h
51 # /usr/include/X11/extensions/xtestconst.h
52  
53  
54 # these not documented yet ...
55 use constant CLIENT_MAJOR_VERSION => 2;
56 use constant CLIENT_MINOR_VERSION => 2;
57  
58 my $reqs =
59 [
60 ['XTestGetVersion', # 0
61 sub {
62 my ($X, $major, $minor) = @_;
63 return pack 'CxS', $major, $minor;
64 },
65 sub {
66 my ($X, $data) = @_;
67 return unpack 'xCxxxxS', $data;
68  
69 # Any interest in holding onto the version?
70 # my ($server_major, $server_minor) = unpack 'xCxxxxS', $data;
71 # ### $server_major
72 # ### $server_minor
73 # my $self;
74 # if ($self = $self->{'ext'}{'XTEST'}->[3]) {
75 # $self->{'major'} = $server_major;
76 # $self->{'minor'} = $server_minor;
77 # }
78 # return ($server_major, $server_minor);
79 }],
80  
81 ['XTestCompareCursor', # 1
82 sub {
83 my ($X, $window, $cursor) = @_;
84 return pack ('LL',
85 $window,
86 $cursor eq 'CurrentCursor' ? 1 : _num_none($cursor));
87 },
88 sub {
89 my ($X, $data) = @_;
90 return unpack 'xC', $data;
91 }],
92  
93 ['XTestFakeInput', # 2
94 sub {
95 my $X = shift;
96 if (ref $_[0] eq 'ARRAY') {
97 # one or more packets by arrayrefs
98 return join('',map {_fake_input_pack($X,@$_)} @_);
99 } else {
100 # one packet by event fields
101 return _fake_input_pack($X,@_);
102 }
103 } ],
104  
105 ['XTestGrabControl', # 3
106 sub {
107 my ($X, $impervious) = @_;
108 return pack 'Cxxx', $impervious;
109 }],
110 ];
111  
112 sub _fake_input_pack {
113 my $X = shift;
114 my %h = @_;
115  
116 if ($h{'name'} =~ /^(MotionNotify|(Key|Button)(Press|Release))$/) {
117  
118 # avoid some undef warnings from pack_event() in X11::Protocol 0.56
119 local $^W = 0;
120  
121 return $X->pack_event (detail => 0, # defaults
122 root_x => 0,
123 root_y => 0,
124 root => 0, # default current screen
125 time => 0, # default no delay
126  
127 # unused by XTestFakeInput, zero for the pack
128 event => 0, # window
129 child => 0, # window
130 event_x => 0,
131 event_y => 0,
132 state => 0,
133 same_screen => 0,
134  
135 @_);
136 } else {
137 return $X->pack_event (@_);
138 }
139 }
140  
141 sub _num_time {
142 my ($time) = @_;
143 if (defined $time && $time eq 'CurrentTime') {
144 return 0;
145 } else {
146 return $time;
147 }
148 }
149 sub _num_none {
150 my ($xid) = @_;
151 if (defined $xid && $xid eq "None") {
152 return 0;
153 } else {
154 return $xid;
155 }
156 }
157  
158 sub new {
159 my ($class, $X, $request_num, $event_num, $error_num) = @_;
160 ### XTest new()
161  
162 # Requests
163 _ext_requests_install ($X, $request_num, $reqs);
164  
165 # Any need to negotiate the version before using?
166 # my ($major, $minor) = $X->req('XTestQueryVersion',
167 # CLIENT_MAJOR_VERSION,
168 # CLIENT_MINOR_VERSION);
169 # if ($major != 1) {
170 # carp "Unrecognised XTest major version, got $major want 1";
171 # return 0;
172 # }
173 return bless {
174 # major => $major,
175 # minor => $minor,
176 }, $class;
177 }
178  
179 sub _ext_requests_install {
180 my ($X, $request_num, $reqs) = @_;
181  
182 $X->{'ext_request'}->{$request_num} = $reqs;
183 my $href = $X->{'ext_request_num'};
184 my $i;
185 foreach $i (0 .. $#$reqs) {
186 $href->{$reqs->[$i]->[0]} = [$request_num, $i];
187 }
188 }
189  
190 1;
191 __END__