| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2010, 2011, 2012, 2013 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 . |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package X11::Protocol::Other; |
|
19
|
3
|
|
|
3
|
|
18075
|
use 5.004; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
118
|
|
|
20
|
3
|
|
|
3
|
|
17
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
98
|
|
|
21
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
231
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
14
|
use vars '$VERSION', '@ISA', '@EXPORT_OK'; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
209
|
|
|
24
|
|
|
|
|
|
|
$VERSION = 29; |
|
25
|
|
|
|
|
|
|
|
|
26
|
3
|
|
|
3
|
|
14
|
use Exporter; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
2459
|
|
|
27
|
|
|
|
|
|
|
@ISA = ('Exporter'); |
|
28
|
|
|
|
|
|
|
@EXPORT_OK = qw(root_to_screen |
|
29
|
|
|
|
|
|
|
root_to_screen_info |
|
30
|
|
|
|
|
|
|
default_colormap_to_screen |
|
31
|
|
|
|
|
|
|
default_colormap_to_screen_info |
|
32
|
|
|
|
|
|
|
visual_is_dynamic |
|
33
|
|
|
|
|
|
|
visual_class_is_dynamic |
|
34
|
|
|
|
|
|
|
window_size |
|
35
|
|
|
|
|
|
|
window_visual |
|
36
|
|
|
|
|
|
|
hexstr_to_rgb |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
|
40
|
|
|
|
|
|
|
#use Smart::Comments; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub window_size { |
|
43
|
0
|
|
|
0
|
1
|
|
my ($X, $window) = @_; |
|
44
|
|
|
|
|
|
|
### Other window_size(): "$X $window" |
|
45
|
0
|
|
|
|
|
|
my $screen_info; |
|
46
|
0
|
0
|
|
|
|
|
if ($screen_info = root_to_screen_info($X,$window)) { |
|
47
|
0
|
|
|
|
|
|
return ($screen_info->{'width_in_pixels'}, |
|
48
|
|
|
|
|
|
|
$screen_info->{'height_in_pixels'}); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
0
|
|
|
|
|
|
my %geom = $X->GetGeometry ($window); |
|
51
|
0
|
|
|
|
|
|
return ($geom{'width'}, $geom{'height'}); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
sub window_visual { |
|
54
|
0
|
|
|
0
|
1
|
|
my ($X, $window) = @_; |
|
55
|
|
|
|
|
|
|
### Other window_visual(): "$X $window" |
|
56
|
0
|
|
|
|
|
|
my $screen_info; |
|
57
|
0
|
0
|
|
|
|
|
if ($screen_info = root_to_screen_info($X,$window)) { |
|
58
|
0
|
|
|
|
|
|
return $screen_info->{'root_visual'}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
|
my %attr = $X->GetWindowAttributes ($window); |
|
61
|
0
|
|
|
|
|
|
return $attr{'visual'}; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub root_to_screen { |
|
67
|
0
|
|
|
0
|
1
|
|
my ($X, $root) = @_; |
|
68
|
|
|
|
|
|
|
### Other root_to_screen(): $root |
|
69
|
0
|
|
|
|
|
|
return ($X->{__PACKAGE__.'.root_to_screen_number'} |
|
70
|
0
|
|
|
|
|
|
||= { map {($X->{'screens'}->[$_]->{'root'} => $_)} |
|
71
|
0
|
|
0
|
|
|
|
0 .. $#{$X->{'screens'}} }) |
|
72
|
|
|
|
|
|
|
->{$root}; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
sub root_to_screen_info { |
|
75
|
0
|
|
|
0
|
1
|
|
my ($X, $root) = @_; |
|
76
|
|
|
|
|
|
|
### Other root_to_screen_info(): $root |
|
77
|
0
|
|
|
|
|
|
my $ret; |
|
78
|
0
|
0
|
|
|
|
|
if (defined ($ret = root_to_screen($X,$root))) { |
|
79
|
0
|
|
|
|
|
|
$ret = $X->{'screens'}->[$ret]; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
|
|
|
|
|
return $ret; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# return ($X->{__PACKAGE__.'.root_to_screen_info'} |
|
84
|
|
|
|
|
|
|
# ||= { map {($_->{'root'} => $_)} @{$X->{'screens'}} })->{$root} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub default_colormap_to_screen { |
|
90
|
0
|
|
|
0
|
1
|
|
my ($X, $colormap) = @_; |
|
91
|
|
|
|
|
|
|
### default_colormap_to_screen(): $colormap |
|
92
|
0
|
|
|
|
|
|
return ($X->{__PACKAGE__.'.default_colormap_to_screen_number'} |
|
93
|
0
|
|
|
|
|
|
||= { map {($X->{'screens'}->[$_]->{'default_colormap'} => $_)} |
|
94
|
0
|
|
0
|
|
|
|
0 .. $#{$X->{'screens'}} }) |
|
95
|
|
|
|
|
|
|
->{$colormap}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
sub default_colormap_to_screen_info { |
|
98
|
0
|
|
|
0
|
1
|
|
my ($X, $colormap) = @_; |
|
99
|
|
|
|
|
|
|
### Other colormap_to_screen_info(): $colormap |
|
100
|
0
|
|
|
|
|
|
my $ret; |
|
101
|
0
|
0
|
|
|
|
|
if (defined ($ret = default_colormap_to_screen($X,$colormap))) { |
|
102
|
0
|
|
|
|
|
|
$ret = $X->{'screens'}->[$ret]; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
0
|
|
|
|
|
|
return $ret; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# # return true if $colormap is one of the screen default colormaps |
|
108
|
|
|
|
|
|
|
# sub colormap_is_default { |
|
109
|
|
|
|
|
|
|
# my ($X, $colormap) = @_; |
|
110
|
|
|
|
|
|
|
# return defined (default_colormap_to_screen($X,$colormap)); |
|
111
|
|
|
|
|
|
|
# } |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
115
|
|
|
|
|
|
|
# my %visual_class_is_dynamic = (StaticGray => 0, 0 => 0, |
|
116
|
|
|
|
|
|
|
# GrayScale => 1, 1 => 1, |
|
117
|
|
|
|
|
|
|
# StaticColor => 0, 2 => 0, |
|
118
|
|
|
|
|
|
|
# PseudoColor => 1, 3 => 1, |
|
119
|
|
|
|
|
|
|
# TrueColor => 0, 4 => 0, |
|
120
|
|
|
|
|
|
|
# DirectColor => 1, 5 => 1, |
|
121
|
|
|
|
|
|
|
# ); |
|
122
|
|
|
|
|
|
|
sub visual_class_is_dynamic { |
|
123
|
0
|
|
|
0
|
1
|
|
my ($X, $visual_class) = @_; |
|
124
|
0
|
|
|
|
|
|
return $X->num('VisualClass',$visual_class) & 1; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
sub visual_is_dynamic { |
|
127
|
0
|
|
|
0
|
1
|
|
my ($X, $visual_id) = @_; |
|
128
|
0
|
|
0
|
|
|
|
my $visual_info = $X->{'visuals'}->{$visual_id} |
|
129
|
|
|
|
|
|
|
|| croak 'Unknown visual ',$visual_id; |
|
130
|
0
|
|
|
|
|
|
return visual_class_is_dynamic ($X, $visual_info->{'class'}); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# cf XcmsLRGB_RGB_ParseString() in XcmsLRGB.c |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub hexstr_to_rgb { |
|
138
|
0
|
|
|
0
|
1
|
|
my ($str) = @_; |
|
139
|
|
|
|
|
|
|
### hexstr_to_rgb(): $str |
|
140
|
|
|
|
|
|
|
# Crib: [:xdigit:] is new in 5.6, so only 0-9A-F |
|
141
|
0
|
0
|
|
|
|
|
$str =~ /^#(([0-9A-F]{3}){1,4})$/i or return; |
|
142
|
0
|
|
|
|
|
|
my $len = length($1)/3; # of each group, so 1,2,3 or 4 |
|
143
|
0
|
|
|
|
|
|
return (map {hex(substr($_ x 4, 0, 4))} # first 4 chars of replicated |
|
|
0
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
substr ($str, 1, $len), # full groups |
|
145
|
|
|
|
|
|
|
substr ($str, 1+$len, $len), |
|
146
|
|
|
|
|
|
|
substr ($str, -$len)); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# my %hex_factor = (1 => 0x1111, |
|
150
|
|
|
|
|
|
|
# 2 => 0x101, |
|
151
|
|
|
|
|
|
|
# 3 => 0x10 + 1/0x100, |
|
152
|
|
|
|
|
|
|
# 4 => 1); |
|
153
|
|
|
|
|
|
|
# my $factor = $hex_factor{$len} || return; |
|
154
|
|
|
|
|
|
|
# ### $len |
|
155
|
|
|
|
|
|
|
# ### $factor |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# # return true if $pixel is black or white in the default root window colormap |
|
161
|
|
|
|
|
|
|
# sub pixel_is_black_or_white { |
|
162
|
|
|
|
|
|
|
# my ($X, $pixel) = @_; |
|
163
|
|
|
|
|
|
|
# return ($pixel == $X->{'black_pixel'} || $pixel == $X->{'white_pixel'}); |
|
164
|
|
|
|
|
|
|
# } |
|
165
|
|
|
|
|
|
|
# |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
|
168
|
|
|
|
|
|
|
__END__ |