#!/usr/bin/perl -l use strict; use warnings; use Time::HiRes (); use Gtk2::Notify -init, 'onCloseTest'; # testing 101: use "signal_connect" or "signal_add_emission_hook"? # - "signal_connect" sounds reasonable, but only first notification gets it # - "signal_add_emission_hook" triggers "closed" signals way too early my $use_emission_hook = scalar @ARGV; # notifications cache my %notes = (); # generate some notifications for my $id ( 1 .. 3 ) { my $n = $notes{$id} = Gtk2::Notify->new( 'summary ' . $id, 'body ' . $id ); $n->set_timeout( $id * 1000 ); my $hook_method = $use_emission_hook ? 'signal_add_emission_hook' : 'signal_connect'; $n->$hook_method( closed => \&closed, $id ); $n->show; print Time::HiRes::time, ' Showing note ', $id; } Gtk2->main; # "onClose" handler sub closed { shift if $use_emission_hook; # skip "hints" my ($n, $id) = @_; print Time::HiRes::time, ' Closing note ', $id; delete $notes{$id}; Gtk2->main_quit if !%notes; return; }