summaryrefslogtreecommitdiff
path: root/lib/App
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/XScreenSaver/DBus.pm20
-rw-r--r--lib/App/XScreenSaver/DBus/Logind.pm (renamed from lib/App/XScreenSaver/DBus/InhibitSleep.pm)45
-rw-r--r--lib/App/XScreenSaver/DBus/Saver.pm22
-rw-r--r--lib/App/XScreenSaver/DBus/SaverProxy.pm41
4 files changed, 61 insertions, 67 deletions
diff --git a/lib/App/XScreenSaver/DBus.pm b/lib/App/XScreenSaver/DBus.pm
index 86a6368..907739f 100644
--- a/lib/App/XScreenSaver/DBus.pm
+++ b/lib/App/XScreenSaver/DBus.pm
@@ -4,10 +4,10 @@ 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;
-our $VERSION = '1.0.2'; # VERSION
-# ABSTRACT: main application class
+our $VERSION = '1.0.5'; # VERSION
+# ABSTRACT: tie xscreensaver into dbus
has reactor => (
@@ -16,9 +16,9 @@ has reactor => (
);
-has inhibit_sleep => (
+has logind => (
is => 'lazy',
- builder => sub { App::XScreenSaver::DBus::InhibitSleep->new() },
+ builder => sub { App::XScreenSaver::DBus::Logind->new() },
);
@@ -34,7 +34,7 @@ has log => ( is => 'lazy', builder => sub { Log::Any->get_logger } );
sub run($self) {
- $self->inhibit_sleep->start();
+ $self->logind->start();
$self->saver->start();
$self->reactor->run;
}
@@ -49,11 +49,11 @@ __END__
=head1 NAME
-App::XScreenSaver::DBus - main application class
+App::XScreenSaver::DBus - tie xscreensaver into dbus
=head1 VERSION
-version 1.0.2
+version 1.0.5
=head1 SYNOPSIS
@@ -66,9 +66,9 @@ version 1.0.2
the event loop
-=head2 C<inhibit_sleep>
+=head2 C<logind>
-instance of L<< C<App::XScreenSaver::DBus::InhibitSleep> >>.
+instance of L<< C<App::XScreenSaver::DBus::Logind> >>.
=head2 C<saver>
diff --git a/lib/App/XScreenSaver/DBus/InhibitSleep.pm b/lib/App/XScreenSaver/DBus/Logind.pm
index 284ff47..45de75f 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);
@@ -6,8 +6,8 @@ use curry;
use Net::DBus;
use IPC::Run;
use Log::Any;
-our $VERSION = '1.0.2'; # VERSION
-# ABSTRACT: implements the logind "inhibitor locks" protocol
+our $VERSION = '1.0.5'; # VERSION
+# ABSTRACT: implements the logind "inhibitor locks" and "session lock" protocols
has bus => ( is => 'lazy', builder => sub { Net::DBus->system() } );
@@ -25,6 +25,15 @@ has logind_obj => (
);
+has session_obj => (
+ is => 'lazy',
+ builder => sub($self) {
+ my $session_path = $self->logind_obj->GetSessionByPID($$);
+ return $self->logind_srv->get_object($session_path);
+ },
+);
+
+
has inhibit_fd => ( is => 'rwp' );
@@ -36,6 +45,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;
}
@@ -68,6 +85,16 @@ sub _going_to_sleep($self,$before) {
return;
}
+sub _lock($self) {
+ $self->log->debugf('locking the screen');
+ $self->_xscreensaver_command('-lock');
+}
+
+sub _unlock($self) {
+ $self->log->debugf('unlocking the screen');
+ $self->_xscreensaver_command('-deactivate');
+}
+
sub _xscreensaver_command($self,$command) {
my ($out, $err);
IPC::Run::run(
@@ -89,17 +116,17 @@ __END__
=head1 NAME
-App::XScreenSaver::DBus::InhibitSleep - implements the logind "inhibitor locks" protocol
+App::XScreenSaver::DBus::Logind - implements the logind "inhibitor locks" and "session lock" protocols
=head1 VERSION
-version 1.0.2
+version 1.0.5
=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;
@@ -118,6 +145,10 @@ the (e)logind DBus service
the (e)logind DBus object
+=head2 C<session_obj>
+
+the (e)logind session DBus object
+
=head2 C<inhibit_fd>
the file descriptor that logind gives us when we ask for a lock; we
diff --git a/lib/App/XScreenSaver/DBus/Saver.pm b/lib/App/XScreenSaver/DBus/Saver.pm
index 196c418..c36bece 100644
--- a/lib/App/XScreenSaver/DBus/Saver.pm
+++ b/lib/App/XScreenSaver/DBus/Saver.pm
@@ -7,7 +7,7 @@ use Log::Any;
use Try::Tiny;
use IPC::Run;
use App::XScreenSaver::DBus::SaverProxy;
-our $VERSION = '1.0.2'; # VERSION
+our $VERSION = '1.0.5'; # VERSION
# ABSTRACT: implements the "idle inhibition" protocol
@@ -46,28 +46,24 @@ has paths => (
has log => ( is => 'lazy', builder => sub { Log::Any->get_logger } );
-has _impls => ( is => 'rw' );
+has _proxies => ( is => 'rw' );
has _prod_id => ( is => 'rw' );
has _inhibits => ( is => 'rw', default => sub { +{} } );
sub start($self) {
- my $inhibit_cb = $self->curry::weak::_inhibit;
- my $uninhibit_cb = $self->curry::weak::_uninhibit;
-
# export to dbus
- $self->_impls([ map {
+ $self->_proxies([ map {
App::XScreenSaver::DBus::SaverProxy->new(
$self->service,
$_,
- $inhibit_cb,
- $uninhibit_cb,
+ $self,
)
} $self->paths->@* ]);
$self->_prod_id(
$self->reactor->add_timeout(
- 5_000,
+ 60_000,
Net::DBus::Callback->new(
method => $self->curry::weak::_prod_screensaver
),
@@ -83,13 +79,12 @@ sub start($self) {
return;
}
-sub _inhibit($self,$name,$reason,$message) {
+sub Inhibit($self,$name,$reason,$sender) {
my $cookie;
do {
$cookie = int(rand(2**31))
} until !exists $self->_inhibits->{$cookie};
- my $sender = $message->get_sender;
$self->_inhibits->{$cookie} = [ $name, $reason, $sender ];
$self->log->debugf(
@@ -103,11 +98,10 @@ sub _inhibit($self,$name,$reason,$message) {
return $cookie;
}
-sub _uninhibit($self,$cookie,$message) {
+sub UnInhibit($self,$cookie,$this_sender) {
my $inhibit = delete $self->_inhibits->{$cookie}
or return;
my ($name, $reason, $sender) = @$inhibit;
- my $this_sender = $message->get_sender;
$self->log->debugf(
'<%s> (was %s, is %s) resumed screensaver for <%s> (cookie %d) - %d left',
@@ -172,7 +166,7 @@ App::XScreenSaver::DBus::Saver - implements the "idle inhibition" protocol
=head1 VERSION
-version 1.0.2
+version 1.0.5
=head1 SYNOPSIS
diff --git a/lib/App/XScreenSaver/DBus/SaverProxy.pm b/lib/App/XScreenSaver/DBus/SaverProxy.pm
index 10fbb99..af4ec17 100644
--- a/lib/App/XScreenSaver/DBus/SaverProxy.pm
+++ b/lib/App/XScreenSaver/DBus/SaverProxy.pm
@@ -2,38 +2,14 @@ package App::XScreenSaver::DBus::SaverProxy;
use v5.20;
use strict;
use warnings;
-use experimental qw(signatures postderef);
# this is the interface name
use Net::DBus::Exporter qw(org.freedesktop.ScreenSaver);
-use parent 'Net::DBus::Object';
-our $VERSION = '1.0.2'; # VERSION
+use parent 'Net::DBus::ProxyObject';
+our $VERSION = '1.0.5'; # VERSION
# ABSTRACT: proxy dbus object
-
-dbus_method('Inhibit',['string','string'],['uint32']);
-dbus_method('UnInhibit',['uint32'],[]);
-
-sub new($class,$service,$path,$inhibit_cb,$uninhibit_cb) {
- my $self = $class->SUPER::new($service, $path);
- bless $self, $class;
- $self->{__inhibit_cb} = $inhibit_cb;
- $self->{__uninhibit_cb} = $uninhibit_cb;
- return $self;
-}
-
-our $_message;
-sub _dispatch_object($self,$connection,$message,@etc) {
- local $_message = $message;
- return $self->SUPER::_dispatch_object($connection,$message,@etc);
-}
-
-sub Inhibit($self,$name,$reason) {
- return $self->{__inhibit_cb}->($name,$reason,$_message);
-}
-
-sub UnInhibit($self,$cookie) {
- return $self->{__uninhibit_cb}->($cookie,$_message);
-}
+dbus_method('Inhibit',['string','string','caller'],['uint32']);
+dbus_method('UnInhibit',['uint32','caller'],[]);
1;
@@ -49,14 +25,7 @@ App::XScreenSaver::DBus::SaverProxy - proxy dbus object
=head1 VERSION
-version 1.0.2
-
-=head1 DESCRIPTION
-
-This is functionally the same as L<< C<Net::DBus::ObjectProxy> >>, but
-specialised for this application, and with a hack to allow L<<
-C<App::XScreenSaver::DBus::Saver> >> to access the sender of the
-message.
+version 1.0.5
=head1 AUTHOR