0

I have a desktop computer with a Radeon R7 360 and FOS-drivers. My main display, which I am using always, is connected to the DVI-port and my TV is connected to the HDMI-out, in case I want to put any videos or films on or just need an extra display.

However, when I turn my TV on and it is recognised by Ubuntu, the additional space is always added to the wrong side. I usually choose to "expand the desktop to the right side", but what actually happens is my main desktop is then displayed on the TV and my regular monitor is "added" to its space. I then always have to go into the settings and drag the displays in correct order, this setup is also not saved, since I have to redo this procedure every time I turn on my TV to expand my desktop.

Is there any solution for this or does someone have an idea on where to set up a fixed configuration for my two displays?

I am currently using Ubuntu Studio 15.10 with Xfce.

Edit: This is the output of xrandr:

Screen 0: minimum 320 x 200, current 4480 x 1080, maximum 16384 x 16384
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected 1920x1080+2560+0 (normal left inverted right x axis y axis) 160mm x 90mm
   1920x1080     60.00*+  50.00    59.94    30.00    25.00    24.00    29.97    23.98  
   1920x1080i    60.00    50.00    59.94  
   1280x1024     60.02  
   1360x768      60.02  
   1152x864      59.97  
   1280x720      60.00    50.00    59.94  
   1024x768      60.00  
   800x600       60.32  
   720x576       50.00  
   720x576i      50.00  
   720x480       60.00    59.94  
   640x480       60.00    59.94  
   720x400       70.08  
DVI-0 connected primary 2560x1080+0+0 (normal left inverted right x axis y axis) 673mm x 284mm
   2560x1080     60.00*+
   1920x1080     60.00  
   1680x1050     59.88  
   1280x1024     75.02    60.02  
   1280x800      59.91  
   1152x864      75.00  
   1024x768      75.08    60.00  
   800x600       75.00    60.32  
   640x480       75.00    60.00  
   720x400       70.08  
1
  • 1
    Could you add the output of xrandr somewhere if your setup is correct? It is a bug, bug still can be fixed with a workaround. Feb 13, 2016 at 18:23

2 Answers 2

4

