You are not logged in.

#1 2021-03-05 15:21:02

Dun
Member
Registered: 2014-12-28
Posts: 98

[SOLVED] .xprofile for multiple monitors / xorg.conf multihead

I have 3 displays connected to my machine. One uses VGA and the other two are using HDMI/DP adapters. X starts the display with VGA at 640x480 and the position of the displays is always reset.
So I created an .xprofile file.

#!/bin/bash
xrandr --output VGA1 --mode 1920x1080
xrandr --output HDMI1 --right-of VGA1
xrandr --output HDMI2 --same-as HDMI1

But when I run it with xinit the i3 wm takes about 10 seconds to load and HDMI2 is the same as VGA1. When I run it manually inside i3 it works.
I also tried using the .xprofile file as the display-setup-script in LightDM with but that also takes about 10 seconds to load and afterwards LigthDM is kinda frozen. I'm able to enter my password but I can't really use LightDM since all animations only flicker and it only displays the first frame all the time. Also the only display that shows LightDM is VGA1.

I think the last line with the --same-as flag is the problem but how could I solve it without having to run the .xprofile always manually?

Last edited by Dun (2021-03-09 23:26:56)

Offline

#2 2021-03-05 16:07:30

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Rather try https://wiki.archlinux.org/index.php/Mu … _xorg.conf and make sure that you don't fork the xprofile execution if you want to stick with it.
Are the outputs btw. connected to the same GPU?

Offline

#3 2021-03-06 16:55:58

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

Rather try https://wiki.archlinux.org/index.php/Mu … _xorg.conf and make sure that you don't fork the xprofile execution if you want to stick with it.

Thanks! With the configuration file it works without any issue. I had trouble to find an equivalent for --same-as until I realized I could simply use the position option to mirror the screens.
Modeline for VGA1 doesn't work though and I had to comment it out for the monitor to work. Is it an issue to have a monitor without that configuration line?

seth wrote:

Are the outputs btw. connected to the same GPU?

I only have the onboard GPU of the CPU.

Offline

#4 2021-03-06 20:31:00

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

You do absolutely not have to add a modeline, certainly not a random one.
The system typically gets them via EDID (ie. your output says what resolutions and frequencies it supports)

Offline

#5 2021-03-07 12:39:32

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

You do absolutely not have to add a modeline, certainly not a random one.
The system typically gets them via EDID (ie. your output says what resolutions and frequencies it supports)

Thanks for the information.

But I have another problem I hadn't considered. When I resume the computer after suspension and VGA1 and HDMI1 are turned off (physically off but still connected), HDMI2 is at the position 0 0 and not 1920 0 anymore. I'm not sure how I could change my config so that won't happen anymore.

(0,0)-----------------+(1920,0)--------------+
|                     ||                     |
|     1920 x 1080     ||     1920 x 1080     |
|        VGA1         ||        HDMI1        |
|                     ||        HDMI2        |
+---------------------++---------------------+
Section "Monitor"
  Identifier "VGA1"
  Option "PreferredMode" "1920x1080_60.00"
  Option "LeftOf" "HDMI1"
  Option "Position" "0 0"
  Option "DPMS" "true"
EndSection

Section "Monitor"
  Identifier "HDMI1"
  Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120>
  Option "PreferredMode" "1920x1080_60.00"
  Option "Position" "1920 0"
  Option "RightOf" "VGA1"
  Option "DPMS" "true"
EndSection

Section "Monitor"
  Identifier "HDMI2"
  Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120>
  Option "PreferredMode" "1920x1080_60.00"
  Option "Position" "1920 0"
  Option "RightOf" "VGA1"
  Option "DPMS" "true"
EndSection

Last edited by Dun (2021-03-07 13:56:52)

Offline

#6 2021-03-07 12:47:48

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

"Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120>" is not a leal modeline, also remove those parts from the config entirely and rely on the EDID data.
Eg. the PreferredMode for VGA1 doesn't even exist.

  Option "Position" "1920 0"
  Option "RightOf" "VGA1"

You've a relative and an absolute postition. Pick one. This also holds for VGA1.

Post the cleaned up config and report whether the S3/wake issue remains with those.

Offline

#7 2021-03-07 13:23:44

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Section "Monitor"
  Identifier "VGA1"
  Option "PreferredMode" "1920x1080_60.00"
  Option "Position" "0 0"
  Option "DPMS" "true"
EndSection

Section "Monitor"
  Identifier "HDMI1"
  Option "PreferredMode" "1920x1080_60.00"
  Option "Position" "1920 0"
  Option "DPMS" "true"
EndSection

Section "Monitor"
  Identifier "HDMI2"
  Option "PreferredMode" "1920x1080_60.00"
  Option "Position" "1920 0"
  Option "DPMS" "true"
EndSection

Sadly the issue persists. If I wake up HDMI2 is at position 0 0 instead of 1920 0.

Last edited by Dun (2021-03-07 13:25:37)

Offline

#8 2021-03-07 13:26:51

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Remove the "PreferredMode", but that's likely not the cause.
I assume what happens is that HDMI2 shows up before VGA - can you swap their positions and does that survive an S3?

Offline

#9 2021-03-07 13:39:57

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Yes removing PreferredMode has no effect. After the wakeup I'm able to change the position of HDMI2 back to 1920 0 with xrandr but it always changes back to 0 0 on the next wakeup.

Offline

#10 2021-03-07 13:41:56

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

What I meant was to use 'Option "Position" "1920 0"' for VGA1 and 'Option "Position" "0 0"' for HDMI2 (swap them) and whether that's stable against an S3

Offline

#11 2021-03-07 13:49:01

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Now VGA1 is at 0 0 after the wakeup and HDMI2 stays at 0 0.

Offline

