summaryrefslogtreecommitdiff
path: root/lib/App/XScreenSaver/DBus/InhibitSleep.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/XScreenSaver/DBus/InhibitSleep.pm')
-rw-r--r--lib/App/XScreenSaver/DBus/InhibitSleep.pm61
1 files changed, 56 insertions, 5 deletions
diff --git a/lib/App/XScreenSaver/DBus/InhibitSleep.pm b/lib/App/XScreenSaver/DBus/InhibitSleep.pm
index 44f84bc..b419f50 100644
--- a/lib/App/XScreenSaver/DBus/InhibitSleep.pm
+++ b/lib/App/XScreenSaver/DBus/InhibitSleep.pm
@@ -4,31 +4,82 @@ use experimental 'signatures';
use curry;
use Net::DBus;
use Log::Any;
+# VERSION
+# ABSTRACT: implements the logind "inhibitor locks" protocol
+
+=head1 SYNOPSIS
+
+ use Net::DBus::Reactor;
+ use App::XScreenSaver::DBus::InhibitSleep;
+ my $is = App::XScreenSaver::DBus::InhibitSleep->new;
+ $is->start;
+
+ Net::DBus::Reactor->new->run;
+
+=attr C<bus>
+
+the DBus system bus
+
+=cut
has bus => ( is => 'lazy', builder => sub { Net::DBus->system() } );
+
+=attr C<logind_srv>
+
+the (e)logind DBus service
+
+=cut
+
has logind_srv => (
is => 'lazy',
builder => sub { shift->bus->get_service('org.freedesktop.login1') },
);
+
+=attr C<logind_obj>
+
+the (e)logind DBus object
+
+=cut
+
has logind_obj => (
is => 'lazy',
builder => sub { shift->logind_srv->get_object('/org/freedesktop/login1') },
);
+=attr C<inhibit_fd>
+
+the file descriptor that logind gives us when we ask for a lock; we
+close it to release the lock
+
+=cut
+
has inhibit_fd => ( is => 'rwp' );
+=attr C<log>
+
+a logger
+
+=cut
+
has log => ( is => 'lazy', builder => sub { Log::Any->get_logger } );
+=method C<start>
+
+starts listening to the C<PrepareForSleep> signal from (e)logind, and
+takes the lock
+
+=cut
+
sub start($self) {
$self->logind_obj->connect_to_signal(
'PrepareForSleep',
- $self->curry::weak::going_to_sleep,
+ $self->curry::weak::_going_to_sleep,
);
- $self->inhibit();
+ $self->_inhibit();
return;
}
-sub inhibit($self) {
+sub _inhibit($self) {
return if $self->inhibit_fd;
$self->_set_inhibit_fd(
$self->logind_obj->Inhibit(
@@ -41,7 +92,7 @@ sub inhibit($self) {
return;
}
-sub going_to_sleep($self,$before) {
+sub _going_to_sleep($self,$before) {
if ($before) {
$self->log->debug('locking');
system(qw(xscreensaver-command -suspend));
@@ -51,7 +102,7 @@ sub going_to_sleep($self,$before) {
else {
$self->log->debug('woken up');
system(qw(xscreensaver-command -deactivate));
- $self->inhibit();
+ $self->_inhibit();
}
return;
}