Switch to using alarm instead of delay to stop skewing.
authorAndrew Ruthven <puck@catalyst.net.nz>
Mon, 22 Sep 2008 22:54:20 +0000 (10:54 +1200)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Mon, 22 Sep 2008 22:54:20 +0000 (10:54 +1200)
lib/Display/Plugin.pm
lib/Display/Plugins/FSpot.pm
lib/Display/Plugins/MPD.pm

index 0405ca4..bd31c06 100644 (file)
@@ -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;
index 2c7b208..8cdfe59 100644 (file)
@@ -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 {
index ca46ff2..8d81fe9 100644 (file)
@@ -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;