Reload Desktop Background via Command line

Running Ubuntu 19.04 MATE. I have a problem trying to rotate the screen with a script. It's that the background doesn't fully reset to the new orientation. I can fix this by changing (in the GUI) the background to a different one and back again. I've been trying to do this with the script, but I'm quite new to bash scripting and not having much luck. Working through it, I can't help but thinking there might be a command that will simply reload or refresh the background without changing it to a new one? Wondering if anyone knows what it might me? Thanks.

I am trying to understand what you have written here. So bear with me while I try and restate what I think you are saying:

You have manged to write a script with a command to rotate a given picture and then instate it as your desktop backround. However, when the script runs, whilst it instates the background, it does so in a way that "does not fully reset to the new orientation". You fix this by changing to another background and then back to the one you want in the GUI.

My first question is what do you mean, precisely by "does not fully reset to the new orientation". Do you mean it does not change the orientation at all?

My second question is have you tried incorporating into the script the temporary change to the new background and then back to the one you want?

In other words, the scripts contents would go something like:

change the orientation of picture A
change desktop wallpaper to picture A
change desktop wallpaper to picture B
change desktop wallpaper to picture A

Sounds more like an xrandr screen rotation thing than just the image. The image seems to not update with the screen rotation?

Try killall caja, it should restart your desktop and reorient the background. Not a great solution, but the easiest.

A better option is to disable, then re-enable, the desktop background using gsettings (i don't remember the key, and I'm currently not on my computer, but it's something like gsettings set org.mate.desktop.background draw-background false, followed by the same but with true. You'll have to dig in dconf to find the actual key)

To your first question - The background picture will rotate. I will try to clarify what I mean by not fully reset. If the resolution is 1920x1080, the background is rotated and appears to be sized correctly, but nothing appears below pixel 1080 (logical guess). I will try to post a couple of screenshots that should explain it.

Sometimes, I can get the black to appear when rotating back to landscape, but it usually works going in that direction. (Portrait to Landscape) Also, sometimes the black portion of the screen will "remember" what was on that portion of the screen. i.e. Drag a window through it and it will continue to show staggered windows.

To the second question - That is what I'm to figure out how to script, but was hoping for a simpler command.

Normal Lanscape

Portrait with errors

killall caja 

Does seem to work. What is the downsides to using this?

I will try to figure out the second method, but I seem to remember trying something like that already.

Picture of what I was talking about earlier with the "remember" portion of the screen

I have that corruption problem too when turning on my second monitor (doesn't happen if I start a session with both monitors turned on).

Having found out that going to the "background" tab of the MATE appearance settings got rid of the problem, I decided to use a script to reload my background and assigned a keyboard shortcut to it.

Here's the script if you want to use it:
#!/bin/sh
gsettings set org.mate.background picture-filename '/path/to/image.png'
gsettings set org.mate.background picture-options 'zoom'

Other options you can use instead of zoom are centered, scaled,spanned and stretched.

Just edit it with the path to your wallpaper. Save the file and gave it executions permissions using chmod +x or by ticking the appropriate case in the permissions properties of the file.
Then, go to your keyboard shortcuts (mate-keybinding-properties) and add a new one
called mate-terminal -e 'path/to/your/script' and assign it the key combination you want.
You will just have to hit the shortcut when needed.

The downside is you have to edit the script every time you want to change the wallpaper.

2 Likes

@maeks84, the main downside is that you're killing the entire caja process just to fix a background rendering issue, so if you have any ongoing file transfers or anything like that, they will also be killed.

Here's what I've used in the past to correct some annoyances when changing screen settings:

gsettings set org.mate.background show-desktop-icons false
sleep 1
gsettings set org.mate.background show-desktop-icons true

In fact, the mate-settings-daemon does exactly the same when changing back and forth between HiDPI scaling modes:

It's an ugly, but currently necessary, hack...

3 Likes

It's an ugly, but currently necessary, hack...

Horrible horrible hack. But thanks so very very much man!

Run in terminal just in case.
First script sets the background

#!/bin/bash

XCAJA="$(xwininfo -name x-caja-desktop)"

# extract Xwindow ID
XCAJA_XID="$(sed -n '/^xwininfo\:[ \t]Window id\:[ \t]*/s/^xwininfo\:[ \t]Window id\:[ \t]*//g;/\"x-caja-desktop\"/s/[ \t]*\"x-caja-desktop\"//p' <<<${XCAJA})"

xprop -root -spy -id ${XCAJA_XID} WM_NORMAL_HINTS 2>/dev/null |
    while read line; do
          case "${line}"  in
              *"program specified minimum size:"*)
                      BCK=$(gsettings get org.mate.background picture-filename)
                      OPT=$(gsettings get org.mate.background picture-options)
                      # Adjust sleep time
                      sleep 3
                      gsettings set org.mate.background picture-filename $BCK
                      gsettings set org.mate.background picture-options $OPT
                      ;;
          esac
    done

Second remaps a desktop window (requires xdotool)

#!/bin/bash

XCAJA="$(xwininfo -name x-caja-desktop)"

# extract Xwindow ID
XCAJA_XID="$(sed -n '/^xwininfo\:[ \t]Window id\:[ \t]*/s/^xwininfo\:[ \t]Window id\:[ \t]*//g;/\"x-caja-desktop\"/s/[ \t]*\"x-caja-desktop\"//p' <<<${XCAJA})"

xprop -root -spy -id ${XCAJA_XID} WM_NORMAL_HINTS 2>/dev/null |
    while read line; do
          case "${line}"  in
              *"program specified minimum size:"*)
                      # Adjust sleep time
                      sleep 3
                      xdotool windowunmap ${XCAJA_XID}
                      sleep 1
                      xdotool windowmap ${XCAJA_XID}
                      ;;
          esac
    done
```

One of those should work :slight_smile:  in theory

I even tried to draw on the x-caja-desktop window with the xloadimage

[code]
#!/bin/bash
# Install xloadimage
XCAJA="$(xwininfo -name x-caja-desktop)"

# extract Xwindow ID
XCAJA_XID="$(sed -n '/^xwininfo\:[ \t]Window id\:[ \t]*/s/^xwininfo\:[ \t]Window id\:[ \t]*//g;/\"x-caja-desktop\"/s/[ \t]*\"x-caja-desktop\"//p' <<<${XCAJA})"

xprop -root -spy -id ${XCAJA_XID} WM_NORMAL_HINTS 2>/dev/null |
    while read line; do
          case "${line}"  in
              *"program specified minimum size:"*)
                      BCK=$(gsettings get org.mate.background picture-filename)
                      # Adjust sleep time
                      sleep 3
                      BCK="${BCK#*\'}"
                      BCK="${BCK%\'*}"
                      xloadimage -windowid ${XCAJA_XID} -name "${BCK}"  -quiet 2>/dev/null
                      xdotool windowunmap ${XCAJA_XID}
                      sleep 1
                      xdotool windowmap ${XCAJA_XID}
                      ;;
          esac
    done
[/code]
1 Like

Maybe this will do :slight_smile: https://linux.die.net/man/1/xrefresh