Crontab not running feh correctly on two screens in i3 (display variable set to :0)
I have two screens and I have a script to set a new wallpaper in i3 every day. The script basically downloads an image and then runs following command
convert {save_location} -trim JPG:- | feh --bg-max -
This works perfectly when ran interactively - each screen gets a copy of the same wallpaper like this
|@@@@@@@@| |@@@@@@@@|
|@@hello@| |@@hello@|
|@@@@@@@@| |@@@@@@@@|
The display variable is set to :0
echo $DISPLAY
:0
However if I run it with crontab -e:
0 1 * * * DISPLAY=:0 python .../change_wallpaper.py
then it does not set a copy of wallpaper on each screen. It treats two screens as one and sets this wallpaper into the center of a "combined screen":
|----@@@@| |@@@@----|
|----@@he| |llo@----|
|----@@@@| |@@@@----|
This obviously looks ugly.
I searched but could not find how to solve this. Maybe someone could advice a useful config option or a variable that I should add to the cron environment to solve this? Thanks a lot in advance
My environment: Ubuntu 20.04, i3, gdm
After reading the source code, I decided that the problem is related to xinerama. Although not being able to solve this in a beautiful way, here is a script that serves as a workaround:
#!/bin/bash
# Compute screen size
size=$(xrandr | grep *+ -m 1 \
| sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
# then manually collate a combined picture for two screens and
# launch feh without xinerama functionality
convert [path/to/picture] \
-trim \
-resize $size \
-background black -compose Copy \
-gravity center -extent $size \
-quality 92 +duplicate +append JPG:- \
| feh --bg-max --no-xinerama -
As written in the script comments, the script computes the screen size and then manually collates a combined picture for two screens (with the imagemagick tool) and launches feh without xinerama functionality at all.
This works in cron as well as interactively. However, this would probably not work very well if the screens are of different sizes.
I am inclined to think that non working xinerama API is some kind of bug, so would love to see your comments
I cannot reproduce the issue here. On a two-screen system with i3, nodm, and Debian Unstable, the following crontab entry correctly sets the wallpaper for each monitor.
* * * * * DISPLAY=:0 feh --bg-max /some/file.jpg
Does the issue also appear when you call feh directly in the crontab instead of using the Python script? Which version of feh are you running? If you are using your own feh build, are the version present in your commandline and the version used by the crontab the same (i.e., can we rule out different feh versions due to different PATHs)?
Thanks a lot, derf.
There is one more thing that I did not mention. When the script is run the screen is off. It is being switched off with
xset dpms force off
Indeed, when I tried crontab with screen on (running directly in crontab the command that you suggested) - it worked correctly. When I tried again with screen being off - the image went to the middle of the "combined screen" - bug reproduced
As for the feh version, honestly I can't remember for sure but I think it comes from ubuntu repository.
$ feh -version
feh version 3.3
Compile-time switches: curl exif verscmp xinerama
I checked the environment by running
* * * * * /usr/bin/env > /home/[username]/tmp/cron-env
and there is no difference in the two cases
Additional info: Both screens are attached to Nvidia card (2080 Ti) with Nvidia closed-source driver running. One with HDMI and other with DP cable. xorg.conf:
...
Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
Option "DPMS"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection