From fd737392298f137c94ba5a69d3fffe839bb870b2 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Sun, 21 Jan 2024 21:06:53 -0700 Subject: [PATCH] Update to signatures and fix to 5.36 for Debian dependencies --- sway/wallpaper.pl | 51 +++++++++++------------------------------------ 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/sway/wallpaper.pl b/sway/wallpaper.pl index bb15653..2aeb17a 100755 --- a/sway/wallpaper.pl +++ b/sway/wallpaper.pl @@ -3,8 +3,7 @@ # TODO: add option to allow recursive sub-directories (in choose_image()) # TODO: license, etc. -use strict; -use warnings; +use v5.36; use POSIX; use File::Copy; @@ -24,9 +23,8 @@ use constant ERROR => { our @e; -sub usage() +sub usage($self) { - my $self = shift; print("$0 [output(s)] [-d|--daemon]\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 @@ -51,10 +49,8 @@ will be reset.\n"); exit(0); } -sub new +sub new($class, %args) { - my ($class, %args) = @_; - use AnyEvent::Sway; $args{ipc} = AnyEvent::Sway->new(); use Image::Magick; @@ -125,18 +121,16 @@ $SIG{KILL} = sub { }; # 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'"); die "No outputs detected.\n" unless (scalar(@$o) > 0); return $o; } # 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})) { my %active = (); foreach my $o (@{$self->{outputs}}) { @@ -157,9 +151,8 @@ sub get_active } } -sub clean +sub clean($self) { - my $self = shift; if (-e $self->{pidfile}) { open (my $fh, '<', $self->{pidfile}); 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) { return(undef); } @@ -195,10 +184,8 @@ sub dig_dirs } } -sub choose_image +sub choose_image($self) { - my $self = shift; - my @i; my $depth = 0; my @w; @@ -218,17 +205,11 @@ sub choose_image 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; $cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$self->{'path'}$1-cropped.$2#; - #$image = "/tmp/Pharma-out.png.jpg"; use Image::Magick; my $im = Image::Magick->new(); die "$image is not readable" unless (-r $image); @@ -254,11 +235,8 @@ sub crop 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 my $cmd = "output $target background $cropped fill #000000"; $self->do_log("LOG_DEBUG", "Running $cmd\n"); @@ -270,12 +248,8 @@ sub set_background 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; # 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->{outputs} = $self->get_outputs(); # Local copy of targets so that it will re-check active every time