我一直在寻找一种拥有双壁纸的方法。到目前为止,唯一想到的就是 HydraPaper。问题是我还需要安装 Flatpak。我已经使用apt
和snap
作为软件包,所以我不想再安装另一个专门用于壁纸的软件包管理器。有没有 HydraPaper 的替代品?
答案1
这可能就是您正在寻找的。
我使用“bash”、“convert”和“gsettings”完成了此操作。它适用于我的 2 个屏幕。
概要:
- 获得两张高度相同的图像
- 图片新宽度 = 屏幕宽度 * 图片原高度 / 屏幕高度
- 将图像拉伸至新宽度
- 将两张图片合并,使其适合两个屏幕的整个宽度
我正在运行 Ubuntu 18.04。请随意破解你的想法
#! /bin/bash
#! /bin/bash -vx
# input:
# new_background.sh -reset - to reset background to the previous picture
# new_background.sh -set - to set a new background
lastImage=$HOME/.new_background_last_image.txt
DIR="/usr/share/backgrounds"
joinImage=$HOME/.new_background_last_image.jpg
# choose 2 images from dir
number=$(ls -1 $DIR | wc -l | awk '{print $1}')
mapfile -t screenSize < <( xrandr | grep -e "^DP" | awk ' { print $0 }' )
if [ ${#screenSize[@]} != 2 ]
then
echo there don\'t appear to be 2 screens - jobs ends
exit
fi
tot=0
prevH=0
prevW=0
prevFile=""
found=0
SET=-1
case "$1" in
-reset ) SET=0
;;
-set ) SET=1
;;
esac
if [ "$SET" -eq -1 ]
then
echo enter either -set or -reset
exit
fi
# reset previous picture
if [ "$SET" -eq 0 ]
then
URI=$(cat $lastImage)
gsettings set org.gnome.desktop.background picture-options 'zoom'
gsettings set org.gnome.desktop.background picture-uri "${URI}"
exit
fi
# find 2 pictures
while [ $tot -lt $number ]
do
# go throguh files at random until 2 have the same height
randomN=$[ ( $RANDOM % $number ) ]
fileName=$(ls -1 $DIR/* | grep -e jpg -e png | awk 'NR=='$randomN' {print $0}')
if [ x$prevFile == x$fileName ]
then
continue
fi
if [ x"" == x$fileName ]
then
continue
fi
if [ x$prevFile != x$fileName ] && [ x"" != x$fileName ]
then
ww=$(convert $fileName -print "Size: %wx%h\n" /dev/null | awk '{ print $2}')
w=$(echo $ww | awk -F x ' {print $1 }')
h=$(echo $ww | awk -F x ' {print $2 }')
if [ $h -eq $prevH ]
then
found=1
break
fi
fi
prevW=$w
prevH=$h
prevFile=$fileName
tot=$[$tot+1]
done
if [ $found -eq 0 ]
then
echo no files found # may be solved by running the program again
exit
fi
# new width = width of screen * original height of image / height of screen
# = 1920 2160(e.g.) 1080
pref=$(expr $(mktemp -u) : ".*\.\(.*\)")
outputFile=(${pref}_1 ${pref}_2)
files=( $fileName $prevFile )
widths=( $w $prevW)
heights=( $h $prevH)
# do each file
reverse=0 # if the second screen is the first in the screenSize list reverse=1
for I in 0 1;
do
# size of screen I
mapfile -t tt < <(echo ${screenSize[$I]} | grep -E -o '[0-9]+x[0-9]+\+[0-9]+\+[0-9]+' | sed s'/[x+]/ /g' | awk ' { print $1,"\n", $2, "\n", $3, "\n", $4 } ')
# this is the start position of the screen
# if not 0 and I=0 then it is the 2nd screen and reverse images when joining
offset=${tt[2]}
if [ $I == 0 ] && [ $offset != 0 ]
then
reverse=1
fi
let "newWidth = ${heights[$I]}*${tt[0]}/${tt[1]}"
convert -resize ${newWidth}x${heights[$I]}! ${files[$I]} ${outputFile[$I]}
done
# join the files
if [ $reverse == 0 ]
then
convert +append ${outputFile[0]} ${outputFile[1]} $joinImage
else
convert +append ${outputFile[1]} ${outputFile[0]} $joinImage
fi
URI=$(gsettings get org.gnome.desktop.background picture-uri)
# save the previous file name
echo $URI > $lastImage
uri=file:"//$joinImage"
gsettings set org.gnome.desktop.background picture-options 'spanned'
gsettings set org.gnome.desktop.background picture-uri "${uri}"
rm ${outputFile[0]} ${outputFile[1]}
# end-of-file