15

Doing a google search reveals the command

xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s <image-path>

The first time I run this command I got a message saying that the property /backdrop/screen0/monitor0/image-path does not exist in channel xfce4-desktop.

So, I created this property:

xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -n -t string -s <image-path>

But still the background didn't change.

I then changed the background from space-03.jpg to space-04.jpg normally, from the Desktop Settings application of XUbuntu. Then I run:

$ xfconf-query -c xfce4-desktop -p /backdrop -lv
/backdrop/screen0/image-path                           /usr/share/backgrounds/space-03.jpg
/backdrop/screen0/monitor0/image-path                  /usr/share/backgrounds/space-03.jpg
/backdrop/screen0/monitor0/image-show                  true
/backdrop/screen0/monitor1/image-path                  /usr/share/backgrounds/space-03.jpg
/backdrop/screen0/monitor1/image-show                  true
/backdrop/screen0/monitorLVDS1/workspace0/color-style  0
/backdrop/screen0/monitorLVDS1/workspace0/image-style  5
/backdrop/screen0/monitorLVDS1/workspace0/last-image   /usr/share/backgrounds/space-04.jpg

As you can see, the property /backdrop/screen0/monitorLVDS1/workspace0/last-image has changed (!).

If I change this property then it works just fine but the thing is that I need to find a general way in order to implement it in my program (Wallch).

Even Variety (which is a very nice program, by the way) does not work properly on my machine and chooses to change the property /backdrop/screen0/monitor0/image-path which does nothing.

One way would be to create all the possible properties and change all of them when needed, simultaneously. I don't like this solution because of 2 reasons:

  1. Several system calls that will be needed
  2. At one point I will need to take the current image's path (in order to open the folder of it, copy the path of it, delete it and some other functions that the program provides). I would not know which property holds the path of the truly set image in order to make it available to the program.

I also do not understand why XFCE has done it so complex. Why wouldn't one property be enough like in gsettings?

hytromo
  • 4,901

1 Answers1

4

I think that should do the job

Use the following code to get the connected devices and count them:

connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutput=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") 
connected=$(echo $connectedOutputs | wc -w)

then you have to manipulate over them and choose whether to set the value for image-path or last-image

xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -n -t string -s  ~/Pictures/1.jpeg
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorLVDS1/workspace0/last-image -n -t string -s  ~/Pictures/1.jpeg

for i in $(xfconf-query -c xfce4-desktop -p /backdrop -l|egrep -e "screen.*/monitor.*image-path$" -e "screen.*/monitor.*/last-image$"); do
    xfconf-query -c xfce4-desktop -p $i -n -t string -s ~/Pictures/2.png  
    xfconf-query -c xfce4-desktop -p $i -s ~/Pictures/2.png

done

Assume that 1.jpeg is any file just needed to create the string by default. And 2.png is the wanted picture to be set. I added the first line just to make sure that xfce4-desktop exists.

This script was tested in my machine and it is working well.

Hope that helps my friend

EDIT: A list of port names was found here like so:

Output port names

Intel driver - UMS

VGA - Analog VGA output

LVDS - Laptop panel

DP1 - DisplayPort output

TV - Integrated TV output

TMDS-1 - First DVI SDVO output

TMDS-2 - Second DVI SDVO output

The SDVO and DVO TV outputs are not supported by the driver at this time.

Intel driver - KMS

LVDS1 - Laptop panel

VGA1 - Analog VGA output

DVI1 - Digital video output

radeon driver

VGA-0 - Analog VGA output

LVDS - Laptop panel

S-video - Integrated TV output

DVI-0 - DVI output

For further Info check here

kamil
  • 7,407
  • Why should that do the job? – Seth Feb 13 '14 at 17:29
  • @Seth Because I am looping through all available monitors and I will set the appropriate value for the found monitor. either last-image or image-path – kamil Feb 13 '14 at 17:31
  • In an newly installed XFCE system the values don't even exist. They are being created when you change once your desktop background manually. So, this isn't a good solution in my opinion. I include this answer in my question. I clearly say that I could try them all (create and change them every time), but this is far from being a good solution to the problem. – hytromo Feb 13 '14 at 19:09
  • you can create properties like you did – kamil Feb 14 '14 at 08:55
  • @hakermania check the edit – kamil Feb 14 '14 at 09:08
  • @kamil So, if the properties do not yet exist (have to be created), will they be listed with xfconf-query -c xfce4-desktop -p /backdrop -l ? – hytromo Feb 14 '14 at 10:53
  • @hakermania check again my friend – kamil Feb 14 '14 at 11:20
  • Again, this won't work in my case if I haven't changed my desktop background at least once. Because /backdrop/screen0/monitorLVDS1/workspace0/last-image will not exist (you only create /backdrop/screen0/monitor0/image-path). So, the solution is create them all and change them all, as I initially told. I will wait a bit and if nobody provides a better answer, you take the bounty ;) – hytromo Feb 14 '14 at 11:30
  • @hakermania Actually there is a way to do it dynamically. Using xrandr gives you all monitors, but it needs some tweaking to grep only monitor names and then you can automate the process. I will update the answer again – kamil Feb 14 '14 at 13:04
  • The commands you posted both output LVDS1. They could output 0, to my understanding. In the former case, the property should be /backdrop/screen0/monitor$OUTPUT/workspace0/last-image, while in the latter case, the property should be /backdrop/screen0/monitor$OUTPUT/image-path. Should I check each time the value of $OUTPUT and act correspondingly? How do I know that $OUTPUT cannot get a 3rd value, say LVDS1monitor0 that needs the property /backdrop/screen0/monitor$OUTPUT/workspace0/image-path? (just an example). Sorry if I am being tiring, but the way needs to be really generic. – hytromo Feb 14 '14 at 14:21
  • @hakermania You should manipulate xrandr, This is the only command that would help you as far as I know because we are working on xfce (based on X). xrandr is helpful but it isn't ready for displaying output as you need it. You have to use grep and sed to extract your needed parts from its output – kamil Feb 14 '14 at 16:50
  • I understand what you are saying. What I'm asking is this: The property changes between LVDS1 and 0. How do I know that there isn't any 3rd value, say LVDS0 that needs another property? – hytromo Feb 14 '14 at 17:21
  • @hakermania I assume that LVDSx start with LVDS1 but monitor starts with monitor0 – kamil Feb 14 '14 at 17:23
  • Assumptions are bad for the stability of a program, though. – hytromo Feb 14 '14 at 17:53