summaryrefslogtreecommitdiff
path: root/bin/i3-rotate-wallpaper
blob: b31bf91f9c446d2c74ca52230e2a6e8e616c508f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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