I'm using Perl Gtk2, and I want to see the list of open toplevel windows, using:
my @WL = Gtk2::Window->list_toplevels;
print STDOUT "TOP_WINDOWS:\n @WL\n";
TOP_WINDOWS:
Gtk2::Window=HASH(0x23a4040) Gtk2::Window=HASH(0x23b5628) Gtk2::Window=HASH(0x1ca6238)
When I dump this list:
print STDOUT "DUMPER:\n", Dumper (@WL);
... it yields this:
DUMPER:
$VAR1 = bless( {}, 'Gtk2::Window' );
$VAR2 = bless( {}, 'Gtk2::Window' );
$VAR3 = bless( {}, 'Gtk2::Window' );
How do I process the above bless objects/value? I'm looking to get the name (or some kind of unique indicator) of each of the top_level window.
FOLLOW-UP QUSTION: The following doesn't work for "state" when I have additional widgets inside the toplevel - I got to believe I'm simply missing something here!
sub SM_callback ()
{
my ($button, $data) = @_;
my $DS = $$data[0];
my $hostname = $$data[1];
state $DW;
if ( ! $DW )
{
$DW = Gtk2::Window->new('toplevel');
$DW->set_default_size(400, 200);
$DW->set_title($hostname);
my $VB = Gtk2::VBox->new( 0, 0 );
$DW->add($VB);
my $TB = Gtk2::TextBuffer->new();
$TB->set_text($hostname);
my $TV = Gtk2::TextView->new_with_buffer($TB);
my $SW = Gtk2::ScrolledWindow->new( undef, undef );
$SW->add($TV);
$VB->add($SW);
$DW->show_all;
}
else
{
$DW->present;
}
}
Here's my final solution:
By looping thru the list_toplevels in call_back funct, and if top_level window is already opened (or minimized) via checking get_name, then present it, otherwise create the new top_level window (and set_name for future checking).