+0.009_001
+
+- add Darwin (Apple Mac OS X) support
+
+- test release to see how broken it is
+
0.009 15 Jun 2010
- check for Win32 support with Devel::CheckLib if we don't find them
README
Screenshot.pm Main perl implementation
Screenshot.xs Interface to C code
+scdarwin.c Darwin implementation
scwin32.c Win32 implementation
scx11.c X11 implementation
t/00load.t Test - can we load the modules
t/20x11.t Test - X11 implementation
t/30tkx11.t Test - X11 implementation via Tk
t/40tkwin32.t Test - Win32 implementation via Tk
+t/50darwin.t Test - Darwin implementation
t/90pod.t Test - check POD is valid
t/91podcover.t Test - check all functions are covered by POD
t/92manifest.t Test - check we match the MANIFEST
}
if ($^O eq "darwin") {
+ # this test is overly simple
push @objs, "scdarwin.o";
push @cflags, "-DSS_DARWIN";
push @lddlflags, qw/-framework OpenGL -framework Cocoa/;
VERSION_FROM => 'Screenshot.pm',
OBJECT => "@objs",
PREREQ_PM => {
- 'Imager' => 0.54,
+ 'Imager' => 0.69,
},
INC => Imager::ExtUtils->includes,
TYPEMAPS => [ Imager::ExtUtils->typemap ],
$opts{LDDLFLAGS} = $Config{lddlflags} . " @lddlflags";
}
-# avoid "... isn't numberic in numeric gt ..." warnings for dev versions
+# avoid "... isn't numeric in numeric gt ..." warnings for dev versions
my $eu_mm_version = eval $ExtUtils::MakeMaker::VERSION;
if ($eu_mm_version > 6.06) {
$opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
{
configure_requires =>
{
- Imager => "0.54"
+ Imager => "0.69"
},
build_requires =>
{
- Imager => "0.54",
+ Imager => "0.69",
"Test::More" => "0.47",
}
};
SDK header files and libraries for Win32 support
and/or
X11 header files and libraries for X11 support.
+ and/or
+ OS X header files and libraries (supplied with Xcode)
A C compiler compatible with that used to build perl itself.
Optional:
- Win32 (mingw)
- Win32/X11 (cygwin as of Jan 1 2007)
- X11 (Debian Linux)
+ - Mac OS X 10.6.4.
License:
$result = _x11($opts{display}, $opts{id}, $opts{left}, $opts{top},
$opts{right}, $opts{bottom});
}
+ elsif (defined $opts{darwin}) { # as long as it's there
+ defined &_darwin
+ or die "Darwin driver not enabled\n";
+ $result = _darwin($opts{left}, $opts{top}, $opts{right}, $opts{bottom});
+ }
elsif ($opts{widget}) {
# Perl/Tk widget
my $top = $opts{widget}->toplevel;
defined &_x11;
}
+sub have_darwin {
+ defined &_darwin;
+}
+
sub x11_open {
my $display = _x11_open(@_);
unless ($display) {
# test for x11 support
if (Imager::Screenshot->have_x11) { ... }
+ # test for Darwin (Mac OS X) support
+ if (Imager::Screenshot->have_darwin) { ... }
+
=head1 DESCRIPTION
Note: taking a screenshot of a remote display is slow.
+=item screenshot darwin => 0
+
+Retrieve a screenshot under Mac OS X. The only supported value for
+the C<darwin> parameter is C<0>.
+
+For a screen capture to be taken, the current user using
+Imager:Screenshot must be the currently logged in user on the display.
+
+If you're using fast user switching, the current user must be the
+active user.
+
+Note: this means you can ssh into a Mac OS X box and screenshot from
+the ssh session, if you're the current user on the display.
+
=item screenshot widget => I<widget>
=item screenshot widget => I<widget>, display => I<display>
=item *
+if Darwin support is compiled, return screenshot(darwin => 0).
+
+=item *
+
if X11 support is compiled, return screenshot(id => 0).
=item *
Returns true if X11 support is available.
+=item have_darwin
+
+Returns true if Darwin support is available.
+
=item Imager::Screenshot::x11_open
=item Imager::Screenshot::x11_open I<display name>
example, Win32 and X11, and which is used can have an effect on the
result.
-Under Win32, if there's a screesaver running, then you grab the
-results of the screensaver.
+Under Win32 or OS X, if there's a screesaver running, then you grab
+the results of the screensaver.
+
+On OS X, you can grab the display from an ssh session as long as the
+ssh session is under the same user as the currently active user on the
+display.
Grabbing the root window on a rootless server (eg. Cygwin/X) may not
grab the background that you see. In fact, when I tested under
=item *
-OS X support - I need to find out which APIs to use to do this. I
-found some information on the APIs used for this, but don't have a Mac
-I can test on.
-
-=item *
-
window name searches - currently screenshot() requires a window
identifier of some sort, it would be more usable if we could supply
some other identifier, either a window title or a window class name.
i_clear_error();
disp = CGMainDisplayID();
+ if (!disp) {
+ i_push_error(0, "No main display");
+ return NULL;
+ }
/* for now, only interested in the first display */
rect = CGDisplayBounds(disp);
return NULL;
}
if (!npix) {
- i_push_error(0, "No pixel format found");
+ i_push_error(0, "No pixel format found - hidden display?");
return NULL;
}
glReadBuffer(GL_FRONT);
glReadPixels(left, screen_height - top - height, width, height,
- GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
+ GL_RGBA, GL_UNSIGNED_BYTE, buf);
/* transfer */
while (y >= 0) {
}
free(buf);
+
+ i_tags_setn(&im->tags, "ss_window_width", width);
+ i_tags_setn(&im->tags, "ss_window_height", height);
+ i_tags_set(&im->tags, "ss_type", "Darwin", 6);
+ i_tags_setn(&im->tags, "ss_left", left);
+ i_tags_setn(&im->tags, "ss_top", top);
}
/* clean up */
--- /dev/null
+#!perl -w
+use strict;
+use Test::More;
+
+use Imager::Screenshot 'screenshot';
+
+++$|;
+
+Imager::Screenshot->have_darwin
+ or plan skip_all => "No darwin support";
+
+my $im = screenshot(darwin => 0, right => 1, bottom => 1);
+unless ($im) {
+ my $err = Imager->errstr;
+ $err =~ /No pixel format found/
+ or plan skip_all => "Probably an inactive user";
+ $err =~ /No main display/
+ or plan skip_all => "User doen't have a display";
+}
+
+plan tests => 7;
+
+{
+ my $im = screenshot(darwin => 0);
+ ok($im, "got an image");
+ is($im->getchannels, 3, "we have some color");
+
+ is($im->tags(name => "ss_window_width"), $im->getwidth,
+ "check ss_window_width tag");
+ is($im->tags(name => 'ss_window_height'), $im->getheight,
+ "check ss_window_height tag");
+ is($im->tags(name => 'ss_left'), 0, "check ss_left tag");
+ is($im->tags(name => 'ss_top'), 0, "check ss_top tag");
+ is($im->tags(name => 'ss_type'), 'Darwin', "check ss_type tag");
+}