Hi, this is a Perl question. I have been trying to embed an xterm into a Tk or Gtk2 perl gui. Now I have been succesful with Tk, but Gtk2 loses keyboard focus. I had given up on it, until I tested rxvt-unicode which successfully embedded the rxvt into a Gtk2 perl window. However, when I try to use an xterm instead, the keyboard focus gets lost.

So can anyone explain what is happening? You need a relatively recent version of xterm, to support the "-into xid" function.

Tk works with an embedded xterm or rxvt

#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new(); my $xtermContainer = $mw->Frame(-height=>400, -width=>300, -container => 1)->pack(); my $xtid = $xtermContainer->id(); print "$xtid\n"; # converting the id from HEX to decimal as xterm requires a decimal Id + my ($xtId) = sprintf hex $xtid; print "$xtId\n"; $mw->Button(-text => "Exit", -command => sub{ exit} )->pack( ); $mw->Button(-text => "Xterm", -command => sub{ system("xterm -into $xtId &") } )->pack( ); MainLoop();

The following Gtk2 script works with rxvt-unicode but not xterm , which loses keyboard

#!/usr/bin/perl # sample script to illustrate the -embed option # embed a rxvt inside another X app # see also pty-fd # doesn't handle sigchld use Gtk2; init Gtk2; my $window = new Gtk2::Window 'toplevel'; $window ->signal_connect( 'destroy' => sub{ Gtk2->main_quit; return FALSE; } ); my $frame = new Gtk2::Frame "embedded rxvt-unicode terminal"; $window->add ($frame); my $rxvt = new Gtk2::Socket; $frame->add ($rxvt); $frame->set_size_request (700, 400); $window->show_all; my $xid = $rxvt->window->get_xid; # works with rxvt but xterm loses keyboard focus system "./rxvt -embed $xid &"; #system "xterm -into $xid &"; $window->show_all; main Gtk2;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to xterm keyboard focus problem when embeded by zentara

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.