1package X11::Resolution; 2 3use warnings; 4use strict; 5use X11::Protocol; 6 7=head1 NAME 8 9X11::Resolution - Get information on the current resolution for X. 10 11=head1 VERSION 12 13Version 0.0.0 14 15=cut 16 17our $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 47This 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 56sub 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 75This 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 93sub 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 116This is a internal function and should not be called. 117 118=cut 119 120#blanks the error flags 121sub 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 134No enviromental variable 'DISPLAY' listed. 135 136=head2 2 137 138None existant display. 139 140=head1 AUTHOR 141 142Zane C. Bowers, C<< <vvelox at vvelox.net> >> 143 144=head1 BUGS 145 146Please report any bugs or feature requests to C<bug-x11-resolution at rt.cpan.org>, or through 147the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=X11-Resolution>. I will be notified, and then you'll 148automatically be notified of progress on your bug as I make changes. 149 150 151 152 153=head1 SUPPORT 154 155You can find documentation for this module with the perldoc command. 156 157 perldoc X11::Resolution 158 159 160You can also look for information at: 161 162=over 4 163 164=item * RT: CPAN's request tracker 165 166L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=X11-Resolution> 167 168=item * AnnoCPAN: Annotated CPAN documentation 169 170L<http://annocpan.org/dist/X11-Resolution> 171 172=item * CPAN Ratings 173 174L<http://cpanratings.perl.org/d/X11-Resolution> 175 176=item * Search CPAN 177 178L<http://search.cpan.org/dist/X11-Resolution/> 179 180=back 181 182 183=head1 ACKNOWLEDGEMENTS 184 185 186=head1 COPYRIGHT & LICENSE 187 188Copyright 2009 Zane C. Bowers, all rights reserved. 189 190This program is free software; you can redistribute it and/or modify it 191under the same terms as Perl itself. 192 193 194=cut 195 1961; # End of X11::Resolution 197