Some time ago, Slaven Rezic posted a little program (to clp.tk) to steal and reparent an X11 window. I only toyed with it briefly, but did clean up some warnings it emitted (I can't seem to find the original). This version will spawn 5 xterm's (or pass it a number) and reparent them on pages of a NoteBook widget --- wait for it though, it is slow and clunky (but maybe it'll give you some ideas):

#!/usr/bin/perl -w use strict; # this script is a modified version of: ## $Id: ptk_steal.pl,v 1.1 1999/07/01 19:56:31 eserte Exp $ ## Author: Slaven Rezic ## ## Copyright (C) 1999 Slaven Rezic. All rights reserved. ## This program is free software; you can redistribute it and/or ## modify it under the same terms as Perl itself. use Tk; use X11::Protocol; use Tk::NoteBook; my $shells = $ARGV[0] || 5; my @Pids; my %Pages; my $X = X11::Protocol->new(); my $mw = MainWindow->new(); my $topframe = $mw->Frame()->pack(-side => 'top'); $topframe->Button(-text => 'Exit', -command => sub{kill(9,@Pids); $mw->destroy})->pack(-side => 'right +'); my $botframe = $mw->Frame(-borderwidth => 2, -relief => 'groove', )->pack(-side => 'bottom',-expand => 1); my $nbook = $botframe->NoteBook()->pack; for(1 ..$shells){ $Pages{$_} = $nbook->add("page$_", -label => "Shell$_", -underline => 5); my $pid; unless ($pid = fork){ exec("color_xterm -ls -sb -bg 'gray64' -name WindowToSteal$_") +; } if ($pid){ grab_it("WindowToSteal$_", $Pages{$_}); push @Pids,$pid; } } MainLoop(); sub grab_it { my $winname = shift; my $pane = shift; my $wid; my $check = $pane->repeat(50, sub { $wid = get_window_by_name($winname); }); while (!defined $wid) { $pane->waitVariable(\$wid); } $check->cancel; my $f = $pane->Frame('-container' => 1)->pack(-side => 'bottom'); $f->update; $X->ReparentWindow($wid, oct($f->id), 0, 0); } sub get_window_by_name { _get_window_by_name($X->{'root'}, $_[0]); } sub _get_window_by_name { my($root, $searchname) = @_; my(undef, undef, @new_kids) = $X->QueryTree($root); foreach my $k (@new_kids) { my $atomnr; foreach my $atom ($X->ListProperties($k)) { if ($X->GetAtomName($atom) eq "WM_CLASS") { $atomnr = $atom; last; } } if (defined $atomnr) { my($classprop) = $X->GetProperty($k, $atomnr, "AnyPropertyType +",0, 256, 0); my($class, $name) = split(/\0/, $classprop); if ($class eq $searchname) { return $k; } } my $ret = _get_window_by_name($k, $searchname); if (defined $ret) { return $ret; } } undef; } __END__

In reply to Re: Swallowing X11 apps in Tk by danger
in thread Swallowing X11 apps in Tk by strredwolf

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.