"onClose" for multiple Gtk2::Notify objects
- From: "Marius Feraru" <altblue gmail com>
- To: gtk-perl-list gnome org
- Subject: "onClose" for multiple Gtk2::Notify objects
- Date: Sun, 28 Jan 2007 22:59:48 +0200
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 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;
}
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
--
altblue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]