summaryrefslogtreecommitdiff
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
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
-rw-r--r--lib/App/XScreenSaver/DBus.pm25
-rw-r--r--lib/App/XScreenSaver/DBus/Lock.pm111
-rw-r--r--lib/App/XScreenSaver/DBus/Logind.pm (renamed from lib/App/XScreenSaver/DBus/InhibitSleep.pm)38
3 files changed, 40 insertions, 134 deletions
diff --git a/lib/App/XScreenSaver/DBus.pm b/lib/App/XScreenSaver/DBus.pm
index db9355f..60b12db 100644
--- a/lib/App/XScreenSaver/DBus.pm
+++ b/lib/App/XScreenSaver/DBus.pm
@@ -4,9 +4,8 @@ use Moo;
use experimental qw(signatures postderef);
use Net::DBus::Reactor;
use Log::Any;
-use App::XScreenSaver::DBus::InhibitSleep;
+use App::XScreenSaver::DBus::Logind;
use App::XScreenSaver::DBus::Saver;
-use App::XScreenSaver::DBus::Lock;
# VERSION
# ABSTRACT: main application class
@@ -26,15 +25,15 @@ has reactor => (
builder => sub { Net::DBus::Reactor->main() },
);
-=attr C<inhibit_sleep>
+=attr C<logind>
-instance of L<< C<App::XScreenSaver::DBus::InhibitSleep> >>.
+instance of L<< C<App::XScreenSaver::DBus::Logind> >>.
=cut
-has inhibit_sleep => (
+has logind => (
is => 'lazy',
- builder => sub { App::XScreenSaver::DBus::InhibitSleep->new() },
+ builder => sub { App::XScreenSaver::DBus::Logind->new() },
);
=attr C<saver>
@@ -50,17 +49,6 @@ has saver => (
},
);
-=attr C<lock>
-
-instance of L<< C<App::XScreenSaver::DBus::Lock> >>.
-
-=cut
-
-has lock => (
- is => 'lazy',
- builder => sub { App::XScreenSaver::DBus::Lock->new() },
-);
-
=attr C<log>
a logger
@@ -77,9 +65,8 @@ not return
=cut
sub run($self) {
- $self->inhibit_sleep->start();
+ $self->logind->start();
$self->saver->start();
- $self->lock->start();
$self->reactor->run;
}
diff --git a/lib/App/XScreenSaver/DBus/Lock.pm b/lib/App/XScreenSaver/DBus/Lock.pm
deleted file mode 100644
index 22410f2..0000000
--- a/lib/App/XScreenSaver/DBus/Lock.pm
+++ /dev/null
@@ -1,111 +0,0 @@
-package App::XScreenSaver::DBus::Lock;
-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 "session lock" protocol
-
-=head1 SYNOPSIS
-
- use Net::DBus::Reactor;
- use App::XScreenSaver::DBus::Lock;
- my $is = App::XScreenSaver::DBus::Lock->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<session_obj>
-
-the (e)logind session DBus object
-
-=cut
-
-has session_obj => (
- is => 'lazy',
- builder => sub($self) {
- my $session_path = $self->logind_obj->GetSessionByPID($$);
- return $self->logind_srv->get_object($session_path);
- },
-);
-
-=attr C<log>
-
-a logger
-
-=cut
-
-has log => ( is => 'lazy', builder => sub { Log::Any->get_logger } );
-
-=method C<start>
-
-starts listening to the C<Lock> and C<Unlock> signals from the
-session, and activates the screen saver
-
-=cut
-
-sub start($self) {
- $self->session_obj->connect_to_signal(
- 'Lock',
- $self->curry::weak::_lock,
- );
- $self->session_obj->connect_to_signal(
- 'Unlock',
- $self->curry::weak::_unlock,
- );
- return;
-}
-
-sub _lock($self) {
- $self->_xscreensaver_command('-lock');
-}
-
-sub _unlock($self) {
- $self->_xscreensaver_command('-deactivate');
-}
-
-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;
diff --git a/lib/App/XScreenSaver/DBus/InhibitSleep.pm b/lib/App/XScreenSaver/DBus/Logind.pm
index 226facf..b8abad3 100644
--- a/lib/App/XScreenSaver/DBus/InhibitSleep.pm
+++ b/lib/App/XScreenSaver/DBus/Logind.pm
@@ -1,4 +1,4 @@
-package App::XScreenSaver::DBus::InhibitSleep;
+package App::XScreenSaver::DBus::Logind;
use v5.20;
use Moo;
use experimental qw(signatures postderef);
@@ -7,13 +7,13 @@ use Net::DBus;
use IPC::Run;
use Log::Any;
# VERSION
-# ABSTRACT: implements the logind "inhibitor locks" protocol
+# ABSTRACT: implements the logind "inhibitor locks" and "session lock" protocols
=head1 SYNOPSIS
use Net::DBus::Reactor;
- use App::XScreenSaver::DBus::InhibitSleep;
- my $is = App::XScreenSaver::DBus::InhibitSleep->new;
+ use App::XScreenSaver::DBus::Logind;
+ my $is = App::XScreenSaver::DBus::Logind->new;
$is->start;
Net::DBus::Reactor->new->run;
@@ -48,6 +48,20 @@ has logind_obj => (
builder => sub { shift->logind_srv->get_object('/org/freedesktop/login1') },
);
+=attr C<session_obj>
+
+the (e)logind session DBus object
+
+=cut
+
+has session_obj => (
+ is => 'lazy',
+ builder => sub($self) {
+ my $session_path = $self->logind_obj->GetSessionByPID($$);
+ return $self->logind_srv->get_object($session_path);
+ },
+);
+
=attr C<inhibit_fd>
the file descriptor that logind gives us when we ask for a lock; we
@@ -77,6 +91,14 @@ sub start($self) {
'PrepareForSleep',
$self->curry::weak::_going_to_sleep,
);
+ $self->session_obj->connect_to_signal(
+ 'Lock',
+ $self->curry::weak::_lock,
+ );
+ $self->session_obj->connect_to_signal(
+ 'Unlock',
+ $self->curry::weak::_unlock,
+ );
$self->_inhibit();
return;
}
@@ -109,6 +131,14 @@ sub _going_to_sleep($self,$before) {
return;
}
+sub _lock($self) {
+ $self->_xscreensaver_command('-lock');
+}
+
+sub _unlock($self) {
+ $self->_xscreensaver_command('-deactivate');
+}
+
sub _xscreensaver_command($self,$command) {
my ($out, $err);
IPC::Run::run(