ptk_steal

Discussion in 'Perl Misc' started by JiggaHertz, Feb 7, 2005.

  1. JiggaHertz

    JiggaHertz Guest

    I'm trying to use the ptk_steal script that I found on the
    comp.lang.perl.tk group and I'm getting 2 individual windows instead of
    an xterm inside of a tk frame. Here's the output of xwininfo for those
    windows:

    # xwininfo

    xwininfo: Please select the window about which you
    would like information by clicking the
    mouse in that window.

    xwininfo: Window id: 0x1c0000d "WindowToSteal"

    Absolute upper-left X: 270
    Absolute upper-left Y: 270
    Relative upper-left X: 0
    Relative upper-left Y: 0
    Width: 499
    Height: 316
    Depth: 8
    Visual Class: PseudoColor
    Border width: 0
    Class: InputOutput
    Colormap: 0x34 (installed)
    Bit Gravity State: NorthWestGravity
    Window Gravity State: NorthWestGravity
    Backing Store State: NotUseful
    Save Under State: no
    Map State: IsViewable
    Override Redirect State: no
    Corners: +270+270 -831+270 -831-614 +270-614
    -geometry 80x24+264+240

    # xwininfo

    xwininfo: Please select the window about which you
    would like information by clicking the
    mouse in that window.

    xwininfo: Window id: 0x1b80004 "Ptk_steal"

    Absolute upper-left X: 16
    Absolute upper-left Y: 40
    Relative upper-left X: 0
    Relative upper-left Y: 0
    Width: 96
    Height: 21
    Depth: 8
    Visual Class: PseudoColor
    Border width: 0
    Class: InputOutput
    Colormap: 0x34 (installed)
    Bit Gravity State: NorthWestGravity
    Window Gravity State: NorthWestGravity
    Backing Store State: NotUseful
    Save Under State: no
    Map State: IsViewable
    Override Redirect State: no
    Corners: +16+40 -1488+40 -1488-1139 +16-1139
    -geometry 96x21+10+10


    I've verified that the window id from the xterm "WindowToSteal" is
    correct. I included the ptk_steal.pl script as reference. Any help
    would be greatly appreciated.

    Thanks,
    JH

    ==================================================================

    #!/usr/bin/perl
    # $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.
    # Mail: -berlin.de
    # WWW: http://user.cs.tu-berlin.de/~eserte/#
    use Tk;
    use X11::protocol;

    $x = X11::protocol->new();
    $top = MainWindow->new;

    system("xterm -name WindowToSteal &");

    $check = $top->repeat(
    50,
    sub {
    $wid = get_window_by_name("WindowToSteal");
    }
    );

    while ( !defined $wid ) {
    $top->waitVariable( \$wid );
    }

    $check->cancel;

    warn sprintf("Window id: %x\n", $wid);
    $top->geometry("+10+10");
    $top->Label( -text => "A xterm:" )->pack;
    if ( $Tk::VERSION >= 800 ) {
    $f = $top->Frame( '-container' => 1 )->pack;
    }

    else {
    $f = $top->Frame( -width => 500, -height => 400 )->pack;

    }
    warn sprintf("Resized main frame\n");
    $f->update;
    warn sprintf("Updated main frame\n");
    $test = $x->ReparentWindow( $wid, oct( $f->id ), 0, 0 );
    $x->MapWindow($wid);
    warn sprintf("Reparent Window done\n");
    warn sprintf("test = $test\n");
    sub get_window_by_name {
    _get_window_by_name( $x->{'root'}, $_[0] );

    }

    sub _get_window_by_name {
    my ( $root, $searchname ) = @_;
    my ( $dummy, $dummy2, @new_kids ) = $x->QueryTree($root);
    foreach my $k (@new_kids) {
    my $atomnr;

    #warn sprintf("%x\n", $k);
    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;

    }

    MainLoop;
    __END__
     
    JiggaHertz, Feb 7, 2005
    #1
    1. Advertising

  2. JiggaHertz

    JiggaHertz Guest

    zentara wrote:
    > On Mon, 07 Feb 2005 10:03:47 -0500, JiggaHertz <>
    > wrote:
    >
    >
    >>I'm trying to use the ptk_steal script that I found on the
    >>comp.lang.perl.tk group and I'm getting 2 individual windows instead of
    >>an xterm inside of a tk frame. Here's the output of xwininfo for those
    >>windows:

    >
    >
    > From what you are saying, you want an xterm in a Tk window. The script
    > you refer to does something different.
    >
    > Here is what you want:
    > #!/usr/bin/perl -w

    <code removed>
    > system("xterm -into $xtId &");

    <code removed>

    The xterm on my system doesn't allow a -into command line switch. Also
    I was hoping to generalize this to embed other application windows.

    Thanks for your help,
    JH
     
    JiggaHertz, Feb 8, 2005
    #2
    1. Advertising

  3. JiggaHertz

    Chris Guest

    If you don't mind having the xterm temporarily come up in its own
    window, a different approach may be easier for you: let the xterm, et
    al, create its window "as usual," then REPARENT it into the desired
    "container" window in your app.

    All YOUR code needs to do is launch the xterm, find its top-level
    window (left as an exercise for the reader), and reparent it into the
    window of your desired container. I imagine you would have to find
    ways to deal with resize, reconfigure, etc. events on the container
    window, but... this should get you at least MOST of the way to where
    you want to be.

    Your mileage may vary.

    Chris
     
    Chris, Feb 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page