summaryrefslogtreecommitdiff
path: root/lib/App/XScreenSaver/DBus/InhibitSleep.pm
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2021-05-06 15:08:15 +0100
committerdakkar <dakkar@thenautilus.net>2021-05-06 15:08:15 +0100
commit67d30e007b8f2b2ee10529bc76460adcdf7e6c10 (patch)
treed8ca512b022503b4379197051fa02db83ff51122 /lib/App/XScreenSaver/DBus/InhibitSleep.pm
parentlock the screen when logind says so (diff)
downloadxscreensaver-dbus-67d30e007b8f2b2ee10529bc76460adcdf7e6c10.tar.gz
xscreensaver-dbus-67d30e007b8f2b2ee10529bc76460adcdf7e6c10.tar.bz2
xscreensaver-dbus-67d30e007b8f2b2ee10529bc76460adcdf7e6c10.zip
compact the code
Diffstat (limited to 'lib/App/XScreenSaver/DBus/InhibitSleep.pm')
-rw-r--r--lib/App/XScreenSaver/DBus/InhibitSleep.pm123
1 files changed, 0 insertions, 123 deletions
diff --git a/lib/App/XScreenSaver/DBus/InhibitSleep.pm b/lib/App/XScreenSaver/DBus/InhibitSleep.pm
deleted file mode 100644
index 226facf..0000000
--- a/lib/App/XScreenSaver/DBus/InhibitSleep.pm
+++ /dev/null
@@ -1,123 +0,0 @@
-package App::XScreenSaver::DBus::InhibitSleep;
-use v5.20;
-use Moo;
-use experimental qw(signatures postderef);
-use curry;
-use Net::DBus;
-use IPC::Run;
-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->_inhibit();
- return;
-}
-
-sub _inhibit($self) {
- return if $self->inhibit_fd;
- $self->_set_inhibit_fd(
- $self->logind_obj->Inhibit(
- 'sleep',
- 'xscreensaver','locking before sleep',
- 'delay',
- )
- );
- $self->log->debugf('got logind inhibit fd %d',$self->inhibit_fd);
- return;
-}
-
-sub _going_to_sleep($self,$before) {
- if ($before) {
- $self->log->debug('locking');
- $self->_xscreensaver_command('-suspend');
- $self->log->debug('locked');
- $self->_set_inhibit_fd(undef);
- }
- else {
- $self->log->debug('woken up');
- $self->_xscreensaver_command('-deactivate');
- $self->_inhibit();
- }
- return;
-}
-
-sub _xscreensaver_command($self,$command) {
- my ($out, $err);
- IPC::Run::run(
- ['xscreensaver-command',$command],
- \undef, \$out, \$err,
- );
- $self->log->tracef('xscreensaver-command %s said <%s>',$command,$out);
- $self->log->warnf('xscreensaver-command %s errored <%s>',$command,$err)
- if $err;
-}
-
-1;