~jbicha/ubuntu/oneiric/shutter/shutter-0.87.3

« back to all changes in this revision

Viewing changes to share/shutter/resources/modules/Shutter/Screenshot/Main.pm

  • Committer: Jeremy Bicha
  • Date: 2011-08-24 02:07:08 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: jbicha@ubuntu.com-20110824020708-ykaluz1ipfmmz5se
* New upstream release.
  - "Show in folder" feature
  - Captures real cursor, not just the default cursor
  - Other bugfixes
* debian/control:
  - Bump to Standards-Version 3.9.2
  - Update dependencies to better match upstream's selections
* debian/source/format: Use 3.0 (quilt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#Glib
34
34
use Glib qw/TRUE FALSE/; 
35
35
 
 
36
#stringified perl data structures, suitable for both printing and eval
 
37
use Data::Dumper;
 
38
 
36
39
#--------------------------------------
37
40
 
38
41
sub new {
351
354
        return ($pixbuf, $l_cropped, $r_cropped, $t_cropped, $b_cropped);
352
355
}
353
356
 
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 {
356
359
 
357
360
        my ( $self, $xp, $yp, $widthp, $heightp, $gdk_window, $pixbuf ) = @_;
358
361
 
359
 
        #~ require lib;
360
 
        #~ import lib $self->{_sc}->get_root."/share/shutter/resources/modules";
361
 
        #~ 
362
 
        #~ require X11::Protocol;
363
 
 
364
 
        #~ #X11 protocol and XSHAPE ext
365
 
        #~ $self->{_x11}                          = X11::Protocol->new( $ENV{ 'DISPLAY' } );
366
 
        #~ $self->{_x11}{ext_xfixes} = $self->{_x11}->init_extension('XFIXES');
367
 
 
368
 
        my $cursor = Gtk2::Gdk::Cursor->new( 'GDK_LEFT_PTR' );
369
 
 
370
 
        my $cursor_pixbuf = $cursor->get_image;
371
 
        
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";
376
 
                eval{
377
 
                        $cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($icons_path."/Normal.cur");
378
 
                };
379
 
                if($@){
380
 
                        warn "ERROR: There was an error while loading the default cursor: $@\n";
381
 
                }
 
362
        require lib;
 
363
        import lib $self->{_sc}->get_root."/share/shutter/resources/modules";
 
364
        
 
365
        require X11::Protocol;
 
366
 
 
367
        #X11 protocol and XFIXES ext
 
368
        $self->{_x11}                     = X11::Protocol->new( $ENV{ 'DISPLAY' } );
 
369
        $self->{_x11}{ext_xfixes} = $self->{_x11}->init_extension('XFIXES');
 
370
        
 
371
        #pixbuf
 
372
        my $cursor_pixbuf = undef;
 
373
        
 
374
        #Cursor position (root window coordinates)
 
375
        my $cursor_pixbuf_xroot = undef;
 
376
        my $cursor_pixbuf_yroot = undef;
 
377
        
 
378
        #The "hotspot" position
 
379
        my $cursor_pixbuf_xhot = undef;
 
380
        my $cursor_pixbuf_yhot = undef;
 
381
 
 
382
        if($self->{_x11}{ext_xfixes}){
 
383
                
 
384
                my ($root_x, $root_y, $width, $height, $xhot, $yhot, $serial, $pixels) = $self->{_x11}->XFixesGetCursorImage;
 
385
                
 
386
                #packed data string
 
387
                my $data;
 
388
                my $pos = 0;
 
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;
 
396
                                $pos += 4;
 
397
                                
 
398
                                #~ print "r:$r,g:$g,b:$b,a:$a\n";
 
399
                                
 
400
                                $r = ($r * 255) / $a if($a);
 
401
                                $g = ($g * 255) / $a if($a);
 
402
                                $b = ($b * 255) / $a if($a);
 
403
                                
 
404
                                $data .= pack ('C*', $r, $g, $b, $a);
 
405
                        }
 
406
                }
 
407
                
 
408
                $cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_data($data,'rgb',1,8,$width,$height-1,4*$width);
 
409
 
 
410
                $cursor_pixbuf_xhot = $xhot;
 
411
                $cursor_pixbuf_yhot = $yhot;
 
412
 
 
413
                $cursor_pixbuf_xroot = $root_x;
 
414
                $cursor_pixbuf_yroot = $root_y;
 
415
                
 
416
        }else{
 
417
 
 
418
                my ( $window_at_pointer, $root_x, $root_y, $mask ) = $gdk_window->get_pointer;
 
419
 
 
420
                my $cursor = Gtk2::Gdk::Cursor->new( 'GDK_LEFT_PTR' );
 
421
                $cursor_pixbuf = $cursor->get_image;
 
422
        
 
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";
 
427
                        eval{
 
428
                                $cursor_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($icons_path."/Normal.cur");
 
429
                        };
 
430
                        if($@){
 
431
                                warn "ERROR: There was an error while loading the default cursor: $@\n";
 
432
                        }
 
433
                }
 
434
                
 
435
                $cursor_pixbuf_xhot = $cursor_pixbuf->get_option('x_hot');
 
436
                $cursor_pixbuf_yhot = $cursor_pixbuf->get_option('y_hot');
 
437
                
 
438
                $cursor_pixbuf_xroot = $root_x;
 
439
                $cursor_pixbuf_yroot = $root_y;
 
440
        
382
441
        }
383
442
        
384
443
        if ( $cursor_pixbuf ) {
385
 
                my ( $window_at_pointer, $x, $y, $mask ) = $gdk_window->get_pointer;
 
444
        
 
445
                #x,y pos (cursor)
 
446
                my $x = $cursor_pixbuf_xroot;
 
447
                my $y = $cursor_pixbuf_yroot;
386
448
        
387
449
                #screenshot dimensions saved in a rect (global x, y)
388
450
                my $scshot  = Gtk2::Gdk::Rectangle->new( $xp, $yp, $widthp, $heightp );
389
451
                
390
452
                #see 'man xcursor' for a detailed description
391
453
                #of these values
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;
394
456
 
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 );
415
477
                                                                           $pixbuf, 
416
478
                                                                           $dest_x,
417
479
                                                                           $dest_y, 
418
 
                                                                           $cursor->width + $xhot,
419
 
                                                                           $cursor->height + $yhot, 
 
480
                                                                           $cursor->width,
 
481
                                                                           $cursor->height, 
420
482
                                                                           $x - $xp - $xhot,
421
483
                                                                           $y - $yp - $yhot, 
422
484
                                                                           1.0, 1.0, 'bilinear', 255
423
485
                                                                         );
 
486
                                                                         
424
487
                }
425
488
        }
426
489