|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
Gtk2::Gdk::Window->foreign_new, help neededHello 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 _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededMario Kemper wrote:
> #! /usr/bin/perl > use strict; > use Gtk2; I think you're missing the '-init' argument here. Or manually: Gtk2->init. For doing stuff with windows, you might also want to take a look at Gnome2::Wnck: <http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck/index.html> -- Bye, -Torsten _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededOn Wed, 02 Jul 2008 20:23:32 +0200
Mario Kemper <mario.kemper@...> wrote: >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: >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 This rings a little bell, reminding me of when I tried grabbing screenshots thru wininfo ids. And since you said it was working, but now it dosn't, may be a clue that you have the same glitch. The glitch was you needed to run the capture script from the same virtual desktop as the window to-be-captured. Now Gnome2::Wnck does have the ability to switch you to the virtual desktop, I was using X11::WMCtrl This was my hacking script when I did it #!/usr/bin/perl use warnings; use strict; use Image::Magick; use X11::WMCtrl; use Data::Dumper; my $wmctrl = X11::WMCtrl->new; printf("window manager is %s\n", $wmctrl->get_window_manager->{name}); my @windows = $wmctrl->get_windows; my $wid; # x window id my $host; # virtual desktop foreach my $app(@windows){ my $title = $app->{title}; if( $title =~ /Mozilla/i){ print "$title\n"; print Dumper(\$app),"\n\n"; $wid = $app->{id}; $host = $app->{host}; } } $wmctrl->switch($host); #must be on same virtual desktop as the browser #works my $blob = `import -window $wid jpg:`; #my $blob = `import -`; #postscript produced #print "$blob\n"; # now $blob is in memory and you can do what you # want with it. my $output = Image::Magick->new(magick=>'jpg'); $output->BlobToImage( $blob ); $output->Resize(geometry=>'160x120'); $output->Write( $0.'.jpg'); exit; # png works too __END__ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/CandyGram_for_Mongo.html _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededOh, thanks alot. Staring at the same lines of code for a while makes you
blind ;-) Thank you Torsten. I've got the old code running now and i am wondering if it is possible to select a foreign window and get the mouse movement in this window via event. At the moment i am using this dirty code to select a window and print out the mouse movement. It works pretty well but is not really a solution because it'll never reach the gtk main loop... Does anyone know a better solution to get the mouse movement just via a normal event? As you see i was trying to use a drawing area and get the events but this is not working. Thank you all. #! /usr/bin/perl use strict; use Gtk2; Gtk2->init; my @anids=(); my @xwininfo_resp = `xwininfo -tree`; 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; my @drawing_areas; my $area = new Gtk2::DrawingArea; $area->set_events ([qw/exposure-mask leave-notify-mask button-press-mask pointer-motion-mask pointer-motion-hint-mask/]); $area->signal_connect (motion_notify_event => \&motion_notify_event); $area->signal_connect (key_press_event => \&key_press_event); 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'; while(1){ my ($window, $win_x, $win_y) = $root->at_pointer; my ($w, $h) = $window->get_size; print $window." ".$win_x." ".$win_y."\n"; my ($x_start, $y_start) = $window->get_position; print $area." at size ".$w." and ".$h."\n"; #~ &draw_rect($window, [$x_start-5,$y_start-5,$w-5,$h-5],'red'); $area->show_all; sleep 1; } #~ 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++; } } my %allocated_colors; sub button_press_event { my $widget = shift; # GtkWidget *widget my $event = shift; # GdkEventButton *event print join ' ', $event->coords,"\n"; return 1; } sub motion_notify_event { my $widget=shift; my $event=shift; my ($x, $y, $state); if ($event->is_hint) { (undef, $x, $y, $state) = $event->window->get_pointer; } else { $x = $event->x; $y = $event->y; $state = $event->state; } print "value of x and y are $x and $y \n" ; if ($state >= "button1-mask" ) { print "value of x and y and button1 are $x and $y \n" ; } if ($state >= "button2-mask" ) { print "value of x and y and button2 are $x and $y \n" ; } return 1; #was TRUE in source (was scribble.pl) } sub draw_rect { my($widget,$coords,$color) = @_; # see Gdk::Gdk::Window, Gtk2::Gdk::Drawable, Gtk2::Gdk::GC my $colormap = Gtk2::Gdk::Colormap->get_system; my $gc = new Gtk2::Gdk::GC($widget); $gc->set_foreground(get_color($colormap, $color)); $widget->draw_rectangle($gc,0, @$coords); } sub get_color { my ($colormap, $name) = @_; my $ret; if ($ret = $allocated_colors{$name}) { return $ret; } my $color = Gtk2::Gdk::Color->parse($name); $colormap->alloc_color($color,1,1); $allocated_colors{$name} = $color; return $color; } Gtk2->main; Am Mittwoch, den 02.07.2008, 21:16 +0200 schrieb Torsten Schoenfeld: > Mario Kemper wrote: > > > #! /usr/bin/perl > > use strict; > > use Gtk2; > > I think you're missing the '-init' argument here. Or manually: Gtk2->init. > > For doing stuff with windows, you might also want to take a look at Gnome2::Wnck: > > <http://gtk2-perl.sourceforge.net/doc/pod/Gnome2/Wnck/index.html> > _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededOn Wed, 02 Jul 2008 20:23:32 +0200
Mario Kemper <mario.kemper@...> wrote: >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: >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 Sorry if this is a multiple post, my mailer seemed to send it, but I never received it from the list? Maybe the magic pixel fairy deemed it useless? :-) This rings a little bell, reminding me of when I tried grabbing screenshots thru wininfo ids. And since you said it was working, but now it dosn't, may be a clue that you have the same glitch. The glitch was you needed to run the capture script from the same virtual desktop as the window to-be-captured. Now Gnome2::Wnck does have the ability to switch you to the virtual desktop, I was using X11::WMCtrl This was my hacking script when I did it #!/usr/bin/perl use warnings; use strict; use Image::Magick; use X11::WMCtrl; use Data::Dumper; my $wmctrl = X11::WMCtrl->new; printf("window manager is %s\n", $wmctrl->get_window_manager->{name}); my @windows = $wmctrl->get_windows; my $wid; # x window id my $host; # virtual desktop foreach my $app(@windows){ my $title = $app->{title}; if( $title =~ /Mozilla/i){ print "$title\n"; print Dumper(\$app),"\n\n"; $wid = $app->{id}; $host = $app->{host}; } } $wmctrl->switch($host); #must be on same virtual desktop as the browser #works my $blob = `import -window $wid jpg:`; #my $blob = `import -`; #postscript produced #print "$blob\n"; # now $blob is in memory and you can do what you # want with it. my $output = Image::Magick->new(magick=>'jpg'); $output->BlobToImage( $blob ); $output->Resize(geometry=>'160x120'); $output->Write( $0.'.jpg'); exit; # png works too __END__ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/CandyGram_for_Mongo.html _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededI've already received your messsage through the list and it was a great
help. Maybe you've some suggestions for my next step i've explained in my last mail today. Am Donnerstag, den 03.07.2008, 07:19 -0400 schrieb zentara: > On Wed, 02 Jul 2008 20:23:32 +0200 > Mario Kemper <mario.kemper@...> wrote: > > >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: > > >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 > > Sorry if this is a multiple post, my mailer seemed to send it, but I never > received it from the list? Maybe the magic pixel fairy deemed it useless? :-) > > This rings a little bell, reminding me of when I tried grabbing screenshots > thru wininfo ids. And since you said it was working, but now it dosn't, may be a clue > that you have the same glitch. The glitch was you needed to run the capture script from the > same virtual desktop as the window to-be-captured. Now Gnome2::Wnck > does have the ability to switch you to the virtual desktop, I was using X11::WMCtrl > > This was my hacking script when I did it > > #!/usr/bin/perl > use warnings; > use strict; > use Image::Magick; > use X11::WMCtrl; > use Data::Dumper; > > my $wmctrl = X11::WMCtrl->new; > > printf("window manager is %s\n", $wmctrl->get_window_manager->{name}); > > my @windows = $wmctrl->get_windows; > > my $wid; # x window id > my $host; # virtual desktop > > foreach my $app(@windows){ > my $title = $app->{title}; > if( $title =~ /Mozilla/i){ > print "$title\n"; > print Dumper(\$app),"\n\n"; > > $wid = $app->{id}; > $host = $app->{host}; > > } > } > > $wmctrl->switch($host); > #must be on same virtual desktop as the browser > > #works > my $blob = `import -window $wid jpg:`; > > #my $blob = `import -`; #postscript produced > #print "$blob\n"; > # now $blob is in memory and you can do what you > # want with it. > > my $output = Image::Magick->new(magick=>'jpg'); > $output->BlobToImage( $blob ); > $output->Resize(geometry=>'160x120'); > $output->Write( $0.'.jpg'); > > exit; > # png works too > > > __END__ > > zentara > > _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededMario Kemper <mario.kemper@...> writes:
> > I've got the old code running now and i am wondering if it is possible > to select a foreign window and get the mouse movement in this window via > event. The short answer is yes, you can select events on any window (not just your own) and they come to your client program. But I don't know off-hand the easiest way to hook into gtk/gdk to see them. -- The sigfile one-line movie reviews series: "Jaws" -- about being bloody frightened of being eaten by a bloody great shark. _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
|
|
Re: Gtk2::Gdk::Window->foreign_new, help neededOn Jul 2, 2008, at 4:54 PM, zentara wrote: > This rings a little bell, reminding me of when I tried grabbing > screenshots > thru wininfo ids. And since you said it was working, but now it > dosn't, may be a clue > that you have the same glitch. The glitch was you needed to run the > capture script from the > same virtual desktop as the window to-be-captured. You need to use the same display as the target window. window = Gtk2::Gdk::Window->foreign_new_for_display ($display, $anid) * $display (Gtk2::Gdk::Display) * $anid (Gtk2::Gdk::NativeWindow) Since: gtk+ 2.2 That said, i'm not really sure how to get that. -- Diane, ten-oh-three, Great Northern Hotel. Sheriff Truman and I have just been with the one-armed man, or what's left of him. In another time, another culture, he may have been a seer, or a shaman priest, but in our world, he's a shoe salesman, and lives among the shadows. -- Special Agent Dale Cooper _______________________________________________ gtk-perl-list mailing list gtk-perl-list@... http://mail.gnome.org/mailman/listinfo/gtk-perl-list |
| Free Forum Powered by Nabble | Forum Help |