You are not logged in.

#1 2020-08-26 18:00:06

bionor
Member
Registered: 2020-08-23
Posts: 15

Issue with TV screen + monitor setup

I've having an issue where my system struggles a bit with my dual screen setup. I have a TV connected via a receiver through HDMI and a monitor also connected via HDMI.

What happens is that xorg seems to struggle with hotplugging. When I start the computer I usually leave the receiver off until I need it (if for instance to watch a movie with Kodi). When I switch on the receiver it seems that the xorg.conf is reset or something which means I have to set it up again every time. It defaults to using the TV as the main screen as well as being on the wrong side (left vs right). Even when I've set it up correctly it sometimes switches back to default without switching anything off, for instance when I quit Kodi, the screens sometimes flash and reverts back to default.

https://wiki.archlinux.org/index.php/NV … e_monitors

In the article linked above I read that it might be possible to force a certain configuration with xorg.conf, but I'm somewhat unsure as to whether the scenario described there applies to my situation and how exactly to proceed as my setup is a little different to what is shown in it.

The issue is the same whether I use NVIDIA proprietary driver or nouveau. I'm currently using the nvidia driver as it lets me use full force composition to remove the screen tearing I otherwise get.

My /etc/X11/xorg.conf:

# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings:  version 450.66

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 450.66

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "0"
EndSection

Section "Files"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "PHILIPS FTV"
    HorizSync       30.0 - 83.0
    VertRefresh     56.0 - 76.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce GTX 970"
EndSection

Section "Screen"

# Removed Option "metamodes" "DP-5: nvidia-auto-select +1920+0 {ForceCompositionPipeline=On, ForceFullCompositionPipeline=On, AllowGSYNC=Off}, HDMI-0: nvidia-auto-select +0+0 {ForceCompositionPipeline=On, ForceFullCompositionPipeline=On, AllowGSYNC=Off}"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "Stereo" "0"
    Option         "nvidiaXineramaInfoOrder" "DFP-7"
    Option         "metamodes" "DP-5: nvidia-auto-select +1920+0 {AllowGSYNC=Off}, HDMI-0: nvidia-auto-select +0+0 {ForceCompositionPipeline=On, ForceFullCompositionPipeline=On, AllowGSYNC=Off}"
    Option         "SLI" "Off"
    Option         "MultiGPU" "Off"
    Option         "BaseMosaic" "off"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

Any clues as to what I can do to remedy this situation?

Offline

#2 2020-08-26 22:10:17

bionor
Member
Registered: 2020-08-23
Posts: 15

Re: Issue with TV screen + monitor setup

I might have been able to resolve it. At least partially. Turns out it's there's a xrandr settings daemon that overrides xorg.conf and all I had to do was to disable it. It works now for reboots and for the full duration the machine has both screens attached, but I haven't yet tested what happens when I switch off the receiver and how that affects the xorg config the next time I switch it on again.

Offline

#3 2020-08-27 14:22:34

bionor
Member
Registered: 2020-08-23
Posts: 15

Re: Issue with TV screen + monitor setup

I tested it and it doesn't work when I switch the receiver off or start the machine with it off. Then I have to re-enable the settings daemon in order for the monitor to get the correct resolution which means the Xorg.conf gets reset.

I'm thinking there may be a workaround by making two separate xorg.conf files (one for single monitor setup and one for dual setup) in a separate folder and then write a script that detects which setup is correct at any given moment and then symlinks /etc/X11/xorg.conf to the correct file for the current setup.

But I have no idea how to do that. Something something udev perhaps? I really hope someone can help me a little bit with this. This is something which have been bothering me for a very long time and now finally I feel like I'm getting closer to a solution, but need some help with the last steps.

Offline

#4 2020-08-27 14:57:15

bionor
Member
Registered: 2020-08-23
Posts: 15

Re: Issue with TV screen + monitor setup

I found out there's an app called arandr which helps with creating scripts for various setups, which I did. I guess now the only thing left is to automate it. How do I create a script which detects whether port X is the only one in use and run the proper script and otherwise run the other script?

EDIT:
I found out there's a setting I can apply for xorg.conf which makes xorg pretend both screens are always connected which works:

Option "AllowEmptyInitialConfiguration" "true"

But with this enabled I get a black background on both screens and attempts to set a new one doesn't change anything.

Last edited by bionor (2020-08-27 15:26:32)

Offline

#5 2020-08-27 20:56:35

bionor
Member
Registered: 2020-08-23
Posts: 15

Re: Issue with TV screen + monitor setup

I've made a script which is able to detect what the setup is and apply the correct configuration, which I've set to run after login and it works great.

Now the only problem is to figure out how to make that script run when the extra screen is plugged in/unplugged.

I've tried following the various solutions in the link below
https://bbs.archlinux.org/viewtopic.php … 5#p1329375

But the udev rules don't seem to work.

Any ideas? At least now I've come a pretty long ways toward a solution.

Last edited by bionor (2020-08-27 20:57:00)

Offline

#6 2020-08-27 21:20:57

bionor
Member
Registered: 2020-08-23
Posts: 15

Re: Issue with TV screen + monitor setup

Okay I've solved it smile Well, not in the way I wanted it, but from searching the webs it seems making the udev rule work consistently can be difficult. What I've done instead is have a script run in the background which check every 5 seconds for a change in connection status and runs the script that applies the correct setup in the event of a change.

The script i made which checks whether to apply single or dual screen setup: (apologies for poor coding, I'm a newbie in that regard)

constat=$(xrandr | grep -w "connected") 	# Get connection status
lines=$(xrandr | grep -w "connected" | wc -l) 	# Count number of connected devices
hdmi=$(echo $constat | grep "HDMI")		# Check if HDMI is connected

if [[ $lines == "2" ]]; then
   if [ -z "hdmi" ]
   then
      echo "Unknown setup"
   else
      source /home/bio/.screenlayout/dualsetup.sh # There are two connected devices and one of them is an HDMI, execute dual setup
   fi 
  else source /home/bio/.screenlayout/singlesetup.sh # There is only one connected screen, execute single setup
fi

The background script found @ https://askubuntu.com/questions/630202/ … -connected

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

#--- set both commands (connect / disconnect) below
connect_command = "gedit"
disconnect_command = ""
#---

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:
    time.sleep(5)
    # second count
    xr2 = count_screens(get(["xrandr"]))
    # check if there is a change in the screen state
    if xr2 != xr1:
        print("change")
        if xr2 == 2:

            # command to run if connected (two screens)
            run_command(connect_command)
        elif xr2 == 1:
            # command to run if disconnected (one screen)
            # uncomment run_command(disconnect_command) to enable, then also comment out pass
            pass
            # run_command(disconnect_command)
    # set the second count as initial state for the next loop
    xr1 = xr2

I've set this up to run as a startup application in my DE.

Not sure if I like the idea of this running at all times though. How to set up a udev rule or similar that works?

If there's no replies, then at least hopefully this can help someone else struggling with their setup as I did.

Last edited by bionor (2020-08-27 21:22:41)

Offline

Board footer

Powered by FluxBB