From b45cd6d1106c932c32e44943051de750fbe5418d Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Tue, 23 Sep 2008 10:38:34 +1200 Subject: [PATCH] Get notification expiring working. Fixed by swapping Glib::Timeout for a POE delay, and including POE::Session so that the constants are available. --- lib/Display/Notifications.pm | 9 ++++++--- lib/Display/Plugins/MPD.pm | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Display/Notifications.pm b/lib/Display/Notifications.pm index 6c6d836..06f4744 100644 --- a/lib/Display/Notifications.pm +++ b/lib/Display/Notifications.pm @@ -1,7 +1,9 @@ package Display::Notifications; use Clutter; +use POE::Session; use Set::Object; +use strict; my $delay = 5; @@ -23,7 +25,7 @@ sub new { } sub add { - my ($self, $notification) = @_; + my ($self, $kernel, $notification) = @_[OBJECT, KERNEL, ARG0]; my $block = Clutter::Group->new(); $block->set_opacity(0); @@ -54,7 +56,7 @@ sub add { my $effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_inc'); my $timeline = Clutter::Effect->fade($effect, $block, 255); - $self->{'kernel'}->delay_add('notifications_expire', $delay); + $kernel->delay_add(notifications_expire, $delay); $timeline->start(); } @@ -63,7 +65,7 @@ sub expire { my ($self) = @_[OBJECT]; for my $block ($self->{'blocks'}->members()) { - if ($block->expire <= time()) { + if ($block->{'expire'} <= time()) { $self->{'stage'}->remove($block->{'block'}); $self->{'blocks'}->remove($block); } @@ -73,6 +75,7 @@ sub expire { sub init { my $self = shift; + $self->{'kernel'}->state('notifications_add', $self, 'add'); $self->{'kernel'}->state('notifications_expire', $self, 'expire'); } diff --git a/lib/Display/Plugins/MPD.pm b/lib/Display/Plugins/MPD.pm index edb62c7..ca46ff2 100644 --- a/lib/Display/Plugins/MPD.pm +++ b/lib/Display/Plugins/MPD.pm @@ -3,7 +3,9 @@ package Display::Plugins::MPD; use Clutter; use Audio::MPD; use POSIX qw/strftime/; +use POE::Session; use base ('Display::Plugin'); +use strict; sub new { my $proto = shift; @@ -21,7 +23,7 @@ sub new { } sub display { - my $self = shift; + my ($self, $kernel) = @_[OBJECT, KERNEL]; my $current = $self->{'mpd'}->current(); @@ -35,20 +37,22 @@ sub display { $self->{'file'} = $current->file(); - $self->{'notifications'}->add($self->{'status'}); + $kernel->yield('notifications_add', $self->{'status'}); } - return 1; + $kernel->delay('mpd_display', 5); } sub init { my $self = shift; + $self->{'kernel'}->state('mpd_display', $self, 'display'); + $self->{'status'} = Clutter::Label->new('Sans 20', "Song\nAlbum"); $self->{'status'}->set_color(Clutter::Color->parse('White')); $self->{'status'}->set_ellipsize('end'); - Glib::Timeout->add_seconds(5, $self->can('display'), $self); + $self->{'kernel'}->delay('mpd_display', 5); } 1; -- 2.30.2