| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2017, 2019 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 modify | ||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||
| 8 | # version. | ||||||||||||
| 9 | # | ||||||||||||
| 10 | # X11-Protocol-Other is distributed in the hope that it will be useful, but | ||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||
| 13 | # 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 | package X11::Protocol::Other; | ||||||||||||
| 19 | 7 | ▶ | use 5.004; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 7 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 7 | ▶ | use X11::AtomConstants; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | 7 | ▶ | use vars '$VERSION', '@ISA', '@EXPORT_OK'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 7 | $VERSION = 31; | |||||||||||
| 26 | |||||||||||||
| 27 | 7 | ▶ | use Exporter; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 7 | @ISA = ('Exporter'); | |||||||||||
| 29 | 7 | @EXPORT_OK = qw(root_to_screen | |||||||||||
| 30 | root_to_screen_info | ||||||||||||
| 31 | default_colormap_to_screen | ||||||||||||
| 32 | default_colormap_to_screen_info | ||||||||||||
| 33 | visual_is_dynamic | ||||||||||||
| 34 | visual_class_is_dynamic | ||||||||||||
| 35 | window_size | ||||||||||||
| 36 | window_visual | ||||||||||||
| 37 | get_property_atoms | ||||||||||||
| 38 | hexstr_to_rgb | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | |||||||||||||
| 41 | # uncomment this to run the ### lines | ||||||||||||
| 42 | #use Smart::Comments; | ||||||||||||
| 43 | |||||||||||||
| 44 | 0 | ▶ | sub window_size { | ||||||||||
|
Subroutine
window_size: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 45 | 0 | my ($X, $window) = @_; | |||||||||||
| 46 | ### Other window_size(): "$X $window" | ||||||||||||
| 47 | 0 | my $screen_info; | |||||||||||
| 48 | 0 | ▶ | if ($screen_info = root_to_screen_info($X,$window)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | return ($screen_info->{'width_in_pixels'}, | ||||||||||||
| 50 | 0 | $screen_info->{'height_in_pixels'}); | |||||||||||
| 51 | } | ||||||||||||
| 52 | 0 | my %geom = $X->GetGeometry ($window); | |||||||||||
| 53 | 0 | return ($geom{'width'}, $geom{'height'}); | |||||||||||
| 54 | } | ||||||||||||
| 55 | 0 | ▶ | sub window_visual { | ||||||||||
|
Subroutine
window_visual: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 56 | 0 | my ($X, $window) = @_; | |||||||||||
| 57 | ### Other window_visual(): "$X $window" | ||||||||||||
| 58 | 0 | my $screen_info; | |||||||||||
| 59 | 0 | ▶ | if ($screen_info = root_to_screen_info($X,$window)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | return $screen_info->{'root_visual'}; | |||||||||||
| 61 | } | ||||||||||||
| 62 | 0 | my %attr = $X->GetWindowAttributes ($window); | |||||||||||
| 63 | 0 | return $attr{'visual'}; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | #------------------------------------------------------------------------------ | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub root_to_screen { | ||||||||||
|
Subroutine
root_to_screen: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 69 | 0 | my ($X, $root) = @_; | |||||||||||
| 70 | ### Other root_to_screen(): $root | ||||||||||||
| 71 | return ($X->{__PACKAGE__.'.root_to_screen_number'} | ||||||||||||
| 72 | 0 | ||= { map {($X->{'screens'}->[$_]->{'root'} => $_)} | |||||||||||
| 73 | 0 | 0 .. $#{$X->{'screens'}} }) | |||||||||||
| 74 | 0 | ▶ | ->{$root}; | ||||||||||
|
Condition0%0/2
$X->{"X11::Protocol::Other.root_to_screen_number"} ||= {map({$X->{"screens"}[$_]{"root"}, $_;} 0 .. $#{$$X{"screens"};})}
MC/DC0%0/1
$X->{"X11::Protocol::Other.root_to_screen_number"} ||= {map({$X->{"screens"}[$_]{"root"}, $_;} 0 .. $#{$$X{"screens"};})}
$X->{"X11::Protocol::Other.root_to_screen_number"}
Truth table0%0/2
A
A= $X->{"X11::Protocol::Other.root_to_screen_number"}
| |||||||||||||
| 75 | } | ||||||||||||
| 76 | 0 | ▶ | sub root_to_screen_info { | ||||||||||
|
Subroutine
root_to_screen_info: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 77 | 0 | my ($X, $root) = @_; | |||||||||||
| 78 | ### Other root_to_screen_info(): $root | ||||||||||||
| 79 | 0 | my $ret; | |||||||||||
| 80 | 0 | ▶ | if (defined ($ret = root_to_screen($X,$root))) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 0 | $ret = $X->{'screens'}->[$ret]; | |||||||||||
| 82 | } | ||||||||||||
| 83 | 0 | return $ret; | |||||||||||
| 84 | |||||||||||||
| 85 | # return ($X->{__PACKAGE__.'.root_to_screen_info'} | ||||||||||||
| 86 | # ||= { map {($_->{'root'} => $_)} @{$X->{'screens'}} })->{$root} | ||||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | #------------------------------------------------------------------------------ | ||||||||||||
| 90 | |||||||||||||
| 91 | 0 | ▶ | sub default_colormap_to_screen { | ||||||||||
|
Subroutine
default_colormap_to_screen: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 92 | 0 | my ($X, $colormap) = @_; | |||||||||||
| 93 | ### default_colormap_to_screen(): $colormap | ||||||||||||
| 94 | return ($X->{__PACKAGE__.'.default_colormap_to_screen_number'} | ||||||||||||
| 95 | 0 | ||= { map {($X->{'screens'}->[$_]->{'default_colormap'} => $_)} | |||||||||||
| 96 | 0 | 0 .. $#{$X->{'screens'}} }) | |||||||||||
| 97 | 0 | ▶ | ->{$colormap}; | ||||||||||
|
Condition0%0/2
$X->{"X11::Protocol::Other.default_colormap_to_screen_number"} ||= {map({$X->{"screens"}[$_]{"default_colormap"}, $_;} 0 .. $#{$$X{"screens"};})}
MC/DC0%0/1
$X->{"X11::Protocol::Other.default_colormap_to_screen_number"} ||= {map({$X->{"screens"}[$_]{"default_colormap"}, $_;} 0 .. $#{$$X{"screens"};})}
$X->{"X11::Protocol::Other.default_colormap_to_screen_number"}
Truth table0%0/2
A
A= $X->{"X11::Protocol::Other.default_colormap_to_screen_number"}
| |||||||||||||
| 98 | } | ||||||||||||
| 99 | 0 | ▶ | sub default_colormap_to_screen_info { | ||||||||||
|
Subroutine
default_colormap_to_screen_info: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 100 | 0 | my ($X, $colormap) = @_; | |||||||||||
| 101 | ### Other colormap_to_screen_info(): $colormap | ||||||||||||
| 102 | 0 | my $ret; | |||||||||||
| 103 | 0 | ▶ | if (defined ($ret = default_colormap_to_screen($X,$colormap))) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | 0 | $ret = $X->{'screens'}->[$ret]; | |||||||||||
| 105 | } | ||||||||||||
| 106 | 0 | return $ret; | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | # # return true if $colormap is one of the screen default colormaps | ||||||||||||
| 110 | # sub colormap_is_default { | ||||||||||||
| 111 | # my ($X, $colormap) = @_; | ||||||||||||
| 112 | # return defined (default_colormap_to_screen($X,$colormap)); | ||||||||||||
| 113 | # } | ||||||||||||
| 114 | |||||||||||||
| 115 | |||||||||||||
| 116 | #------------------------------------------------------------------------------ | ||||||||||||
| 117 | # my %visual_class_is_dynamic = (StaticGray => 0, 0 => 0, | ||||||||||||
| 118 | # GrayScale => 1, 1 => 1, | ||||||||||||
| 119 | # StaticColor => 0, 2 => 0, | ||||||||||||
| 120 | # PseudoColor => 1, 3 => 1, | ||||||||||||
| 121 | # TrueColor => 0, 4 => 0, | ||||||||||||
| 122 | # DirectColor => 1, 5 => 1, | ||||||||||||
| 123 | # ); | ||||||||||||
| 124 | 0 | ▶ | sub visual_class_is_dynamic { | ||||||||||
|
Subroutine
visual_class_is_dynamic: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 125 | 0 | my ($X, $visual_class) = @_; | |||||||||||
| 126 | 0 | return $X->num('VisualClass',$visual_class) & 1; | |||||||||||
| 127 | } | ||||||||||||
| 128 | 0 | ▶ | sub visual_is_dynamic { | ||||||||||
|
Subroutine
visual_is_dynamic: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 129 | 0 | my ($X, $visual_id) = @_; | |||||||||||
| 130 | 0 | ▶ | my $visual_info = $X->{'visuals'}->{$visual_id} | ||||||||||
|
Condition0%0/2
$X->{'visuals'}{$visual_id} || croak('Unknown visual ', $visual_id)
MC/DC0%0/1
$X->{'visuals'}{$visual_id} || croak('Unknown visual ', $visual_id)
$X->{'visuals'}{$visual_id}
Truth table0%0/2
A
A= $X->{'visuals'}{$visual_id}
| |||||||||||||
| 131 | || croak 'Unknown visual ',$visual_id; | ||||||||||||
| 132 | 0 | return visual_class_is_dynamic ($X, $visual_info->{'class'}); | |||||||||||
| 133 | } | ||||||||||||
| 134 | |||||||||||||
| 135 | #------------------------------------------------------------------------------ | ||||||||||||
| 136 | |||||||||||||
| 137 | # cf XcmsLRGB_RGB_ParseString() in XcmsLRGB.c | ||||||||||||
| 138 | |||||||||||||
| 139 | 0 | ▶ | sub hexstr_to_rgb { | ||||||||||
|
Subroutine
hexstr_to_rgb: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 140 | 0 | my ($str) = @_; | |||||||||||
| 141 | ### hexstr_to_rgb(): $str | ||||||||||||
| 142 | # Crib: [:xdigit:] is new in 5.6, so only 0-9A-F | ||||||||||||
| 143 | 0 | ▶ | $str =~ /^#(([0-9A-F]{3}){1,4})$/i or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 144 | 0 | my $len = length($1)/3; # of each group, so 1,2,3 or 4 | |||||||||||
| 145 | 0 | return (map {hex(substr($_ x 4, 0, 4))} # first 4 chars of replicated | |||||||||||
| 146 | substr ($str, 1, $len), # full groups | ||||||||||||
| 147 | substr ($str, 1+$len, $len), | ||||||||||||
| 148 | substr ($str, -$len)); | ||||||||||||
| 149 | } | ||||||||||||
| 150 | |||||||||||||
| 151 | # my %hex_factor = (1 => 0x1111, | ||||||||||||
| 152 | # 2 => 0x101, | ||||||||||||
| 153 | # 3 => 0x10 + 1/0x100, | ||||||||||||
| 154 | # 4 => 1); | ||||||||||||
| 155 | # my $factor = $hex_factor{$len} || return; | ||||||||||||
| 156 | # ### $len | ||||||||||||
| 157 | # ### $factor | ||||||||||||
| 158 | |||||||||||||
| 159 | |||||||||||||
| 160 | #------------------------------------------------------------------------------ | ||||||||||||
| 161 | |||||||||||||
| 162 | 0 | ▶ | sub get_property_atoms { | ||||||||||
|
Subroutine
get_property_atoms: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 163 | 0 | my ($X, $window, $property) = @_; | |||||||||||
| 164 | 0 | (my $value, | |||||||||||
| 165 | undef, # type | ||||||||||||
| 166 | my $format, | ||||||||||||
| 167 | my $bytes_after) | ||||||||||||
| 168 | = $X->GetProperty ($window, $property, | ||||||||||||
| 169 | X11::AtomConstants::ATOM(), # type | ||||||||||||
| 170 | 0, # offset | ||||||||||||
| 171 | 0x7FFFFFFF, # long-length: CARD32, unlimited | ||||||||||||
| 172 | 0); # delete | ||||||||||||
| 173 | ### $value | ||||||||||||
| 174 | ### $format | ||||||||||||
| 175 | 0 | ▶ | $format == 32 or return; # not atoms | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 176 | 0 | ▶ | if ($bytes_after) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | 0 | croak "oops, extremely long property, has $bytes_after more"; | |||||||||||
| 178 | } | ||||||||||||
| 179 | 0 | return unpack('L*', $value); | |||||||||||
| 180 | } | ||||||||||||
| 181 | |||||||||||||
| 182 | 0 | ▶ | sub set_property_atoms { | ||||||||||
|
Subroutine
set_property_atoms: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 183 | 0 | my $X = shift; | |||||||||||
| 184 | 0 | my $window = shift; | |||||||||||
| 185 | 0 | my $property = shift; | |||||||||||
| 186 | 0 | $X->ChangeProperty($window, | |||||||||||
| 187 | $property, # property | ||||||||||||
| 188 | X11::AtomConstants::ATOM(), # type | ||||||||||||
| 189 | 32, # format | ||||||||||||
| 190 | 'Replace', | ||||||||||||
| 191 | pack('L*',@_)); | ||||||||||||
| 192 | } | ||||||||||||
| 193 | |||||||||||||
| 194 | # sub set_property_atom_names { | ||||||||||||
| 195 | # my ($X, $window, $property, @atoms) = @_; | ||||||||||||
| 196 | # # ENHANCE-ME: might like to intern all atoms in one round-trip, or perhaps | ||||||||||||
| 197 | # # that's better left to a single big pre-fill of atoms in mainline code | ||||||||||||
| 198 | # set_property_atoms($X,$window,$property, | ||||||||||||
| 199 | # map {$X->atom($_)} @atoms); | ||||||||||||
| 200 | # } | ||||||||||||
| 201 | |||||||||||||
| 202 | |||||||||||||
| 203 | #------------------------------------------------------------------------------ | ||||||||||||
| 204 | |||||||||||||
| 205 | # # return true if $pixel is black or white in the default root window colormap | ||||||||||||
| 206 | # sub pixel_is_black_or_white { | ||||||||||||
| 207 | # my ($X, $pixel) = @_; | ||||||||||||
| 208 | # return ($pixel == $X->{'black_pixel'} || $pixel == $X->{'white_pixel'}); | ||||||||||||
| 209 | # } | ||||||||||||
| 210 | # | ||||||||||||
| 211 | |||||||||||||
| 212 | 7 | 1; | |||||||||||
| 213 | __END__ | ||||||||||||