summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-08-09 17:07:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-08-09 17:07:17 -0700
commite5785968d8fe1ee8e20b061ec713dcdf5dfdc06e (patch)
treee7fcc16a9d373c98545fcf96e43338463d6bf88f /bin
parent88d652eaf8e94387f70e5380af07bf49ccda79ef (diff)
downloaddotfiles-e5785968d8fe1ee8e20b061ec713dcdf5dfdc06e.tar.gz
add multi-monitor support to wallpaper scripts
Diffstat (limited to 'bin')
-rwxr-xr-xbin/i3-rotate-wallpaper113
-rwxr-xr-xbin/i3-startup-always2
-rwxr-xr-xbin/resize-wallpapers-for-outputs36
3 files changed, 87 insertions, 64 deletions
diff --git a/bin/i3-rotate-wallpaper b/bin/i3-rotate-wallpaper
index 63cda8b3..99b87473 100755
--- a/bin/i3-rotate-wallpaper
+++ b/bin/i3-rotate-wallpaper
@@ -1,71 +1,58 @@
-#!/bin/sh
+#!/usr/bin/perl
-. $HOME/.shenv
+use 5.028;
+use strict;
+use warnings;
-set -e
+# dirs where wallpaper can be found
+our @dirs = ("$ENV{HOME}/annex/wallpaper/pro");
-# space-separated dirs where wallpaper can be found
-dirs="$HOME/lib/annex/doc/img/wallpaper/pro"
-
-# the user can request to freeze the current wallpaper by `touch $HOME/local/.norotate`
-test -e "$HOME/local/.norotate" && exit 0
-
-# We don't know to deal with more than one monitor, so don't even try
-# (to resize an image for each monitor's wallpaper, and then paste it
-# at the right coordinates in a single wallpaper.png to be applied to
-# the root window with feh, we would need to be using a real scripting
-# language (e.g. Python's pillow))
-# (maybe this: https://github.com/hhannine/Superpaper)
-monitors="$(xrandr -q | grep ' connected' | wc -l)"
-test $monitors -gt 1 && exit 0
+# the user can request to freeze the current wallpaper by
+# `touch $HOME/local/.norotate`
+exit if -e "$ENV{HOME}/local/.norotate";
# 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)
-if [ "x$1" = "x" ]; then
- # https://stackoverflow.com/a/16758439
- img="$(find $dirs -name '*' -exec file -L {} \; | grep -o -P '^.+: \w+ image' | shuf -n 1 | cut -d: -f1)"
-else
- img="$1"
-fi
-
-if [ -n "$DISPLAY" ]; then
- dims="$(xdpyinfo | grep dimensions: | awk '{print $2}')"
-elif [ -e "$HOME/local/wallpaper.png" ]; then
- dims="$(identify $HOME/local/wallpaper.png | awk '{print $3}')"
-else
- echo >&2 "$0: unable to determine display dimensions"
- exit 1
-fi
-
-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
+my @images;
+push @images,
+ 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
diff --git a/bin/i3-startup-always b/bin/i3-startup-always
index 59b0e027..fa2d278e 100755
--- a/bin/i3-startup-always
+++ b/bin/i3-startup-always
@@ -59,7 +59,7 @@ xsetroot -solid \#FFFFF6
# use wallpaper.png if it's the right size
if i3-have-wallpaper; then
- feh --bg-scale $HOME/local/wallpaper.png
+ feh --bg-scale --no-xinerama $HOME/local/wallpaper.png
# old fallback to a tileable image
# else
# feh --bg-tile ~/lib/img/diagmonds_2X.png
diff --git a/bin/resize-wallpapers-for-outputs b/bin/resize-wallpapers-for-outputs
new file mode 100755
index 00000000..284826d7
--- /dev/null
+++ b/bin/resize-wallpapers-for-outputs
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+# note that swaybg and swaylock have per-output wallpapers built in, so
+# hopefully someday this script will be obsolete ...
+
+use 5.028;
+use strict;
+use warnings;
+
+my $output_re = qr/ ([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+) /;
+
+chomp(my @xrandr = `xrandr`);
+my ($canvas) = grep /^Screen 0:/, @xrandr;
+my ($canvas_w, $canvas_h) = $canvas =~ /current ([0-9]+) x ([0-9]+)/;
+# sort the displays from left to right and then from top to bottom
+my @displays = sort {
+ my (undef, undef, $a_x, $a_y) = $a =~ $output_re;
+ my (undef, undef, $b_x, $b_y) = $b =~ $output_re;
+ $a_y <=> $b_y or $a_x <=> $b_x
+} grep / connected /, @xrandr;
+
+@ARGV == @displays
+ or die "uh oh, " . @displays . " displays but only " . @ARGV . " wallpapers";
+
+my @args = ("-page", "${canvas_w}x${canvas_h}");
+for (@displays) {
+ /$output_re/;
+ push @args, '(', shift @ARGV, "-resize", "${1}x${2}^",
+ qw(-gravity center -extent), "${1}x${2}", "-repage",
+ "${1}x${2}+${3}+${4}", ')';
+}
+push @args, qw(-layers merge -transparent), '#FFFFF6',
+ "$ENV{HOME}/local/wallpaper.png";
+
+system "convert", @args;
+exit $? >> 8;