Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Embedding Programs with Gtk2::Socket

by eibwen (Friar)
on Jul 18, 2006 at 18:24 UTC ( [id://562089]=perlquestion: print w/replies, xml ) Need Help??

eibwen has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to figure out how to use Gtk2::Plug and Gtk2::Socket for awhile, but I've recently stumbled across this PyGTK FAQ Entry. From what I understand, embedding an arbitrary program which adheres to the XEMBED protocol is fairly straight forward:

#!/usr/bin/perl -w use strict; use Gtk2 '-init'; my $window = new Gtk2::Window; my $socket = new Gtk2::Socket; $window->add($socket); $socket->add_id($window_id_of_program_to_embed); $window->show_all; Gtk2->main;

The biggest problem I see with this is trying to launch the program to embed and determine it's window id. I've written a code in c using X11 functions to determine the window id of a program given it's name, class, and classname (from `xprop`):

int main(void) { int i; unsigned int number_of_children; Display *display; Window window, root, *children, window_root, window_parent; XClassHint class_hint; XTextProperty wmname; if (!(display = XOpenDisplay(":0.0"))) return 1; if (!(root = DefaultRootWindow(display))) return 1; if (!(XQueryTree(display, root, &window_root, &window_parent, &chi +ldren, &number_of_children))) return 1; if (!(number_of_children > 0)) return 1; for (i=0;i<number_of_children;i++) { if (!XGetWMName(display, *(children+i), &wmname)) continue; if (!XGetClassHint(display, *(children+i), &class_hint)) conti +nue; if ( (strcmp("Volume", (char *) wmname.value) == 0) && (strcmp("gnome-settings-daemon", class_hint.res_name) == 0 +) && (strcmp("Gnome-settings-daemon", class_hint.res_class) == +0) ) { window = *(children+i); break; } } if (number_of_children > 0) XFree(children); if (i == number_of_children) return 1; printf("Found window id 0x%x\n", window);

But I don't know how to find the window id in a cross platform manner, much less keep track of the window id generated by a spawned process.

For that matter, I've tried searching CPAN to find the perl module containing the above X11 functions, but nothing was obvious (X11::Lib and Tk::Xlib have promising names, but aren't documented). If I end up having to switch on $^O, I have no idea how to determine the window id (or hwnd?) on windows, much less with all the pertinent error checking demonstrated in the c code above.

Replies are listed 'Best First'.
Re: Embedding Programs with Gtk2::Socket
by Anonymous Monk on Jul 18, 2006 at 18:46 UTC
    For Unix+X, you can use Gnome2::Wnck. Don't worry about the "Gnome2" part; it only depends on Gtk2.
    #!/usr/bin/perl use strict; use warnings; use Gnome2::Wnck; Gtk2 -> init(); my $screen = Gnome2::Wnck::Screen -> get_default(); $screen -> force_update(); my @windows = $screen -> get_windows(); foreach my $window (@windows) { my $name = $window -> get_name(); my $class_name = $window -> get_class_group() -> get_name(); print <<"EOS"; $window name: $name class name: $class_name EOS }
Re: Embedding Programs with Gtk2::Socket
by zentara (Archbishop) on Jul 19, 2006 at 13:52 UTC
    I am not up2-speed on plug and gtk2, but this is an example I have which may help you. There are 2 scripts, plug.pl and socket, put them into a directory and run socket.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Embedding Programs with Gtk2::Socket
by alexxxm (Acolyte) on Sep 15, 2010 at 11:16 UTC
    I dont know if you succeeded in this problem, but I would be very interested to have fresh news.

    As a side note, I had problems compiling your C program, until I added

    #include <stdio.h> #include <X11/Xlib.h> #include <X11/Xutil.h>
    moreover, I was unable to run the perl program: I let it collect the xid by:
    $window_id_of_program_to_embed=`getwindowid2 $windowname`;
    (where getwindowid2 is your C program, which outputs just the numerical idof any window named $windowname)

    the program just creates an empty box, without errors/warnings, and the app to be embedded just stays there.

    Any idea?

    alessandro

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://562089]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found