forking a new mainwindow from a module



Hi,
In Tk, I was able to make a module which forked and opened a new
Tk mainwindow, to display the parent's pid and mem usage.

I'm trying to do the same thing with Gtk2, but I am getting crashes,
with the error:

Xlib: unexpected async reply (sequence 0xd7)!
The program 'ztest' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadRequest (invalid request code or no such operation)'.
  (Details: serial 218 error_code 1 request_code 0 minor_code 0)

If I call the module from a Tk, or commandline program, the Gtk2 window
opens fine. It crashes when I call it from a Gtk2 program.

This is GMeM.pm  placed in PERL5LIB
##################################################
package GMeM;
use warnings;
use strict;

my $pid =$$;
print "$pid\n";

if (fork() == 0) {
    print "forked ok\n";
    use Gtk2 '-init';

    my $win = Gtk2::Window->new('toplevel');
    $win->signal_connect( 'destroy' => \&delete_event );

    my ($xscr, $yscr) = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height);
    $win->move($xscr - 80, $yscr - 15);

    my $lab = Gtk2::Label->new("PID: $pid->      " );
    my $font = Gtk2::Pango::FontDescription->from_string("Sans Bold 14");
    $lab->modify_font($font);

    $win->add($lab);
    $win->show_all();

    Gtk2->main;
#####################################  
sub delete_event { Gtk2->main_quit; return 0; }

}
1;
########################################################

and here is a Gtk2 test program which crashes:
#############################################
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use GMeM;

my $window = Gtk2::Window->new('toplevel');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_title('GMeM-test');
$window->set_size_request(300,200);

my $button = Gtk2::Button->new_from_stock('gtk-quit');
$window->add( $button);
$button->signal_connect( clicked => \&delete_event );

$window->show_all();
Gtk2->main;
##################################### 
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
#####################################################

Any ideas on what I can do to fix this?

Thanks.

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]