]> git.etc.gen.nz Git - picture-display.git/commitdiff
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 0405ca411f9cc63de2f9ae80d3cfb7b08a74e82a..bd31c06225f0aa9409d457a0bda469c0ccb45f64 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 2c7b208a8727c99a2f484e634ac1b19b71a5b9ab..8cdfe597738e393c95b797fc91ec7aeb68b7243b 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 ca46ff2e7edce649e17a0231a5a00b8822de13a3..8d81fe946c15ce0a69c5c00c8bcb635fbd7f2633 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;