Update to signatures and fix to 5.36 for Debian dependencies
This commit is contained in:
parent
d686e64015
commit
fd73739229
|
@ -3,8 +3,7 @@
|
||||||
# TODO: add option to allow recursive sub-directories (in choose_image())
|
# TODO: add option to allow recursive sub-directories (in choose_image())
|
||||||
# TODO: license, etc.
|
# TODO: license, etc.
|
||||||
|
|
||||||
use strict;
|
use v5.36;
|
||||||
use warnings;
|
|
||||||
use POSIX;
|
use POSIX;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
|
|
||||||
|
@ -24,9 +23,8 @@ use constant ERROR => {
|
||||||
|
|
||||||
our @e;
|
our @e;
|
||||||
|
|
||||||
sub usage()
|
sub usage($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
print("$0 [output(s)] [-d|--daemon]\n
|
print("$0 [output(s)] [-d|--daemon]\n
|
||||||
Sets a wallpaper by cropping an appropriate sized section of a larger image.\n
|
Sets a wallpaper by cropping an appropriate sized section of a larger image.\n
|
||||||
All arguments other than the below are assumed to be output names, as defined
|
All arguments other than the below are assumed to be output names, as defined
|
||||||
|
@ -51,10 +49,8 @@ will be reset.\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub new
|
sub new($class, %args)
|
||||||
{
|
{
|
||||||
my ($class, %args) = @_;
|
|
||||||
|
|
||||||
use AnyEvent::Sway;
|
use AnyEvent::Sway;
|
||||||
$args{ipc} = AnyEvent::Sway->new();
|
$args{ipc} = AnyEvent::Sway->new();
|
||||||
use Image::Magick;
|
use Image::Magick;
|
||||||
|
@ -125,18 +121,16 @@ $SIG{KILL} = sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
# simply returns the array of hashes provided by swaymsg
|
# simply returns the array of hashes provided by swaymsg
|
||||||
sub get_outputs
|
sub get_outputs($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
my $o = $self->{ipc}->get_outputs->recv() || $self->do_log('LOG_WARNING',"Failed to query 'get_outputs'");
|
my $o = $self->{ipc}->get_outputs->recv() || $self->do_log('LOG_WARNING',"Failed to query 'get_outputs'");
|
||||||
die "No outputs detected.\n" unless (scalar(@$o) > 0);
|
die "No outputs detected.\n" unless (scalar(@$o) > 0);
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
# returns the same as above but with the 'name' as a hash key for easier lookup
|
# returns the same as above but with the 'name' as a hash key for easier lookup
|
||||||
sub get_active
|
sub get_active($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
if (defined($self->{outputs}) && scalar($self->{outputs})) {
|
if (defined($self->{outputs}) && scalar($self->{outputs})) {
|
||||||
my %active = ();
|
my %active = ();
|
||||||
foreach my $o (@{$self->{outputs}}) {
|
foreach my $o (@{$self->{outputs}}) {
|
||||||
|
@ -157,9 +151,8 @@ sub get_active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub clean
|
sub clean($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
if (-e $self->{pidfile}) {
|
if (-e $self->{pidfile}) {
|
||||||
open (my $fh, '<', $self->{pidfile});
|
open (my $fh, '<', $self->{pidfile});
|
||||||
my $p = <$fh>;
|
my $p = <$fh>;
|
||||||
|
@ -170,12 +163,8 @@ sub clean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dig_dirs
|
sub dig_dirs($self, $paths_ref, $path, $depth=0)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
my $paths_ref = shift;
|
|
||||||
my $path = shift;
|
|
||||||
my $depth = shift || 0;
|
|
||||||
unless (-e $path) {
|
unless (-e $path) {
|
||||||
return(undef);
|
return(undef);
|
||||||
}
|
}
|
||||||
|
@ -195,10 +184,8 @@ sub dig_dirs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub choose_image
|
sub choose_image($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
|
|
||||||
my @i;
|
my @i;
|
||||||
my $depth = 0;
|
my $depth = 0;
|
||||||
my @w;
|
my @w;
|
||||||
|
@ -218,17 +205,11 @@ sub choose_image
|
||||||
return $i[rand(scalar(@i))] || return undef;
|
return $i[rand(scalar(@i))] || return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub crop
|
sub crop($self, $image, $ow, $oh)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
my $image = shift;
|
|
||||||
my $ow = shift;
|
|
||||||
my $oh = shift;
|
|
||||||
|
|
||||||
my $cropped = $image;
|
my $cropped = $image;
|
||||||
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#;
|
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#;
|
||||||
|
|
||||||
#$image = "/tmp/Pharma-out.png.jpg";
|
|
||||||
use Image::Magick;
|
use Image::Magick;
|
||||||
my $im = Image::Magick->new();
|
my $im = Image::Magick->new();
|
||||||
die "$image is not readable" unless (-r $image);
|
die "$image is not readable" unless (-r $image);
|
||||||
|
@ -254,11 +235,8 @@ sub crop
|
||||||
return $cropped if ( -e $cropped );
|
return $cropped if ( -e $cropped );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_background
|
sub set_background($self, $target, $cropped)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
my $target = shift || return "No target or image provided";
|
|
||||||
my $cropped = shift || return "No image provided";
|
|
||||||
# TODO get fallback from javascript
|
# TODO get fallback from javascript
|
||||||
my $cmd = "output $target background $cropped fill #000000";
|
my $cmd = "output $target background $cropped fill #000000";
|
||||||
$self->do_log("LOG_DEBUG", "Running $cmd\n");
|
$self->do_log("LOG_DEBUG", "Running $cmd\n");
|
||||||
|
@ -270,12 +248,8 @@ sub set_background
|
||||||
return "Failed to run Sway IPC command '$cmd'";
|
return "Failed to run Sway IPC command '$cmd'";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub do_log
|
sub do_log($self, $level, $msg, $die=0)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
my $level = shift;
|
|
||||||
my $msg = shift;
|
|
||||||
my $die = shift || 0;
|
|
||||||
my $min = $self->{verbose} || 5;
|
my $min = $self->{verbose} || 5;
|
||||||
|
|
||||||
# Journald is borked. Just don't bother logging
|
# Journald is borked. Just don't bother logging
|
||||||
|
@ -302,9 +276,8 @@ sub do_log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run
|
sub run($self)
|
||||||
{
|
{
|
||||||
my $self = shift;
|
|
||||||
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
|
$self->do_log("LOG_DEBUG", "Fetching outputs from IPC");
|
||||||
$self->{outputs} = $self->get_outputs();
|
$self->{outputs} = $self->get_outputs();
|
||||||
# Local copy of targets so that it will re-check active every time
|
# Local copy of targets so that it will re-check active every time
|
||||||
|
|
Loading…
Reference in New Issue