#! /usr/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/; 
use Gtk2::Gdk::Keysyms;

my $window = Gtk2::Window->new('popup');
#works ok with toplevel
#my $window = Gtk2::Window->new('toplevel');

$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_border_width(5);
$window->set_position('center_always');

my $vbox = &ret_vbox();

#add and show the vbox
$window->add($vbox);
$window->show();

#when $window is a popup, it passes keys to the controlling terminal
$window->signal_connect( 'key_release_event' => \&keyrelease );

Gtk2->main();
###########################################################################
sub ret_vbox {

my $vbox = Gtk2::VBox->new(FALSE,5);
$vbox->set_size_request (300, 300);

my $eventbox = Gtk2::EventBox->new();

$eventbox->signal_connect('button-release-event' => sub {
		my ($widget,$event) = @_;		
		my $button_nr = $event->button;
		print "$button_nr\n";
	    });

#dosn't seem to catch a key release 
$eventbox->signal_connect('key-release-event' => sub {
		my ($widget,$event) = @_;		
		print "$widget $event\n";
		my $key_nr = $event->key;
		print "$key_nr\n";
	});

$vbox->pack_start($eventbox,TRUE,TRUE,0);
$vbox->show_all();
return $vbox;
}
#########################################################################
sub keyrelease {
    my ( $widget, $event ) = @_;
    if ( $event->keyval == $Gtk2::Gdk::Keysyms{q} ) {
        Gtk2->main_quit;
    }
    else {
        print "key was ", chr( $event->keyval ), "\n";
    }

}


