17

I have a laptop and a monitor. Most of the time my laptop is connected to the monitor over HDMI. I use Ubuntu Gnome 14.04 and here is what I want:

  • When no monitor is connected I want a simple background image
  • When the monitor is connected I would like to have the same background image on my laptop and another one on my monitor.

Is that possible? I found this question as well as nitrogen. But both didn't help me.

Edit:

After running gnome-tweak-tool, go to the "Desktop" tab in the left-side panel and then turn off the setting "Have file manager handle the desktop".

Source: Ubuntu Forums.

Unfortunately I am unable to find this in my Gnome-Tweak-Tool: gnome-tweak-tool

I tried to find the same configuration using dconf-editor under org.gnome.desktop.background but all it said was:

Summary: Draw Desktop Background
Description: Have GNOME draw the desktop background. DEPRECATED: This key is deprecated and ignored.

Also my gnome-shell --version is GNOME Shell 3.10.4.

In this gist is the output of xrandr. First one is with the second monitor connected. Second one is without it.

6
  • When using Nitrogen, did you disable the file manager from handing the desktop?
    – Kaz Wolfe
    Oct 8 '14 at 9:11
  • I was not able to find the option in the Gnome-Tweak-Tool any more. I have added additional information to my question. Hope it helps
    – byf-ferdy
    Oct 8 '14 at 10:36
  • @Whaaaaaat nitro is only for 13.10 and lower :/
    – blade19899
    Oct 8 '14 at 11:01
  • I think I got something, what are the resolutions of your screens? Oct 9 '14 at 20:03
  • both 1920x1080 (16:9). Laptop is 19'' I think, Monitor 27''.
    – byf-ferdy
    Oct 9 '14 at 20:37
10
+100

The trick

It seems impossible to separately set wallpapers for the main screen and the second screen. What can be done however is to set a wallpaper, and have it spanned over two screens. We can automatically create a spanning image of two wallpapers of your choice and (also automatically) switch the wallpaper and the picture options, depending on whether the second screen is connected or not.
To make it look nice, it is necessary that at least the vertical screen resolution of both screens is identical, which is the case in your situation.

enter image description here

In practice

Preparation

In this solution, The preparing work you have to do is:

  • First, install imagemagick to automaically create the spanning image:

    sudo apt-get install imagemagick
    
  • Prepare two separate background images of your choice for both the screens:

    • The dimensions should exactly match the screen's dimensions (16:9 in your case)
    • The vertical resolution of both images should be exactly the same.

    call them screen_1.jpeg and screen_2.jpeg (exactly those names). A script will create the spanning image.

  • Create a folder in your home directory and copy both images into the folder.

  • Copy the script below into an empty file and save it as auto_wall.py, together with the two images you prepared.

  • In the head section of the script, there is a line:

    screen_check = "HDMI-0 connected"
    

    if necessary, replace HDMI-0 by <your_second_screenname> (run the command xrandr if necessary to find out)

Run the script (and keep it running in the background) by the command:

python3 /path/to/auto_wall.py

Now if you connect your second screen, the wallpaper on your second screen should switch within a few seconds to screen_2.jpeg you prepared.

  • If all works well, add it to your startup applications.

The script

#!/usr/bin/env python3

import subprocess
import os
import time

curr_dir = os.path.dirname(os.path.abspath(__file__))
screen_check = "HDMI-0 connected"

single_picture = "'file://"+curr_dir+"/screen_1.jpeg'"
double_picture = "'file://"+curr_dir+"/span_image.jpeg'"

def execute_set(command):
    subprocess.call(["/bin/bash", "-c", command])

def execute_get(command):
    return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8").strip()

def switch_tosingle():
    execute_set("gsettings set org.gnome.desktop.background picture-uri "+single_picture)
    execute_set("gsettings set org.gnome.desktop.background picture-options zoom")

def switch_todouble():
    if not os.path.exists(double_picture):
        create_spanimage()
    execute_set("gsettings set org.gnome.desktop.background picture-uri "+double_picture)
    execute_set("gsettings set org.gnome.desktop.background picture-options spanned")

def create_spanimage():
    image_1 = curr_dir+"/"+"screen_1.jpeg"
    image_2 = curr_dir+"/"+"screen_2.jpeg"
    span_image = curr_dir+"/"+"span_image.jpeg"
    execute_set("convert "+image_1+" "+image_2+" "+"+append "+span_image)

def check_ifconnected():
    command = "xrandr"
    check = execute_get(command)
    if screen_check in check:
        return True

def check_wallpaper():
    check = execute_get("gsettings get org.gnome.desktop.background picture-uri")
    if check == single_picture:
        return "single"
    elif check == double_picture:
        return "double"

def arrange():
    test = (check_ifconnected(), check_wallpaper())
    if test == (True, "double") or test == (False, "single"):
        pass
    elif test[0] == True:
        switch_todouble()
    else:
        switch_tosingle()

while True:
    arrange()
    time.sleep(5)

Replacing images

In case you want to change wallpaper(s), just replace one or both of the images you copied to the folder (but mind the name) and remove the span_image.jpeg, created by the script.

I tested it on Ubuntu 14.04 and 14.10, and it worked perfectly. The fact that you use Gnome should not make a difference.

Switching wallpaper settings manually with a key combination

If, for some reason, you would prefer to switch to the spanned wallpaper manually after connecting / disconnecting the external monitor, you can replace the last three lines:

while True:
    arrange()
    time.sleep(5)

by a single line:

arrange()

and add a keyboard shortcut to do the switch: "System Settings" > "Keyboard" > "Shortcuts" > "Custom Shortcuts"

Add the command:

python3 /path/to/auto_wall.py

to a key combination of your choice.

4
  • This looks amazing. Ill check it as soon as I can and let you know! Thank you for the work anyhow!
    – byf-ferdy
    Oct 10 '14 at 18:01
  • @byf-ferdy oops, accidentally left my own (testing) directory in script, fixed it now. Oct 10 '14 at 19:30
  • Great work! It works perfectly!
    – byf-ferdy
    Oct 11 '14 at 14:35
  • 1
    Thanks for the nice question! This is what I like to do. Oct 11 '14 at 14:36
1

In addition on the above answer, you can join two exact size images by using this service : http://www.photojoiner.net/

After you joined two or more images, you should select "span" option in the background settings page.

0

Sometimes I use

eog --fullscreen -s <path to first pic>

on the second monitor to keep a constantly changing backround there. You can adjust the delay between pic change using

gsettings set org.gnome.eog.fullscreen seconds <whatever Val>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.