Playing with desktop notification candies, I tripped over an annoying problem: how to properly use Gtk2::Notify in order to get appropriate closed signals for each such notification object?

Currently, all I get is only the signal for first notification.

Here's the test code:
#!/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 ge +ts 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_co +nnect'; $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; }

Sample output ("signal_connect"):

$ ./on-close.pl
1169969648.259 Showing note 1
1169969648.26891 Showing note 2
1169969648.2776 Showing note 3
1169969649.35453 Closing note 1

Use ^C to exit Gtk loop, as no signals will be received upon closing next notifications.

Sample output ("signal_add_emission_hook"):

$ ./on-close.pl 1
1169969850.63043 Showing note 1
1169969850.63678 Showing note 2
1169969850.6449 Showing note 3
1169969851.63109 Closing note 1
1169969851.63122 Closing note 2
1169969851.63133 Closing note 3

Closing too fast. Notification windows were not really closed yet when receiving those signals.

Environment details:

GNU/Linux 2.6.19
perl 5.8.8 (i386-linux-thread-multi)
glib 2.12.9
gtk2 2.10.8
dbus 1.0.1
libnotify 0.4.3
notification-daemon 0.3.6
Gtk2 1.142
Glib 1.142
Gtk2::Notify 0.02

TIA

UPDATES:
--
AltBlue.

In reply to "onClose" for multiple Gtk2::Notify objects by AltBlue

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.