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.


In reply to Embedding Programs with Gtk2::Socket by eibwen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.