| 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 | 1 | ▶ | BEGIN { require 5 } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | package X11::Protocol::Ext::X_Resource; | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | $VERSION = 31; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 27 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # /usr/include/X11/extensions/XResproto.h | ||||||||||||||||||||||||||||
| 30 | # protocol | ||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||
| 32 | # http://cgit.freedesktop.org/xorg/xserver/tree/Xext/xres.c | ||||||||||||||||||||||||||||
| 33 | # http://cgit.freedesktop.org/xorg/xserver/plain/Xext/xres.c | ||||||||||||||||||||||||||||
| 34 | # server side source | ||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||
| 36 | # /usr/include/X11/extensions/XRes.h | ||||||||||||||||||||||||||||
| 37 | # Xlib. | ||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | ### X_Resource.pm loads | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # these not documented yet ... | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use constant CLIENT_MAJOR_VERSION => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant CLIENT_MINOR_VERSION => 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | my $reqs = | ||||||||||||||||||||||||||||
| 49 | [ | ||||||||||||||||||||||||||||
| 50 | ["XResourceQueryVersion", # 0 | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | ### XResourceQueryVersion request | ||||||||||||||||||||||||||||
| 53 | 0 | shift; # $X | |||||||||||||||||||||||||||
| 54 | 0 | return pack 'CCxx', @_; # ($client_major, $client_minor) | |||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 0 | my ($X, $data) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | return unpack 'x8SS', $data; # ($server_major, $server_minor) | |||||||||||||||||||||||||||
| 59 | }], | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | ["XResourceQueryClients", # 1 | ||||||||||||||||||||||||||||
| 62 | \&_request_empty, | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($X, $data) = @_; | |||||||||||||||||||||||||||
| 65 | ### XResourceQueryClients reply | ||||||||||||||||||||||||||||
| 66 | 0 | my $num = unpack 'x8L', $data; | |||||||||||||||||||||||||||
| 67 | ### $num | ||||||||||||||||||||||||||||
| 68 | # obey $num rather than the reply length | ||||||||||||||||||||||||||||
| 69 | # Other way to do it: List::Pairwise::pair(unpack 'x32L'.(2*$num)) | ||||||||||||||||||||||||||||
| 70 | 0 | return map {[ unpack 'LL', substr($data,32+$_*8,8) ]} 0 .. $num-1; | |||||||||||||||||||||||||||
| 71 | } ], | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | ["XResourceQueryClientResources", # 2 | ||||||||||||||||||||||||||||
| 74 | \&_request_card32s, # ($X, $client_xid) | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($X, $data) = @_; | |||||||||||||||||||||||||||
| 77 | ### XResourceQueryClientResources reply | ||||||||||||||||||||||||||||
| 78 | 0 | my ($num) = unpack 'x8L', $data; | |||||||||||||||||||||||||||
| 79 | ### $num | ||||||||||||||||||||||||||||
| 80 | # obey $num rather than the reply length | ||||||||||||||||||||||||||||
| 81 | 0 | return unpack 'x32L'.(2*$num), $data; | |||||||||||||||||||||||||||
| 82 | }], | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ["XResourceQueryClientPixmapBytes", # 3 | ||||||||||||||||||||||||||||
| 85 | \&_request_card32s, # ($X, $client_xid) | ||||||||||||||||||||||||||||
| 86 | do { | ||||||||||||||||||||||||||||
| 87 | # see if 2^64-1 survives an sprintf %d, if so then 64-bit UV integers | ||||||||||||||||||||||||||||
| 88 | 1 | my $v = ((0xFFFFFFFF * (2.0**32)) + 0xFFFFFFFF); | |||||||||||||||||||||||||||
| 89 | 1 | ($v == sprintf("%u",$v)) | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | ? sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 92 | 0 | my ($X, $data) = @_; | |||||||||||||||||||||||||||
| 93 | ### XResourceQueryClientPixmapBytes reply, 64-bit system | ||||||||||||||||||||||||||||
| 94 | 0 | my ($lo, $hi) = unpack('x8LL', $data); | |||||||||||||||||||||||||||
| 95 | 0 | return $lo + ($hi << 32); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | : do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | # probe for where floating point loses precision | ||||||||||||||||||||||||||||
| 99 | # if $hi<$hi_limit then $hi*2**32 + $lo is exact | ||||||||||||||||||||||||||||
| 100 | 0 | my $hi_limit = 1; | |||||||||||||||||||||||||||
| 101 | 0 | foreach (1 .. 32) { | |||||||||||||||||||||||||||
| 102 | 0 | my $float = $hi_limit * (2.0**32); | |||||||||||||||||||||||||||
| 103 | 0 | my $plus1 = $float+1; | |||||||||||||||||||||||||||
| 104 | 0 | my $plus2 = $float+2; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (! ($plus1 > $float && $plus1 < $plus2)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$plus1 > $float and $plus1 < $plus2
MC/DC0%0/2
$plus1 > $float and $plus1 < $plus2
$plus1 > $float
$plus1 < $plus2
Truth table0%0/3
A and B
A= $plus1 > $floatB= $plus1 < $plus2
| |||||||||||||||||||||||||||||
| 106 | 0 | last; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | $hi_limit *= 2.0; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | ### $hi_limit | ||||||||||||||||||||||||||||
| 111 | ### hex: sprintf "%X", $hi_limit | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 113 | 0 | my ($X, $data) = @_; | |||||||||||||||||||||||||||
| 114 | ### XResourceQueryClientPixmapBytes reply, 32-bit system | ||||||||||||||||||||||||||||
| 115 | 0 | my ($lo, $hi) = unpack('x8LL', $data); | |||||||||||||||||||||||||||
| 116 | ### $lo | ||||||||||||||||||||||||||||
| 117 | ### $hi | ||||||||||||||||||||||||||||
| 118 | ### hex lo: sprintf "%X", $lo | ||||||||||||||||||||||||||||
| 119 | ### hex hi: sprintf "%X", $hi | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($hi == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 121 | 0 | return $lo; | |||||||||||||||||||||||||||
| 122 | } elsif ($hi < $hi_limit) { | ||||||||||||||||||||||||||||
| 123 | 0 | return $lo + $hi * (2 ** 32); | |||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||
| 125 | 0 | require Math::BigInt; | |||||||||||||||||||||||||||
| 126 | 0 | return (Math::BigInt->new($hi) << 32) + $lo; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | } ], | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # #---------------------- | ||||||||||||||||||||||||||||
| 133 | # # protocol 1.2 | ||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||
| 135 | # # mask bits ... | ||||||||||||||||||||||||||||
| 136 | # # ClientXIDMask 0x01 | ||||||||||||||||||||||||||||
| 137 | # # LocalClientPIDMask 0x02 | ||||||||||||||||||||||||||||
| 138 | # # xid_or_pid 'None' | ||||||||||||||||||||||||||||
| 139 | # ["XResourceQueryClientIds", # 4 | ||||||||||||||||||||||||||||
| 140 | # sub { | ||||||||||||||||||||||||||||
| 141 | # my $X = shift; # ($X, $xid_or_pid, $mask, ...) | ||||||||||||||||||||||||||||
| 142 | # return pack 'L*', | ||||||||||||||||||||||||||||
| 143 | # scalar(@_)/2, # num specs | ||||||||||||||||||||||||||||
| 144 | # @_; | ||||||||||||||||||||||||||||
| 145 | # }, | ||||||||||||||||||||||||||||
| 146 | # sub { | ||||||||||||||||||||||||||||
| 147 | # my ($X, $data) = @_; | ||||||||||||||||||||||||||||
| 148 | # ### XResourceQueryClientResources reply | ||||||||||||||||||||||||||||
| 149 | # my ($num) = unpack 'x8L', $data; | ||||||||||||||||||||||||||||
| 150 | # ### $num | ||||||||||||||||||||||||||||
| 151 | # my $pos = 32; | ||||||||||||||||||||||||||||
| 152 | # my @ret; | ||||||||||||||||||||||||||||
| 153 | # # obey $num rather than the reply length | ||||||||||||||||||||||||||||
| 154 | # for (1 .. $num) { | ||||||||||||||||||||||||||||
| 155 | # my @elem = unpack 'L3', substr($data,$pos,12); | ||||||||||||||||||||||||||||
| 156 | # my ($client_xid, $mask, $length) = unpack 'L3', substr($data,$pos,12); | ||||||||||||||||||||||||||||
| 157 | # $pos += 12; | ||||||||||||||||||||||||||||
| 158 | # my $length = 4 * pop @elem; | ||||||||||||||||||||||||||||
| 159 | # push @elem, unpack 'L*', substr($data,$pos,$length); | ||||||||||||||||||||||||||||
| 160 | # $pos += $length; | ||||||||||||||||||||||||||||
| 161 | # push @ret, \@elem; | ||||||||||||||||||||||||||||
| 162 | # } | ||||||||||||||||||||||||||||
| 163 | # return @ret; | ||||||||||||||||||||||||||||
| 164 | # }], | ||||||||||||||||||||||||||||
| 165 | # | ||||||||||||||||||||||||||||
| 166 | # ["XResourceQueryResourceBytes", # 5 | ||||||||||||||||||||||||||||
| 167 | # sub { | ||||||||||||||||||||||||||||
| 168 | # my $X = shift; # ($X, $client_xid, $resource,$type, ...) | ||||||||||||||||||||||||||||
| 169 | # my $client_xid = shift; | ||||||||||||||||||||||||||||
| 170 | # return pack 'L*', | ||||||||||||||||||||||||||||
| 171 | # $client_xid, | ||||||||||||||||||||||||||||
| 172 | # scalar(@_)/2, # num specs | ||||||||||||||||||||||||||||
| 173 | # @_; | ||||||||||||||||||||||||||||
| 174 | # }, | ||||||||||||||||||||||||||||
| 175 | # sub { | ||||||||||||||||||||||||||||
| 176 | # my ($X, $data) = @_; | ||||||||||||||||||||||||||||
| 177 | # ### XResourceQueryClientResources reply | ||||||||||||||||||||||||||||
| 178 | # my ($num) = unpack 'x8L', $data; | ||||||||||||||||||||||||||||
| 179 | # ### $num | ||||||||||||||||||||||||||||
| 180 | # my $pos = 32; | ||||||||||||||||||||||||||||
| 181 | # my @ret; | ||||||||||||||||||||||||||||
| 182 | # # obey $num rather than the reply length | ||||||||||||||||||||||||||||
| 183 | # for (1 .. $num) { | ||||||||||||||||||||||||||||
| 184 | # my @elem = unpack 'L6', # $resource,$type,$bytes,$refcount,$usecount | ||||||||||||||||||||||||||||
| 185 | # substr($data,$pos,24); | ||||||||||||||||||||||||||||
| 186 | # $pos += 24; | ||||||||||||||||||||||||||||
| 187 | # my $length = 20 * pop @elem; | ||||||||||||||||||||||||||||
| 188 | # push @elem, unpack 'L*', substr($data,$pos,$length); | ||||||||||||||||||||||||||||
| 189 | # $pos += $length; | ||||||||||||||||||||||||||||
| 190 | # push @ret, \@elem; | ||||||||||||||||||||||||||||
| 191 | # } | ||||||||||||||||||||||||||||
| 192 | # return @ret; | ||||||||||||||||||||||||||||
| 193 | # }], | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | ]; | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub _request_empty { | ||||||||||||||||||||||||||
|
Subroutine
_request_empty: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | croak "No parameters in this request"; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 0 | return ''; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub _request_card32s { | ||||||||||||||||||||||||||
|
Subroutine
_request_card32s: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 204 | 0 | shift; | |||||||||||||||||||||||||||
| 205 | ### _request_card32s(): @_ | ||||||||||||||||||||||||||||
| 206 | 0 | return pack 'L*', @_; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 213 | 0 | my ($class, $X, $request_num, $event_num, $error_num) = @_; | |||||||||||||||||||||||||||
| 214 | ### X_Resource new() | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | $X->{'ext_request'}{$request_num} = $reqs; | |||||||||||||||||||||||||||
| 217 | 0 | _ext_request_num_fill ($X, $request_num, $reqs); | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | # Any need to query/negotiate the protocol version first? | ||||||||||||||||||||||||||||
| 220 | # Xlib XRes.c doesn't seem to. | ||||||||||||||||||||||||||||
| 221 | # my ($server_major, $server_minor) = $X->req('XResourceQueryVersion', | ||||||||||||||||||||||||||||
| 222 | # CLIENT_MAJOR_VERSION, | ||||||||||||||||||||||||||||
| 223 | # CLIENT_MINOR_VERSION); | ||||||||||||||||||||||||||||
| 224 | 0 | return bless { | |||||||||||||||||||||||||||
| 225 | # major => $server_major, | ||||||||||||||||||||||||||||
| 226 | # minor => $server_minor, | ||||||||||||||||||||||||||||
| 227 | }, $class; | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub _ext_request_num_fill { | ||||||||||||||||||||||||||
|
Subroutine
_ext_request_num_fill: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 231 | 0 | my ($X, $request_num, $reqs) = @_; | |||||||||||||||||||||||||||
| 232 | 0 | my $i; | |||||||||||||||||||||||||||
| 233 | 0 | foreach $i (0 .. $#$reqs) { | |||||||||||||||||||||||||||
| 234 | 0 | $X->{'ext_request_num'}{$reqs->[$i]->[0]} = [$request_num, $i]; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 1 | 1; | |||||||||||||||||||||||||||
| 239 | __END__ | ||||||||||||||||||||||||||||