1package X11::Xlib::Screen; 2use strict; 3use warnings; 4use X11::Xlib::Display; 5require Scalar::Util; 6 7# All modules in dist share a version 8BEGIN { our $VERSION= $X11::Xlib::VERSION; } 9 10=head1 NAME 11 12X11::Xlib::Screen - Convenience wrapper around Display+ScreenID 13 14=head1 DESCRIPTION 15 16In ancient history, a C<Screen> represented one physical graphics device 17+ monitor. 18Now days there tends to be only one per system, with multiple monitors or 19displays aggregated into a single screen using Xinerama or XRandR. 20This was mostly caused by the annoying restriction that graphic resources 21(i.e. windows) are bound to a single screen. 22 23The short of that story is that C<< $display->screen_count >> and 24C<< $screen->width >> etc don't do what a person might expect them to do. 25If you want to know about the boundaries of physical monitors you'll need 26the yet-unwritten C<X11::Xlib::Monitor> objects provided by a future wrapper 27around Xinerama or XRandR. 28 29=head1 ATTRIBUTES 30 31=head2 display 32 33Reference to L<X11::Xlib::Display> 34 35=head2 screen_number 36 37The integer identifying this screen. 38 39=head2 width 40 41Width in pixels 42 43=head2 height 44 45Height in pixels 46 47=head2 width_mm 48 49Physical width in millimeters. 50 51=head2 height_mm 52 53Physical height in millimeters. 54 55=head2 depth 56 57Color depth of the RootWindow of this screen. 58 59=cut 60 61sub display { $_[0]{display} } 62sub screen_number { $_[0]{screen_number} } 63sub width { $_[0]{display}->DisplayWidth($_[0]{screen_number}) } 64sub height { $_[0]{display}->DisplayHeight($_[0]{screen_number}) } 65sub width_mm { $_[0]{display}->DisplayWidthMM($_[0]{screen_number}) } 66sub height_mm { $_[0]{display}->DisplayHeightMM($_[0]{screen_number}) } 67sub depth { $_[0]{display}->DefaultDepth($_[0]{screen_number}) } 68 69=head2 root_window_xid 70 71The XID of the root window of this screen 72 73=head2 root_window 74 75The L<X11::Xlib::Window> object for the root window of this screen 76 77=cut 78 79sub root_window_xid { 80 my $self= shift; 81 $self->{root_window_xid} ||= 82 X11::Xlib::RootWindow($self->{display}, $self->{screen_number}); 83} 84 85sub root_window { 86 my $self= shift; 87 # Allow strong ref to root window, since it isn't going anywhere 88 $self->{root_window} ||= 89 $self->{display}->get_cached_window($self->root_window_xid); 90} 91 92=head2 visual 93 94The default visual of this screen 95 96=cut 97 98sub visual { 99 my $self= shift; 100 $self->{visual} ||= $self->{display}->DefaultVisual($self->{screen_number}); 101} 102 103=head1 METHODS 104 105=cut 106 107sub _new { 108 my $class= shift; 109 my %args= (@_ == 1 && ref $_[0] eq 'HASH')? %{$_[0]} : @_; 110 defined $args{display} or die "'display' is required"; 111 defined $args{screen_number} or die "'screen_number' is required"; 112 Scalar::Util::weaken($args{display}); 113 bless \%args, $class; 114} 115 116=head2 visual_info 117 118 my $vinfo= $screen->visual_info(); # uses defualt visual for this screen 119 my $vinfo= $screen->visual_info($visual); 120 my $vinfo= $screen->visual_info($visual_id); 121 122Shortcut to L<X11::Xlib::Display/visual_info>, but using this screen's 123default visual when no argument is given. 124 125=cut 126 127sub visual_info { 128 my ($self, $visual_or_id)= @_; 129 $self->display->visual_info(defined $visual_or_id? $visual_or_id : $self->visual); 130} 131 132=head2 match_visual_info 133 134 my $vinfo= $screen->match_visual_info($depth, $class); 135 136Like L<X11::Xlib::Display/match_visual_info> but with an implied C<$screen> argument. 137 138=cut 139 140sub match_visual_info { 141 my ($self, $depth, $class)= @_; 142 $self->display->match_visual_info($self, $depth, $class); 143} 144 1451; 146 147__END__ 148 149=head1 AUTHOR 150 151Olivier Thauvin, E<lt>nanardon@nanardon.zarb.orgE<gt> 152 153Michael Conrad, E<lt>mike@nrdvana.netE<gt> 154 155=head1 COPYRIGHT AND LICENSE 156 157Copyright (C) 2009-2010 by Olivier Thauvin 158 159Copyright (C) 2017 by Michael Conrad 160 161This library is free software; you can redistribute it and/or modify 162it under the same terms as Perl itself, either Perl version 5.10.0 or, 163at your option, any later version of Perl 5 you may have available. 164 165=cut 166