| 1 | # Copyright 2010, 2011, 2012, 2013 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Image-Base-X11-Protocol. | ||
| 4 | # | ||
| 5 | # Image-Base-X11-Protocol is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU General Public License as published | ||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||
| 8 | # later version. | ||
| 9 | # | ||
| 10 | # Image-Base-X11-Protocol is distributed in the hope that it will be useful, | ||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
| 13 | # Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with Image-Base-X11-Protocol. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | |||
| 19 | package Image::Base::X11::Protocol::Pixmap; | ||
| 20 | use 5.004; | ||
| 21 | use strict; | ||
| 22 | use Carp; | ||
| 23 | use X11::Protocol::Other; | ||
| 24 | use vars '@ISA', '$VERSION'; | ||
| 25 | |||
| 26 | use Image::Base::X11::Protocol::Drawable; | ||
| 27 | @ISA = ('Image::Base::X11::Protocol::Drawable'); | ||
| 28 | |||
| 29 | $VERSION = 15; | ||
| 30 | |||
| 31 | # uncomment this to run the ### lines | ||
| 32 | #use Smart::Comments; | ||
| 33 | |||
| 34 | sub new { | ||
| 35 | my ($class, %params) = @_; | ||
| 36 | ### X11-Protocol-Pixmap new() | ||
| 37 | |||
| 38 | if (my $pixmap = delete $params{'-pixmap'}) { | ||
| 39 | $params{'-drawable'} = $params{'-pixmap'}; | ||
| 40 | } | ||
| 41 | my $X = $params{'-X'}; | ||
| 42 | |||
| 43 | if (! defined $params{'-drawable'}) { | ||
| 44 | my $screen = $params{'-screen'}; | ||
| 45 | my $for_window = delete $params{'-for_window'}; | ||
| 46 | my $for_drawable = delete $params{'-for_drawable'} | ||
| 47 | || $for_window | ||
| 48 | || (defined $screen && $X->{'screens'}->[$screen]->{'root'}) | ||
| 49 | || $X->{'root'}; | ||
| 50 | |||
| 51 | my $depth = $params{'-depth'}; | ||
| 52 | if (! defined $depth) { | ||
| 53 | if (my $screen_info = X11::Protocol::Other::root_to_screen_info($X, $for_drawable)) { | ||
| 54 | $depth = $screen_info->{'root_depth'}; | ||
| 55 | } else { | ||
| 56 | my %geom = $X->GetGeometry($for_drawable); | ||
| 57 | $depth = $geom{'depth'}; | ||
| 58 | if (! defined $params{'-root'}) { | ||
| 59 | $params{'-root'} = $geom{'root'}; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | ### $depth | ||
| 64 | |||
| 65 | if ($for_window && ! defined $params{'-colormap'}) { | ||
| 66 | ### default colormap from window | ||
| 67 | my %attrs = $X->GetWindowAttributes ($for_window); | ||
| 68 | my $visual = $attrs{'visual'}; | ||
| 69 | if ($depth == $X->{'visuals'}->{$visual}->{'depth'}) { | ||
| 70 | $params{'-colormap'} = $attrs{'colormap'}; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | my $pixmap = $params{'-drawable'} = $X->new_rsrc; | ||
| 75 | ### X11-Protocol-Pixmap CreatePixmap | ||
| 76 | ### ID: $pixmap | ||
| 77 | ### $for_window | ||
| 78 | ### depth: $depth | ||
| 79 | ### width: $params{'-width'} | ||
| 80 | ### height: $params{'-height'} | ||
| 81 | $X->CreatePixmap ($pixmap, | ||
| 82 | $for_drawable, | ||
| 83 | ($params{'-depth'} = $depth), | ||
| 84 | $params{'-width'}, | ||
| 85 | $params{'-height'}); | ||
| 86 | } | ||
| 87 | return $class->SUPER::new (%params); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub _get { | ||
| 91 | my ($self, $key) = @_; | ||
| 92 | if ($key eq '-pixmap') { | ||
| 93 | $key = '-drawable'; | ||
| 94 | } | ||
| 95 | return $self->SUPER::_get($key); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub set { | ||
| 99 | my ($self, %params) = @_; | ||
| 100 | if (exists $params{'-pixmap'}) { | ||
| 101 | $params{'-drawable'} = delete $params{'-pixmap'}; | ||
| 102 | } | ||
| 103 | $self->SUPER::set(%params); | ||
| 104 | } | ||
| 105 | |||
| 106 | 1; | ||
| 107 | __END__ |