#!/usr/bin/perl use 5.028; use strict; use warnings; # dirs where wallpaper can be found our @dirs = ("$ENV{HOME}/annex/wallpaper/pro"); # the user can request to freeze the current wallpaper by # `touch $HOME/local/.norotate` exit if -e "$ENV{HOME}/local/.norotate"; # The user can list wallpapers they want displayed in order of preference in # this file. For example, listing one file will mean the primary output # always gets that image, and any other outputs get outputs from the command # line. my @saved_choices; if (-e "$ENV{HOME}/local/wallpapers") { open my $fh, "<", "$ENV{HOME}/local/wallpapers"; @saved_choices = <$fh>; } # Could keep a log of recently used wallpapers and don't use those # again (would need code to expire from the log, and if want this, # should probably write a real, general program not just this # Sean-specific script) my @images; push @images, shift @saved_choices || shift @ARGV # https://stackoverflow.com/a/16758439 || `find @dirs -exec file -L '{}' \\; | grep -o -P '^.+: \\w+ image' | shuf -n 1 | cut -d: -f1` for 1 .. grep / connected /, `xrandr`; chomp @images; system "resize-wallpapers-for-outputs", @images; system "i3-startup-always" if $ENV{DISPLAY}; # if [ -n "$img" ]; then # # this will just size up images with the correct aspect ratio. For # # images with the wrong aspect ratio, it'll crop them. I find that's # # usually better than adding borders (which is what the commented out # # cmd does) # convert "$img" \ # -resize "$dims"^ -gravity center -extent "$dims" \ # $HOME/local/wallpaper.png # # convert "$img" \ # # -resize "$dims" -background black -gravity center -extent "$dims" \ # # $HOME/local/wallpaper.png # # this calls feh # [ -n "$DISPLAY" ] && i3-startup-always # fi # # do develacc too, though we can't call i3-startup-always # if [ -d "$HOME/local/develacc/local" ]; then # if [ "x$2" = "x" ]; then # img2="$(find $dirs -name '*' -exec file -L {} \; | grep -o -P '^.+: \w+ image' | shuf -n 1 | cut -d: -f1)" # else # img2="$2" # fi # if [ -n "$img2" ]; then # convert "$img2" \ # -resize "$dims"^ -gravity center -extent "$dims" \ # $HOME/local/develacc/local/wallpaper.png # fi # fi