1 package Imager::Screenshot;
\r
3 use vars qw(@ISA $VERSION @EXPORT_OK);
\r
7 push @ISA, 'Exporter';
\r
8 @EXPORT_OK = 'screenshot';
\r
12 @ISA = qw(Exporter);
\r
15 # try XSLoader first, DynaLoader has annoying baggage
\r
17 XSLoader::load('Imager::Screenshot' => $VERSION);
\r
21 push @ISA, 'DynaLoader';
\r
22 bootstrap Imager::Screenshot $VERSION;
\r
27 # lose the class if called as a method
\r
28 @_ % 2 == 1 and shift;
\r
30 my %opts = (decor => 0, display => 0, @_);
\r
35 defined &win32 ? win32(0) :
\r
36 defined &x11 ? x11($opts{display}, 0) :
\r
37 die "No drivers enabled\n";
\r
39 if (defined $opts{hwnd}) {
\r
41 or die "Win32 driver not enabled\n";
\r
42 $result = win32($opts{hwnd}, $opts{decor});
\r
44 elsif (defined $opts{id}) { # X11 window id
\r
46 or die "X11 driver not enabled\n";
\r
47 $result = x11($opts{display}, $opts{id});
\r
49 elsif ($opts{widget}) {
\r
51 my $top = $opts{widget}->toplevel;
\r
52 my $sys = $top->windowingsystem;
\r
53 if ($sys eq 'win32') {
\r
54 unless (defined &win32) {
\r
55 Imager->_set_error("Win32 Tk and Win32 support not built");
\r
58 $result = win32(hex($opts{widget}->id));
\r
60 elsif ($sys eq 'x11') {
\r
61 unless (defined &x11) {
\r
62 Imager->_set_error("X11 Tk and X11 support not built");
\r
66 my $id_hex = $opts{widget}->id;
\r
67 print "id $id_hex\n";
\r
68 $opts{widget}->can('frame')
\r
69 and $id_hex = $opts{widget}->frame;
\r
70 print "id $id_hex\n";
\r
72 # is there a way to get the display pointer from Tk?
\r
73 $result = x11(0, hex($id_hex));
\r
76 Imager->_set_error("Unsupported windowing system '$sys'");
\r
82 Imager->_set_error(Imager->_error_as_msg());
\r
98 my $display = _x11_open(@_);
\r
100 Imager->_set_error(Imager->_error_as_msg);
\r
113 Imager::Screenshot - screenshot to an Imager image
\r
117 use Imager::Screenshot 'screenshot';
\r
120 my $img = screenshot();
\r
123 my $img2 = screenshot(hwnd => $hwnd);
\r
126 my $img3 = screenshot(display => $display, id => $window_id);
\r
129 my $display = Imager::Screenshot::x11_open();
\r
130 Imager::Screenshot::x11_close($display);
\r
132 # test for win32 support
\r
133 if (Imager::Screenshot->have_win32) { ... }
\r
135 # test for x11 support
\r
136 if (Imager::Screenshot->have_x11) { ... }
\r
141 Imager::Screenshot captures either a desktop or a specified window and
\r
142 returns the result as an Imager image.
\r
144 Currently the image is always returned as a 24-bit image.
\r
148 =item screenshot hwnd => I<window handle>
\r
150 =item screenshot hwnd => I<window handle>, decor => <capture decorations>
\r
152 Retrieve a screenshot under Win32, if I<window handle> is zero,
\r
153 capture the desktop.
\r
155 By default, window decorations are not captured, if the C<decor>
\r
156 parameter is set to true then window decorations are included.
\r
158 =item screenshot id => I<window id>
\r
160 =item screenshot id => I<window id>, display => I<display object>
\r
162 Retrieve a screenshot under X11, if I<id> is zero, capture the root
\r
163 window. I<display object> is a integer version of an X11 C< Display *
\r
164 >, if this isn't supplied C<screenshot()> will attempt connect to the
\r
165 the display specified by $ENV{DISPLAY}.
\r
169 If no parameters are supplied:
\r
175 if Win32 support is compiled, return screenshot(hwnd => 0).
\r
179 if X11 support is compiled, return screenshot(id => 0).
\r
189 Returns true if Win32 support is available.
\r
193 Returns true if X11 support is available.
\r
195 =item Imager::Screenshot::x11_open
\r
197 =item Imager::Screenshot::x11_open I<display name>
\r
199 Attempts to open a connection to either the display name in
\r
200 $ENV{DISPLAY} or the supplied display name. Returns a value suitable
\r
201 for the I<display> parameter of screenshot, or undef.
\r
203 =item Imager::Screenshot::x11_close I<display>
\r
205 Closes a display returned by Imager::Screenshot::x11_open().
\r
211 Tony Cook <tonyc@cpan.org>
\r