use Gtk2 '-init';
use Glib qw/TRUE FALSE/;

my $wait_destroy;

sub focus_out {
	print "focus out\n";
	undef $wait_destroy;
}

my $entry = Gtk2::Entry->new;
$entry->signal_connect( focus_out_event => sub {
	my $wait_destroy = Glib::Timeout->add( 5, \&focus_out );
	return FALSE;
} );

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect( destroy => sub {
	Glib::Source->remove( $wait_destroy ) if defined $wait_destroy;
	print "destroy\n";
	Gtk2->main_quit();
} );
$window->add($entry);
$window->show_all;

Gtk2->main;
