双显示器壁纸的 HydraPaper 替代品?

金尔

我一直在寻找一种拥有双壁纸的方法。到目前为止,唯一出现的是HydraPaper。问题是我还需要安装 Flatpak。我已经在使用aptsnap用于软件包,所以我不想单独为壁纸安装另一个软件包管理器。是否有 HydraPaper 的替代品?

pmcb

这可能就是您要寻找的。

我使用“bash”、“convert”和“gsettings”做到了。它适用于我的 2 个屏幕。

概要:

  • 获取两个高度相同的图像
  • 新图像宽度=屏幕宽度*图像原始高度/屏幕高度
  • 将图像拉伸到新宽度
  • 加入现在适合 2 个屏幕全宽的 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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章