Ubuntu – Possibility to save the current resolution, wallpaper and desktop arrangement settings in gnome 3


Every time I disconnect my three external monitors from my laptop, or when I plug them back in, all the resolution and extended desktop settings are messed up. I'll have to change back the settings to get it right again.

I am using gnome 3.18.5 on Ubuntu 16.04. I have Intel HD graphics 530 and an Nvidia 960M with nvidia driver version 375.39. I also installed the gnome shell extension called 'Fix-Multi-Monitors', which did indeed fix a bunch of issues like windows only moving between two out of three monitors with window moving shortcuts.

Anyway, what I'd like to do is somehow have the settings saved for when I've plugged in all three monitors, so I can simply run one single script or setting, so it instantly loads up how I want it, or maybe even that this happens automatically when three displays are detected. I should add that I always plug in the monitors the same way.

What also bothers me is that I have this wallpaper enabled which spans all three monitors but when they are disconnected the wallpaper becomes a thin line on the laptop monitor with the rest of the screen black. I'd like to see only the middle part of that wallpaper to show in that case or maybe have another wallpaper load up automatically when external monitors are disconnected. I hope someone can help me or direct me in the right way to make this a better experience.

I did find a command line tool called disper of which i've read the man page and tried a bunch of commands but I don't think it's able to do what I want.

The paths to my wallpapers are:


Best Answer

  • 1. Script to run your command if four screens are connected

    The script below is an edited version of this one.

    What it does

    Once per five seconds, it checks the number of connected screens. If the number changes, and the total number of connected screens is four, it runs the xrandr command we found in the comment(s).

    How to use

    1. Copy the script into an empty file, save it as four_screens.py
    2. Test run the script from a terminal with the command:

      python3 /path/to/four_screens.py

      and connect your screens. After the fourth is connected, your screen setup should be made.

    3. If all works fine, add the script to Startup Applications: Dash > Startup Applications > Add. Add the command:

      python3 /path/to/four_screens.py
    #!/usr/bin/env python3
    import subprocess
    import time
    #--- set both commands (connect / disconnect) below
    connect_command = "xrandr --output DP-2 --pos 0x0 --mode 1920x1200 "\
                      "&& xrandr --output HDMI-0 --pos 1920x0 --mode 1920x1200 "\
                      "&& xrandr --output DP-3 --pos 3840x0 --mode 1920x1200 "\
                      "&& xrandr --output eDP-1-1 --off"
    disconnect_command = ""
    while True:
    # function to get the output of xrandr
    def get(cmd): return subprocess.check_output(cmd).decode("utf-8")
    # - to count the occurrenc of " connected "
    def count_screens(xr): return xr.count(" connected ")
    # - to run the connect / disconnect command(s)
    def run_command(cmd): subprocess.Popen(["/bin/bash", "-c", cmd])
    # first count
    xr1 = None
    while True:
        # second count
        xr2 = count_screens(get(["xrandr"]))
        # check if there is a change in the screen state
        if xr2 != xr1:
            if xr2 == 4:
                # command to run if connected (two screens)
            elif xr2 == 1:
                # command to run if disconnected (one screen)
                # uncomment run_command(disconnect_command) to enable, then also comment out pass
                # run_command(disconnect_command)
        # set the second count as initial state for the next loop
        xr1 = xr2


    1. The script is extremely low on juice, it adds no noticeable burden whatsoever.
    2. In the same script, we can run the wallpaper change, but to do so, please post the (path to) the two wallpapers into your question.

    2. Alternatively, a shortcut

    If, for whatever reason, you'd prefer not to run a background script, you can run the same command through a keyboard shortcut:

    Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    /bin/bash -c "xrandr --output DP-2 --pos 0x0 --mode 1920x1200 && xrandr --output HDMI-0 --pos 1920x0 --mode 1920x1200 && xrandr --output DP-3 --pos 3840x0 --mode 1920x1200 && xrandr --output eDP-1-1 --off"
  • Related Question