#12 2021-03-07 14:41:29

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Meh.
They're either juggled at the suspend or at the resume - I don't see how you cold prevent that (if there's nothing left at 0x0, something will move there…)

You could go w/ a sleep hook, https://wiki.archlinux.org/index.php/Po … stem-sleep
You'll need proper DISPLAY and XAUTHORITY for your user/session, https://gist.github.com/AladW/de1c5676d93d05a5a0e1

Offline

#13 2021-03-07 22:51:23

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

Meh.
They're either juggled at the suspend or at the resume - I don't see how you cold prevent that (if there's nothing left at 0x0, something will move there…)

You could go w/ a sleep hook, https://wiki.archlinux.org/index.php/Po … stem-sleep
You'll need proper DISPLAY and XAUTHORITY for your user/session, https://gist.github.com/AladW/de1c5676d93d05a5a0e1

Are these proper?

$ echo $DISPLAY   
:0
$ echo $XAUTHORITY
/home/dun/.Xauthority

I can't run the script because fgconsole throws this

Couldn't get a file descriptor referring to the console.

and

pgrep -t tty1 xinit

returns error code 1. I also tried other terminals but no luck.

I created /usr/lib/systemd/system-sleep/monitor.sh.

#!/bin/sh
case $1/$2 in
  pre/*)
    ;;
  post/*)
    # Waiting for a few seconds doesn't work
    sleep 5
    xrandr --output HDMI2 --pos 1920x0 
    ;;
esac

The hook executes but HDMI2 is still a 0 0.

Offline

#14 2021-03-08 06:15:44

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Are these proper?

"plausible"

pgrep -t tty1 xinit
returns error code 1

The actual script makes some assumptions about your session, in particular that it's started w/ xinit

man pgrep wrote:

EXIT STATUS
       0      One or more processes matched the criteria. For pkill the process  must  also  have
              been successfully signalled.
       1      No processes matched or none of them could be signalled.
       2      Syntax error in the command line.
       3      Fatal error: out of memory etc.

The hook executes but HDMI2 is still a 0 0.

W/o the proper environment, xrandr won't do anything (but yell an error about the display  not being found)

Offline

#15 2021-03-08 11:26:39

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

The actual script makes some assumptions about your session, in particular that it's started w/ xinit

I was using LightDM and therefore didn't get the PID of xinit. I switched to xinit and ran the script (without fgconsole, just with pgrep -t tty1 xinit). The script executed without any errors but the xrandr command of the sleep hook still doesn't work.

seth wrote:

W/o the proper environment, xrandr won't do anything (but yell an error about the display  not being found)

How would a proper environment look like? I find little information on this topic that I understand.

Offline

#16 2021-03-08 13:36:36

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

The proper environment are the correctly exported DISPLAY and XAUTHORITY variables.

"Doesn't work" isn't a useful problem description.
Does *this* randr command fail or does any one (eg. selecting a different mode) fail?
Did you try to redirect the xrandr output into a file ("xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1")?

Offline

#17 2021-03-08 20:13:58

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

Did you try to redirect the xrandr output into a file ("xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1")?

Right I didn't think about that.

seth wrote:

Does *this* randr command fail or does any one (eg. selecting a different mode) fail?

Yes it fails.

Can't open display

If I add -d :0 it's

No protocol specified
Can't open display :0

Changing the mode or the brightness of all displays outputs the same.

Offline

#18 2021-03-08 21:03:49

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Post your current script and maybe echo out the values you actually obtain for DISPLAY and XAUTHORITY.

Offline

#19 2021-03-09 15:18:39

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

#!/bin/sh
case $1/$2 in
  pre/*)
    ;;
  post/*)
    xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
    ;;
esac

DISPLAY and XAUTHORITY aren't set, they echo an empty string.

Offline

#20 2021-03-09 15:43:04

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

Well, ensure to set them (and actually also pre-sleep a bit because we assume the output appears late)

Offline

#21 2021-03-09 16:36:15

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

Well, ensure to set them

You mean in the script like this? It still fails like before. They are now definitely set as I can echo them.

#!/bin/sh
case $1/$2 in
  pre/*)
    ;;
  post/*)
    export $DISPLAY=":0"
    export $XAUTHORITY="/home/dun/.Xauthority"
    xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
    ;;
esac
seth wrote:

(and actually also pre-sleep a bit because we assume the output appears late)


I'm not sure what you mean by that. Do you mean I have to use the sleep command to wait for a few seconds pre sleep?

Offline

#22 2021-03-09 21:31:32

seth
Member
Registered: 2012-09-03
Posts: 59,737

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

You mean in the script like this?

https://wiki.archlinux.org/index.php/En … _variables

export DISPLAY=:0
export XAUTHORITY=/home/dun/.Xauthority

Also read them in your active session to ensure that those are actually the required values.

I'm not sure what you mean by that.

…
sleep 5 # wait for the output
xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
…

If this *still* all fails, run xrandr as your user

…
sudo -u dun xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
…

Offline

#23 2021-03-09 23:26:26

Dun
Member
Registered: 2014-12-28
Posts: 98

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

I tried sleep and running it as a different user before but without the environment variables. I thought it would be enough to export them in .xinitrc. But finally it works now like this.

#!/bin/sh
case $1/$2 in
  pre/*)
    ;;
  post/*)
    export DISPLAY=:0
    export XAUTHORITY=/home/dun/.Xauthority
    sleep 1
    xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
    ;;
esac

Thank you very much for the help and sorry for my incomprehention.

Offline

#24 2021-07-03 08:45:19

SimonJ
Member
Registered: 2021-05-11
Posts: 184

Re: [SOLVED] .xprofile for multiple monitors / xorg.conf multihead

seth wrote:

If this *still* all fails, run xrandr as your user

…
sudo -u dun xrandr --output HDMI2 --pos 1920x0 > /tmp/randr.dbg 2>&1
…

I just wanted to highlight the sudo part is needed with a script I was having issues with. This is really valuable and I am glad I found it. Thanks for posting it.


Rlu: 222126

Offline

Board footer

Powered by FluxBB