/usr/share/perl5/X11/Protocol/Other.pm is in libx11-protocol-other-perl 28-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | # Copyright 2010, 2011, 2012, 2013 Kevin Ryde
# This file is part of X11-Protocol-Other.
#
# X11-Protocol-Other is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# X11-Protocol-Other is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
package X11::Protocol::Other;
use 5.004;
use strict;
use Carp;
use vars '$VERSION', '@ISA', '@EXPORT_OK';
$VERSION = 28;
use Exporter;
@ISA = ('Exporter');
@EXPORT_OK = qw(root_to_screen
root_to_screen_info
default_colormap_to_screen
default_colormap_to_screen_info
visual_is_dynamic
visual_class_is_dynamic
window_size
window_visual
hexstr_to_rgb
);
# uncomment this to run the ### lines
#use Smart::Comments;
sub window_size {
my ($X, $window) = @_;
### Other window_size(): "$X $window"
my $screen_info;
if ($screen_info = root_to_screen_info($X,$window)) {
return ($screen_info->{'width_in_pixels'},
$screen_info->{'height_in_pixels'});
}
my %geom = $X->GetGeometry ($window);
return ($geom{'width'}, $geom{'height'});
}
sub window_visual {
my ($X, $window) = @_;
### Other window_visual(): "$X $window"
my $screen_info;
if ($screen_info = root_to_screen_info($X,$window)) {
return $screen_info->{'root_visual'};
}
my %attr = $X->GetWindowAttributes ($window);
return $attr{'visual'};
}
#------------------------------------------------------------------------------
sub root_to_screen {
my ($X, $root) = @_;
### Other root_to_screen(): $root
return ($X->{__PACKAGE__.'.root_to_screen_number'}
||= { map {($X->{'screens'}->[$_]->{'root'} => $_)}
0 .. $#{$X->{'screens'}} })
->{$root};
}
sub root_to_screen_info {
my ($X, $root) = @_;
### Other root_to_screen_info(): $root
my $ret;
if (defined ($ret = root_to_screen($X,$root))) {
$ret = $X->{'screens'}->[$ret];
}
return $ret;
# return ($X->{__PACKAGE__.'.root_to_screen_info'}
# ||= { map {($_->{'root'} => $_)} @{$X->{'screens'}} })->{$root}
}
#------------------------------------------------------------------------------
sub default_colormap_to_screen {
my ($X, $colormap) = @_;
### default_colormap_to_screen(): $colormap
return ($X->{__PACKAGE__.'.default_colormap_to_screen_number'}
||= { map {($X->{'screens'}->[$_]->{'default_colormap'} => $_)}
0 .. $#{$X->{'screens'}} })
->{$colormap};
}
sub default_colormap_to_screen_info {
my ($X, $colormap) = @_;
### Other colormap_to_screen_info(): $colormap
my $ret;
if (defined ($ret = default_colormap_to_screen($X,$colormap))) {
$ret = $X->{'screens'}->[$ret];
}
return $ret;
}
# # return true if $colormap is one of the screen default colormaps
# sub colormap_is_default {
# my ($X, $colormap) = @_;
# return defined (default_colormap_to_screen($X,$colormap));
# }
#------------------------------------------------------------------------------
# my %visual_class_is_dynamic = (StaticGray => 0, 0 => 0,
# GrayScale => 1, 1 => 1,
# StaticColor => 0, 2 => 0,
# PseudoColor => 1, 3 => 1,
# TrueColor => 0, 4 => 0,
# DirectColor => 1, 5 => 1,
# );
sub visual_class_is_dynamic {
my ($X, $visual_class) = @_;
return $X->num('VisualClass',$visual_class) & 1;
}
sub visual_is_dynamic {
my ($X, $visual_id) = @_;
my $visual_info = $X->{'visuals'}->{$visual_id}
|| croak 'Unknown visual ',$visual_id;
return visual_class_is_dynamic ($X, $visual_info->{'class'});
}
#------------------------------------------------------------------------------
# cf XcmsLRGB_RGB_ParseString() in XcmsLRGB.c
sub hexstr_to_rgb {
my ($str) = @_;
### hexstr_to_rgb(): $str
# Crib: [:xdigit:] is new in 5.6, so only 0-9A-F
$str =~ /^#(([0-9A-F]{3}){1,4})$/i or return;
my $len = length($1)/3; # of each group, so 1,2,3 or 4
return (map {hex(substr($_ x 4, 0, 4))} # first 4 chars of replicated
substr ($str, 1, $len), # full groups
substr ($str, 1+$len, $len),
substr ($str, -$len));
}
# my %hex_factor = (1 => 0x1111,
# 2 => 0x101,
# 3 => 0x10 + 1/0x100,
# 4 => 1);
# my $factor = $hex_factor{$len} || return;
# ### $len
# ### $factor
#------------------------------------------------------------------------------
# # return true if $pixel is black or white in the default root window colormap
# sub pixel_is_black_or_white {
# my ($X, $pixel) = @_;
# return ($pixel == $X->{'black_pixel'} || $pixel == $X->{'white_pixel'});
# }
#
1;
__END__
=for stopwords Ryde XID colormap colormaps ie PseudoColor VisualClass RGB rgb 0xFFFF FFF FFFF Xcms recognised unrecognised recognising
=head1 NAME
X11::Protocol::Other -- miscellaneous X11::Protocol helpers
=head1 SYNOPSIS
use X11::Protocol::Other;
=head1 DESCRIPTION
This is some helper functions for C<X11::Protocol>.
=head1 EXPORTS
Nothing is exported by default, but the functions can be requested in usual
C<Exporter> style,
use X11::Protocol::Other 'visual_is_dynamic';
if (visual_is_dynamic ($X, $visual_id)) {
...
}
Or just called with full package name
use X11::Protocol::Other;
if (X11::Protocol::Other::visual_is_dynamic ($X, $visual_id)) {
...
}
There's no C<:all> tag since this module is meant as a grab-bag of functions
and to import as-yet unknown things would be asking for name clashes.
=head1 FUNCTIONS
=head2 Screen Finding
=over 4
=item C<$number = root_to_screen ($X, $root)>
=item C<$hashref = root_to_screen_info ($X, $root)>
Return the screen number or screen info hash for a given root window.
C<$root> can be any XID integer on C<$X>. If it's not one of the root
windows then the return is C<undef>.
=item C<$number = default_colormap_to_screen ($X, $colormap)>
=item C<$hashref = default_colormap_to_screen_info ($X, $colormap)>
Return the screen number or screen info hash for a given default colormap.
C<$colormap> can be any XID integer on C<$X>. If it's not one of the screen
default colormaps then the return is C<undef>.
=back
=head2 Visuals
=over
=item C<$bool = visual_is_dynamic ($X, $visual_id)>
=item C<$bool = visual_class_is_dynamic ($X, $visual_class)>
Return true if the given visual is dynamic, meaning colormap entries on it
can be changed to change the colour of a given pixel value.
C<$visual_id> is one of the visual ID numbers, ie. one of the keys in
C<$X-E<gt>{'visuals'}>. Or C<$visual_class> is a VisualClass string like
"PseudoColor" or corresponding integer such as 3.
=back
=head2 Window Info
=over
=item C<($width, $height) = window_size ($X, $window)>
=item C<$visual_id = window_visual ($X, $window)>
Return the size or visual ID of a given window.
C<$window> is an integer XID on C<$X>. If it's one of the root windows then
the return values are from the screen info hash in C<$X>, otherwise the
server is queried with C<GetGeometry()> (for the size) or
C<GetWindowAttributes()> (for the visual).
These functions are handy when there's a good chance C<$window> might be a
root window and therefore not need a server round trip.
=back
=head2 Colour Parsing
=over
=item C<($red16, $green16, $blue16) = hexstr_to_rgb($str)>
Parse a given RGB colour string like "#FF00FF" into 16-bit red, green, blue
components. The return values are always in the range 0 to 65535. The
strings recognised are 1, 2, 3 or 4 digit hex.
#RGB
#RRGGBB
#RRRGGGBBB
#RRRRGGGGBBBB
If C<$str> is unrecognised then the return is an empty list, so for instance
my @rgb = hexstr_to_rgb($str)
or die "Unrecognised colour: $str";
The digits of the 1, 2 and 3 forms are replicated as necessary to give a
16-bit range. For example 3-digit style "#321FFF000" gives return values
0x3213, 0xFFFF, 0. Or 1-digit "#F0F" is 0xFFFF, 0, 0xFFFF. Notice "F"
expands to 0xFFFF so an "F", "FF" or "FFF" all mean full saturation the same
as a 4-digit "FFFF".
Would it be worth recognising the Xcms style "rgb:RR/GG/BB"? Perhaps that's
best left to full Xcms, or general colour conversion modules. The X11R6
X(7) man page describes the "rgb:" form, but just "#" is much more common.
=back
=head1 SEE ALSO
L<X11::Protocol>,
L<X11::Protocol::GrabServer>
L<Color::Library> (many named colours), L<Convert::Color>,
L<Graphics::Color> (Moose based) for more colour parsing
L<X11::AtomConstants>,
L<X11::CursorFont>
=head1 HOME PAGE
L<http://user42.tuxfamily.org/x11-protocol-other/index.html>
=head1 LICENSE
Copyright 2010, 2011, 2012, 2013 Kevin Ryde
X11-Protocol-Other is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
X11-Protocol-Other is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
=cut
|