LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 08-27-2020, 09:12 AM   #1
bionor
Member
 
Registered: Dec 2019
Posts: 44

Rep: Reputation: 1
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:
Code:
# 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
I was able to partially resolve it. 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 (as long as both are connected) and for the full duration the machine has both screens attached, but 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.

Last edited by bionor; 08-27-2020 at 09:16 AM.
 
Old 08-27-2020, 09:42 AM   #2
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
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 the "dp1" port 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:
Code:
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; 08-27-2020 at 10:28 AM.
 
Old 08-27-2020, 04:26 PM   #3
bionor
Member
 
Registered: Dec 2019
Posts: 44

Original Poster
Rep: Reputation: 1
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)
Code:
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
Code:
#!/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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
3 monitor setup w/ the 3rd monitor being plugged into a Windows XP box dlublink Linux - Desktop 4 08-13-2009 12:45 AM
default monitor on nvidia / dual monitor setup fenderog SUSE / openSUSE 3 05-01-2009 05:36 PM
How to automatically disable dual monitor setup when only one monitor is present NielsKM Linux - Laptop and Netbook 1 01-01-2008 11:17 AM
3 Monitor setup, Only 1 Monitor can play videos. kierl Linux - Software 0 01-05-2005 07:45 PM
Booting to wrong Monitor (w/ dual monitor setup) NeoNostalgia Linux - General 1 06-30-2004 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration