351
354
return ($pixbuf, $l_cropped, $r_cropped, $t_cropped, $b_cropped);
354
#code ported and partially borrowed from gnome-screenshot
357
#code ported and partially borrowed from gnome-screenshot and Gimp
355
358
sub include_cursor {
357
360
my ( $self, $xp, $yp, $widthp, $heightp, $gdk_window, $pixbuf ) = @_;
360
#~ import lib $self->{_sc}->get_root."/share/shutter/resources/modules";
362
#~ require X11::Protocol;
364
#~ #X11 protocol and XSHAPE ext
365
#~ $self->{_x11} = X11::Protocol->new( $ENV{ 'DISPLAY' } );
366
#~ $self->{_x11}{ext_xfixes} = $self->{_x11}->init_extension('XFIXES');
368
my $cursor = Gtk2::Gdk::Cursor->new( 'GDK_LEFT_PTR' );
370
my $cursor_pixbuf = $cursor->get_image;
372
#try to use default cursor if there was an error
373
unless ( $cursor_pixbuf) {
374
warn "WARNING: There was an error while getting the cursor image - using a default cursor\n";
375
my $icons_path = $self->{_sc}->get_root . "/share/shutter/resources/icons";
377
$cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($icons_path."/Normal.cur");
380
warn "ERROR: There was an error while loading the default cursor: $@\n";
363
import lib $self->{_sc}->get_root."/share/shutter/resources/modules";
365
require X11::Protocol;
367
#X11 protocol and XFIXES ext
368
$self->{_x11} = X11::Protocol->new( $ENV{ 'DISPLAY' } );
369
$self->{_x11}{ext_xfixes} = $self->{_x11}->init_extension('XFIXES');
372
my $cursor_pixbuf = undef;
374
#Cursor position (root window coordinates)
375
my $cursor_pixbuf_xroot = undef;
376
my $cursor_pixbuf_yroot = undef;
378
#The "hotspot" position
379
my $cursor_pixbuf_xhot = undef;
380
my $cursor_pixbuf_yhot = undef;
382
if($self->{_x11}{ext_xfixes}){
384
my ($root_x, $root_y, $width, $height, $xhot, $yhot, $serial, $pixels) = $self->{_x11}->XFixesGetCursorImage;
389
foreach my $y (0 .. $height-1) {
390
foreach my $x (0 .. $width-1) {
391
my $argb = unpack 'L', substr($pixels,$pos,4);
392
my $a = ($argb >> 24) & 0xFF;
393
my $r = ($argb >> 16) & 0xFF;
394
my $g = ($argb >> 8) & 0xFF;
395
my $b = ($argb >> 0) & 0xFF;
398
#~ print "r:$r,g:$g,b:$b,a:$a\n";
400
$r = ($r * 255) / $a if($a);
401
$g = ($g * 255) / $a if($a);
402
$b = ($b * 255) / $a if($a);
404
$data .= pack ('C*', $r, $g, $b, $a);
408
$cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_data($data,'rgb',1,8,$width,$height-1,4*$width);
410
$cursor_pixbuf_xhot = $xhot;
411
$cursor_pixbuf_yhot = $yhot;
413
$cursor_pixbuf_xroot = $root_x;
414
$cursor_pixbuf_yroot = $root_y;
418
my ( $window_at_pointer, $root_x, $root_y, $mask ) = $gdk_window->get_pointer;
420
my $cursor = Gtk2::Gdk::Cursor->new( 'GDK_LEFT_PTR' );
421
$cursor_pixbuf = $cursor->get_image;
423
#try to use default cursor if there was an error
424
unless ( $cursor_pixbuf) {
425
warn "WARNING: There was an error while getting the cursor image - using a default cursor\n";
426
my $icons_path = $self->{_sc}->get_root . "/share/shutter/resources/icons";
428
$cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($icons_path."/Normal.cur");
431
warn "ERROR: There was an error while loading the default cursor: $@\n";
435
$cursor_pixbuf_xhot = $cursor_pixbuf->get_option('x_hot');
436
$cursor_pixbuf_yhot = $cursor_pixbuf->get_option('y_hot');
438
$cursor_pixbuf_xroot = $root_x;
439
$cursor_pixbuf_yroot = $root_y;
384
443
if ( $cursor_pixbuf ) {
385
my ( $window_at_pointer, $x, $y, $mask ) = $gdk_window->get_pointer;
446
my $x = $cursor_pixbuf_xroot;
447
my $y = $cursor_pixbuf_yroot;
387
449
#screenshot dimensions saved in a rect (global x, y)
388
450
my $scshot = Gtk2::Gdk::Rectangle->new( $xp, $yp, $widthp, $heightp );
390
452
#see 'man xcursor' for a detailed description
392
my $xhot = $cursor_pixbuf->get_option('x_hot');
393
my $yhot = $cursor_pixbuf->get_option('y_hot');
454
my $xhot = $cursor_pixbuf_xhot;
455
my $yhot = $cursor_pixbuf_yhot;
395
457
#cursor dimensions (global x, y and width and height of the pixbuf)
396
458
my $cursor = Gtk2::Gdk::Rectangle->new( $x, $y, $cursor_pixbuf->get_width, $cursor_pixbuf->get_height );