From: Andrew Ruthven Date: Mon, 22 Sep 2008 22:54:20 +0000 (+1200) Subject: Switch to using alarm instead of delay to stop skewing. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b32e3d82aa9ac4055b461659e89b4bdcfe8c7ab8;p=picture-display.git Switch to using alarm instead of delay to stop skewing. --- diff --git a/lib/Display/Plugin.pm b/lib/Display/Plugin.pm index 0405ca4..bd31c06 100644 --- a/lib/Display/Plugin.pm +++ b/lib/Display/Plugin.pm @@ -19,4 +19,20 @@ sub new { return $self; } +sub init_delay { + my ($self, $delay, $event) = @_; + + $self->{'_next_check'} = time(); + $self->{'_next_delay'} = $delay; + $self->{'_next_event'} = $event; +} + +sub delay { + my $self = shift; + + $self->{'_next_check'} += $self->{'_next_delay'}; + + $self->{'kernel'}->alarm( $self->{'_next_event'} => $self->{'_next_check'} ); +} + 1; diff --git a/lib/Display/Plugins/FSpot.pm b/lib/Display/Plugins/FSpot.pm index 2c7b208..8cdfe59 100644 --- a/lib/Display/Plugins/FSpot.pm +++ b/lib/Display/Plugins/FSpot.pm @@ -17,6 +17,7 @@ sub new { $self->{'last_file'} = ''; bless ($self, $class); + $self->init_delay($delay, 'fspot_display'); $self->init(); return $self; } @@ -49,7 +50,7 @@ warn "Fade out old\n"; } $self->{'last_file'} = $file; - $self->{'kernel'}->delay(fspot_display, $delay); + $self->delay(); } sub fade_in { diff --git a/lib/Display/Plugins/MPD.pm b/lib/Display/Plugins/MPD.pm index ca46ff2..8d81fe9 100644 --- a/lib/Display/Plugins/MPD.pm +++ b/lib/Display/Plugins/MPD.pm @@ -7,6 +7,8 @@ use POE::Session; use base ('Display::Plugin'); use strict; +my $delay = 5; + sub new { my $proto = shift; my $class = ref($proto) || $proto; @@ -18,6 +20,7 @@ sub new { $self->{'active'} = 0; bless ($self, $class); + $self->init_delay($delay, 'mpd_display'); $self->init(); return $self; } @@ -40,7 +43,7 @@ sub display { $kernel->yield('notifications_add', $self->{'status'}); } - $kernel->delay('mpd_display', 5); + $self->delay(); } sub init { @@ -52,7 +55,7 @@ sub init { $self->{'status'}->set_color(Clutter::Color->parse('White')); $self->{'status'}->set_ellipsize('end'); - $self->{'kernel'}->delay('mpd_display', 5); + $self->{'kernel'}->yield('mpd_display'); } 1;