It appears your TV is physically disconnected when you switch it off, else it won't possibly lose the set up. Below two options to solve the issue, which is most likely the result of a bug:

  1. The (background) script below (option [1.] should automatically move the TV screen (in your case: HDMI-0) to the right of your main screen, if it was connected after being disconnected.
  2. The keyboard shortcut does the same, but manually after connecting (switching on) the TV.

1. A background script, automatically setting the second screen

The script is written in such a way that it takes the screen you want to appear on the right (the one that is disconnected now and then) as an argument (see explanation below). Therefore, it works with any combination of screens, you only need to enter the name of the right screen into the command. The script will find the resolution of the left screen, for correct positioning.

The script

#!/usr/bin/env python3
import subprocess
import time
import sys

"""
This script is a fix for what is presumably a bug, causing the secundary screen
to appear on the left side instead of the right side of the "main" screen.
Run it in the background.
"""

#--- set your secundary (right) screen below
sec = sys.argv[1]
#---

scr_id = sec+" connected"

def get_xrandr():
    return subprocess.check_output("xrandr").decode("utf-8")

def get_setup():
    # returns output of xrandr if secundary monitor was connected (else None)
    get_xr = subprocess.check_output("xrandr").decode("utf-8")
    if scr_id in get_xr:
        return get_xr

def get_xshift(xr):
    # find connected screens (lines)
    mons = [l for l in xr.splitlines() if " connected" in l]
    # get name and x-size of main screen
    left = [l.split() for l in mons if not l.startswith(scr_id)][0]
    return [(left[0], s.split("x")[0]) for s in left if s.count("+") == 2][0]

check1 = []
while True:
    time.sleep(4)
    check2 = get_setup()
    if check1 != check2:
        # on change in monitor setup:
        if check2 != None:
            # if secundary monitor was just connected
            print("run setup")
            x_shiftdata = get_xshift(check2)
            cmd1 = ["xrandr",  "--output", x_shiftdata[0], "--pos", "0x0"]
            cmd2 = ["xrandr",  "--output", sec, "--pos", x_shiftdata[1]+"x0"]
            for cmd in [cmd1, cmd2]:
                subprocess.call(cmd)
    check1 = check2

How to use

  1. Copy the script into an empty file, save it as screen_set.py
  2. Test- run it with the secondary screen as an argument with the command:

    python3 /path/to/screen_set.py HDMI-0
    

    (since HDMI-0 is your secondary screen) Disconnect (switch off) the TV and connect it again, it should appear on the right side.

  3. If all works fine, add it to Startup Applications, with a little break: Dash > Startup Applications > Add. Add the command:

     /bin/bash -c "sleep 15 && python3 /path/to/screen_set.py HDMI-0"
    

Now it should be solved.

2. Alternatively; a keyboard shortcut

The background script adds practically nothing to the processor load, and will not be noticed whatsoever. If you however would prefer a keyboard shortcut to an (automatically working) background script, add the command:

/bin/bash -c "xrandr --output DVI-0 --pos 0x0 && xrandr --output HDMI-0 --pos 2560x0"

which will do the same, but manually: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

/bin/bash -c "xrandr --output DVI-0 --pos 0x0 && xrandr --output HDMI-0 --pos 2560x0"

Explanation; the background script

  • Once per four seconds, the script checks if the TV is connected by checking if the string HDMI-0 connected is in the output of the command xrandr.
  • (Only) if there is a change in the state: False -> True, the script runs the command (in your case):

    xrandr --output DVI-0 --pos 0x0 && xrandr --output HDMI-0 --pos 2560x0
    

    which arranges your screens from left to right, as explained here. If your screen resolutions are different however, the script looks up the correct figures and the name of the main screen. As long as you use the secondary screen as an argument, it works fine.

4
  • Thanks Jacob, you're a magician! I just had time to try out the script and it works perfectly, really cool. Maybe a note on debugging: I noticed that I identified the problem incorrectly, the TV is actuall added to the right, the only problem is that additionally the main display with the panel is moved from the main monitor to the TV. What confused me is that my TV is actually physically located to the right of me. Now it automatically switches them back. Feb 16, 2016 at 15:08
  • @Prototype700 Great! I am not sure what your comment sais, is (was) the launcher moved to the right screen? (can be fixed) and is all working like you want or do we still have some work to do? Feb 16, 2016 at 15:11
  • 1
    This was before using the script, because I had noticed what exactly was going wrong with the displays. I just thought I'd mention it since you obviously have an understanding of the issue in general or maybe it will help someone to identify the problem. Everything works great now for me, this is better than I had expected. Also love it how you write "do we still have some work to do" as if I had any part in you writing this awesome script. ;-) Feb 17, 2016 at 11:34
  • @Prototype700 Perfect, thanks, and I am glad it works :) Feb 17, 2016 at 11:47
2

I have an ATI R5 card that never saves my graphics layout for my three monitors using xfce4-display-settings. ARandR should solve your issue. Install by typing the following in terminal:

sudo apt-get install arandr

Use ARandR to configure your screens, save it to a script (Layout > Save As), and set it to run as a Session and Startup > Application Autostart item. (You may need to set it to sleep 5 first before running the layout script.)

If you have two different layouts that you use, you can configure each of those with ARandR. Then you can run one script or the other depending on which layout you want. Or, better yet, you could assign each to their own keyboard shortcut if so desired.

2
  • In case you'd like to use a startup or shortcut command, no need to install Arandr or any other additional software. xrandr does the job . Feb 14, 2016 at 7:19
  • You're correct. ARandR is only used to output content into the script. Later it can be uninstalled.
    – jbrock
    Feb 14, 2016 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .