line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 . |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
380
|
BEGIN { require 5 } |
19
|
|
|
|
|
|
|
package X11::Protocol::Ext::X_Resource; |
20
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
21
|
1
|
|
|
1
|
|
2
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
4
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
54
|
|
24
|
|
|
|
|
|
|
$VERSION = 30; |
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
|
|
|
1
|
|
4
|
use constant CLIENT_MAJOR_VERSION => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
44
|
1
|
|
|
1
|
|
3
|
use constant CLIENT_MINOR_VERSION => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
492
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $reqs = |
49
|
|
|
|
|
|
|
[ |
50
|
|
|
|
|
|
|
["XResourceQueryVersion", # 0 |
51
|
|
|
|
|
|
|
sub { |
52
|
|
|
|
|
|
|
### XResourceQueryVersion request |
53
|
|
|
|
|
|
|
shift; # $X |
54
|
|
|
|
|
|
|
return pack 'CCxx', @_; # ($client_major, $client_minor) |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
sub { |
57
|
|
|
|
|
|
|
my ($X, $data) = @_; |
58
|
|
|
|
|
|
|
return unpack 'x8SS', $data; # ($server_major, $server_minor) |
59
|
|
|
|
|
|
|
}], |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
["XResourceQueryClients", # 1 |
62
|
|
|
|
|
|
|
\&_request_empty, |
63
|
|
|
|
|
|
|
sub { |
64
|
|
|
|
|
|
|
my ($X, $data) = @_; |
65
|
|
|
|
|
|
|
### XResourceQueryClients reply |
66
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return map {[ unpack 'LL', substr($data,32+$_*8,8) ]} 0 .. $num-1; |
71
|
|
|
|
|
|
|
} ], |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
["XResourceQueryClientResources", # 2 |
74
|
|
|
|
|
|
|
\&_request_card32s, # ($X, $client_xid) |
75
|
|
|
|
|
|
|
sub { |
76
|
|
|
|
|
|
|
my ($X, $data) = @_; |
77
|
|
|
|
|
|
|
### XResourceQueryClientResources reply |
78
|
|
|
|
|
|
|
my ($num) = unpack 'x8L', $data; |
79
|
|
|
|
|
|
|
### $num |
80
|
|
|
|
|
|
|
# obey $num rather than the reply length |
81
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $v = ((0xFFFFFFFF * (2.0**32)) + 0xFFFFFFFF); |
89
|
|
|
|
|
|
|
($v == sprintf("%u",$v)) |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
? sub { |
92
|
|
|
|
|
|
|
my ($X, $data) = @_; |
93
|
|
|
|
|
|
|
### XResourceQueryClientPixmapBytes reply, 64-bit system |
94
|
|
|
|
|
|
|
my ($lo, $hi) = unpack('x8LL', $data); |
95
|
|
|
|
|
|
|
return $lo + ($hi << 32); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
: do { |
98
|
|
|
|
|
|
|
# probe for where floating point loses precision |
99
|
|
|
|
|
|
|
# if $hi<$hi_limit then $hi*2**32 + $lo is exact |
100
|
|
|
|
|
|
|
my $hi_limit = 1; |
101
|
|
|
|
|
|
|
foreach (1 .. 32) { |
102
|
|
|
|
|
|
|
my $float = $hi_limit * (2.0**32); |
103
|
|
|
|
|
|
|
my $plus1 = $float+1; |
104
|
|
|
|
|
|
|
my $plus2 = $float+2; |
105
|
|
|
|
|
|
|
if (! ($plus1 > $float && $plus1 < $plus2)) { |
106
|
|
|
|
|
|
|
last; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
$hi_limit *= 2.0; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
### $hi_limit |
111
|
|
|
|
|
|
|
### hex: sprintf "%X", $hi_limit |
112
|
|
|
|
|
|
|
sub { |
113
|
|
|
|
|
|
|
my ($X, $data) = @_; |
114
|
|
|
|
|
|
|
### XResourceQueryClientPixmapBytes reply, 32-bit system |
115
|
|
|
|
|
|
|
my ($lo, $hi) = unpack('x8LL', $data); |
116
|
|
|
|
|
|
|
### $lo |
117
|
|
|
|
|
|
|
### $hi |
118
|
|
|
|
|
|
|
### hex lo: sprintf "%X", $lo |
119
|
|
|
|
|
|
|
### hex hi: sprintf "%X", $hi |
120
|
|
|
|
|
|
|
if ($hi == 0) { |
121
|
|
|
|
|
|
|
return $lo; |
122
|
|
|
|
|
|
|
} elsif ($hi < $hi_limit) { |
123
|
|
|
|
|
|
|
return $lo + $hi * (2 ** 32); |
124
|
|
|
|
|
|
|
} else { |
125
|
|
|
|
|
|
|
require Math::BigInt; |
126
|
|
|
|
|
|
|
return (Math::BigInt->new($hi) << 32) + $lo; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} ], |
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
|
|
|
|
|
|
|
sub _request_empty { |
198
|
0
|
0
|
|
0
|
|
|
if (@_ > 1) { |
199
|
0
|
|
|
|
|
|
croak "No parameters in this request"; |
200
|
|
|
|
|
|
|
} |
201
|
0
|
|
|
|
|
|
return ''; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
sub _request_card32s { |
204
|
0
|
|
|
0
|
|
|
shift; |
205
|
|
|
|
|
|
|
### _request_card32s(): @_ |
206
|
0
|
|
|
|
|
|
return pack 'L*', @_; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub new { |
213
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub _ext_request_num_fill { |
231
|
0
|
|
|
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; |
239
|
|
|
|
|
|
|
__END__ |