3

I'm using xubuntu with xfc4, for pure fun I tried to make a script which allows me to put a gif as a desktop wallpaper because this is not a default feature in xfce4.

I've already made a script which seem to work pretty fine excepted that the CPU get in a great trouble with it. So is there a way to optimize this code to do the same thing but stay friend with my CPU?

BG_GIF=/home/grasteau/Pictures/walpapper.gif

DURATION=$(exiftool -Duration walpapper.gif | sed 's/ //g' | sed 's/Duration://g' | sed 's/s//g')
PATH_IMAGE=/
mkdir -p /dev/shm/background
rm -f /dev/shm/background/*
gm convert $BG_GIF +adjoin /dev/shm/background/target%d.png
NUMBER_OF_FRAME=$(bc <<< "$(ls -1 /dev/shm/background | wc -l) - 1")
DELAY=$(bc <<< "scale=3; $DURATION/$NUMBER_OF_FRAME")

while true
do 
    for i in $(seq 0 $NUMBER_OF_FRAME); 
    do 
        PATH_IMAGE="/dev/shm/background/target$i.png"
        xfconf-query -c xfce4-desktop -l | grep "last-image$" | while read -r line
        do
            xfconf-query -c xfce4-desktop -p $line -s $PATH_IMAGE
        done
        sleep $DELAY
    done
done
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Xiidref
  • 1,456
  • 8
  • 20
  • 2
    the for loop should only contain the `xfconf-query -c -p -s` and sleep. Make an array of your images and iterate over it with a modulo. BTW the question might be better received on [the CodeReview SE](http://codereview.stackexchange.com/) – Aaron Apr 30 '19 at 09:35
  • 3
    To improve the performance of the bash script do what Aaron said. To improve the performance of changing the background resize the pictures to the correct size beforehand such that xfce doesn't have to scale them in each frame again and again – I could imagine that this is the bottleneck here. – Socowi Apr 30 '19 at 11:34
  • 2
    You can also play a little with the file format. Maybe .jpgs load faster than .pngs because of their file size. – Socowi Apr 30 '19 at 11:46

0 Answers0