Gtk2::Gdk::Window->foreign_new, help needed



Hello folks, 

i am trying to get the native window ids of my running x-session and
handle them in my perl code using Gtk2::Gdk::Window->foreign_new but
this is misleading into an error:
Gdk-CRITICAL **: gdk_window_foreign_new_for_display: assertion
`GDK_IS_DISPLAY (display)'

Here is my code snippet:

#! /usr/bin/perl
use strict;
use Gtk2;

my @anids=();
my @xwininfo_resp = `xwininfo`;
foreach(@xwininfo_resp){
        chomp;
        if ($_ =~ /.*(0x[a-f0-9]+) .*/){
                my $id = $1;
                print "Checking Window: $_\n";
                print "Detected-Id: $id Window\n"; 
                push(@anids, Gtk2::Gdk::Window->foreign_new(hex($id)));
                print "--------------------------------------\n";       
        }
}

my $counter = 0;
foreach my $root (@anids){
        if($root && $root->is_viewable){
                my ($w, $h) = $root->get_size;          
                next unless ($w > 10 && $h > 10);
                my $state = $root->get_state;
                next if $state eq 'GDK_WINDOW_STATE_WITHDRAWN';
        
                my $pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable ($root,
Gtk2::Gdk::Colormap->get_system, 0, 0, 0, 0, $w, $h);

                $pixbuf->get_from_drawable ($root, undef, 0, 0, 0, 0, $w, $h) if
defined($pixbuf); 
                
                $pixbuf->save ("screenshot_$counter.png", 'png') if defined($pixbuf);
                print "$root - State = $state - Number = $counter\n";
         
                $counter++;
        }
}

I think a am doing something totally wrong here, but i can't figure it
out.
I've already had that code running, but i do not know what changed :-(


Thanks in advance
Mario




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]