--- /dev/null
+package Display::Plugin;
+
+# Provide a base class that does common things for all the plugins.
+use Clutter;
+
+sub new {
+ my ($class,$kernel,$session,$stage) = @_;
+
+ my $self = {
+ 'kernel' => $kernel,
+ 'session' => $session,
+ 'stage' => $stage,
+ };
+
+ bless ($self, $class);
+ $self->init();
+ return $self;
+}
+
+1;
use Clutter;
use POSIX qw/strftime/;
+use base ('Display::Plugin');
sub new {
- my ($class,$stage) = @_;
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
- my $self = {
- 'stage' => $stage,
- };
+ my $self = $class->SUPER::new(@_);
bless ($self, $class);
$self->init();
$self->{'clock'}->set_text(strftime("%H:%M %d/%m/%Y", localtime(time)));
Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self);
-
- return 0;
+ $self->{'kernel'}->delay_set(clock_display, 60 - strftime(%s, localtime()));
}
sub init {
my $self = shift;
+ $self->{'kernel'}->state('clock_display', $self, 'display');
+
$self->{'clock'} = Clutter::Label->new('Sans 20', strftime("%H:%M %d/%m/%Y", localtime(time)));
$self->{'clock'}->set_anchor_point($self->{'clock'}->get_width(), 1);
$self->{'clock'}->set_position($self->{'stage'}->get_width() - 20, 15);
$self->{'stage'}->add($self->{'bg'});
$self->{'stage'}->add($self->{'clock'});
- Glib::Timeout->add_seconds(60 - strftime(%s, localtime()), $self->can('display'), $self);
+ $self->{'kernel'}->delay_set(clock_display, 60 - strftime(%s, localtime()));
}
1;
package Display::Plugins::FSpot;
-use DBI;
use Clutter;
+use base ('Display::Plugin');
my $f_spot_db = "/home/andrew/.gnome2/f-spot/photos.db";
sub new {
- my ($class,$stage) = @_;
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
- my $self = {
- 'stage' => $stage,
- 'last_file' => '',
- };
+ my $self = $class->SUPER::new(@_);
+
+ $self->{'last_file'} = '';
bless ($self, $class);
$self->init();
fade_in($self->{'new'});
# } else {
#warn "Fade out old\n";
-# my $old_effect = Clutter::EffectTemplate->new_for_duration(1000, 'smoothstep_dec' );
+# my $old_effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_dec' );
# my $old = Clutter::Effect->fade($old_effect, $self->{'old'}, 0, $self->can('fade_in'), $self->{'new'});
# $old->start();
}
# $self->{'new'} = $temp;
$self->{'last_file'} = $file;
+ $self->{'kernel'}->delay_set(fspot_display => 30);
return 1;
}
sub fade_in {
my $new_pic = shift;
- my $new_effect = Clutter::EffectTemplate->new_for_duration(1000, 'smoothstep_inc');
+ my $new_effect = Clutter::EffectTemplate->new_for_duration(1000, 'main::smoothstep_inc');
my $new = Clutter::Effect->fade($new_effect, $new_pic, 255);
$new->start();
}
sub init {
my $self = shift;
+ $self->{'kernel'}->state('fspot_display', $self, 'display');
+
$self->{'dbh'} = DBI->connect("dbi:SQLite:dbname=$f_spot_db","","")
|| die "Failed to connect to $f_spot_db: $DBI::errstr\n";
$self->{'stage'}->add($self->{$age});
}
- Glib::Timeout->add_seconds(30, $self->can('display'), $self);
+ $self->{'kernel'}->delay_set(fspot_display => 30);
}
1;
use Clutter;
use Audio::MPD;
use POSIX qw/strftime/;
+use base ('Display::Plugin');
sub new {
- my ($class,$stage) = @_;
-
- my $self = {
- 'stage' => $stage,
- 'mpd' => Audio::MPD->new(),
- 'file' => '',
- 'active'=> 0,
- };
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+
+ my $self = $class->SUPER::new(@_);
+
+ $self->{'mpd'} = Audio::MPD->new();
+ $self->{'file'} = '';
+ $self->{'active'} = 0;
bless ($self, $class);
$self->init();
use FindBin;
use Module::Pluggable search_path => ['Display::Plugins'];
use Clutter qw( :init );
+use Glib;
+use POE qw(Loop::Glib);
use Getopt::Long;
use lib "$FindBin::Bin/lib";
'full|f!' => \$full_screen,
);
-my $stage = Clutter::Stage->get_default();
-$stage->set_color(Clutter::Color->parse('Black'));
-$stage->signal_connect('key-press-event' => sub { Clutter->main_quit() });
+my $session = POE::Session->create (
+ inline_states => {
+ _start => \&start,
+ },
+);
-if ($full_screen) {
- $stage->fullscreen;
-} else {
- $stage->set_size(800, 600);
-}
+$poe_kernel->run;
-my @modules = loadModules();
+#Clutter->main();
-$stage->show_all();
+sub start {
+ my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
-Clutter->main();
+ my $stage = Clutter::Stage->get_default();
+ $stage->set_color(Clutter::Color->parse('Black'));
+ $stage->signal_connect('key-press-event' => sub { Clutter->main_quit() });
-sub update_screen {
- for my $module (@modules) {
- $module->display();
+ if ($full_screen) {
+ $stage->fullscreen;
+ } else {
+ $stage->set_size(800, 600);
}
+
+ my @modules = loadModules($kernel, $session, $stage);
+
+ $stage->show_all();
}
+
sub loadModules {
+ my ($kernel, $session, $stage) = @_;
my @modules;
for my $module (plugins()) {
warn "Considering $module\n";
eval "use $module";
if ($@) {
- die "Failed to load plugin: $module ($@)\n";
+ warn "Failed to load plugin: $module ($@)\n";
+ } else {
+ push @modules, $module->new($kernel, $session, $stage);
}
-
- push @modules, $module->new($stage);
}
return @modules;