File Coverage

blib/lib/X11/Resolution.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package X11::Resolution;
2              
3 1     1   23908 use warnings;
  1         2  
  1         30  
4 1     1   6 use strict;
  1         1  
  1         30  
5 1     1   372 use X11::Protocol;
  0            
  0            
6              
7             =head1 NAME
8              
9             X11::Resolution - Get information on the current resolution for X.
10              
11             =head1 VERSION
12              
13             Version 0.0.0
14              
15             =cut
16              
17             our $VERSION = '0.0.0';
18              
19              
20             =head1 SYNOPSIS
21              
22             use X11::Resolution;
23              
24             my $xres=X11::Resolution->new();
25             if($xres->{error}){
26             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
27             }
28              
29             #gets it currently the current screen
30             my ($x, $y)=$xres->getResolution;
31             if($xres->{error}){
32             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
33             }
34             print "x=".$x."\ny=".$y."\n";
35              
36             #gets it for screen zero
37             my ($x, $y)=$xres->getResolution(0);
38             if($xres->{error}){
39             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
40             }
41             print "x=".$x."\ny=".$y."\n";
42              
43             =head1 methodes
44              
45             =head2 new
46              
47             This initiates the object.
48              
49             my $xres=X11::Resolution->new();
50             if($xres->{error}){
51             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
52             }
53              
54             =cut
55              
56             sub new{
57             my $self = {error=>undef, errorString=>''};
58              
59             if (!defined($ENV{DISPLAY})) {
60             warn('X11-Resolution new:1: No enviromentail variable "DISPLAY" defined');
61             $self->{error}=1;
62             $self->{errorString}='No enviromentail variable "DISPLAY" defined.';
63             return $self;
64             }
65              
66             $self->{x}=X11::Protocol->new();
67              
68             bless $self;
69              
70             return $self
71             }
72              
73             =head2 getResolution
74              
75             This fetches the resolution for the current or a given screen.
76              
77             #gets it currently the current screen
78             my ($x, $y)=$xres->getResolution;
79             if($xres->{error}){
80             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
81             }
82             print "x=".$x."\ny=".$y."\n";
83              
84             #gets it for screen zero
85             my ($x, $y)=$xres->getResolution(0);
86             if($xres->{error}){
87             print "Error:".$xres->{error}.": ".$xres->{errorString}."\n";
88             }
89             print "x=".$x."\ny=".$y."\n";
90              
91             =cut
92              
93             sub getResolution{
94             my $self=$_[0];
95             my $display=$_[1];
96              
97             if (!defined($display)) {
98             $display=$ENV{DISPLAY};
99              
100             $display=~s/.*\.//g;
101              
102             }
103              
104             if (!defined($self->{x}->{'screens'}[$display])) {
105             warn('X11-Resolution getResolution:2: ');
106             }
107              
108             my $x=$self->{x}->{'screens'}[$display]{'width_in_pixels'};
109             my $y=$self->{x}->{'screens'}[$display]{'height_in_pixels'};
110              
111             return $x, $y;
112             }
113              
114             =head2 errorBlank
115              
116             This is a internal function and should not be called.
117              
118             =cut
119              
120             #blanks the error flags
121             sub errorBlank{
122             my $self=$_[0];
123              
124             $self->{error}=undef;
125             $self->{errorString}='';
126              
127             return 1;
128             };
129              
130             =head1 ERROR CODES
131              
132             =head2 1
133              
134             No enviromental variable 'DISPLAY' listed.
135              
136             =head2 2
137              
138             None existant display.
139              
140             =head1 AUTHOR
141              
142             Zane C. Bowers, C<< >>
143              
144             =head1 BUGS
145              
146             Please report any bugs or feature requests to C, or through
147             the web interface at L. I will be notified, and then you'll
148             automatically be notified of progress on your bug as I make changes.
149              
150              
151              
152              
153             =head1 SUPPORT
154              
155             You can find documentation for this module with the perldoc command.
156              
157             perldoc X11::Resolution
158              
159              
160             You can also look for information at:
161              
162             =over 4
163              
164             =item * RT: CPAN's request tracker
165              
166             L
167              
168             =item * AnnoCPAN: Annotated CPAN documentation
169              
170             L
171              
172             =item * CPAN Ratings
173              
174             L
175              
176             =item * Search CPAN
177              
178             L
179              
180             =back
181              
182              
183             =head1 ACKNOWLEDGEMENTS
184              
185              
186             =head1 COPYRIGHT & LICENSE
187              
188             Copyright 2009 Zane C. Bowers, all rights reserved.
189              
190             This program is free software; you can redistribute it and/or modify it
191             under the same terms as Perl itself.
192              
193              
194             =cut
195              
196             1; # End of X11::Resolution