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 | |
|
Re: Embedding Programs with Gtk2::Socket
by zentara (Cardinal) on Jul 19, 2006 at 13:52 UTC | |
|
Re: Embedding Programs with Gtk2::Socket
by alexxxm (Acolyte) on Sep 15, 2010 at 11:16 UTC |