You are not logged in.

#1 2021-06-16 16:00:57

Nilas
Member
Registered: 2020-11-10
Posts: 46

Output only to external monitor when starting Xorg

Hi, whenever my laptop is connected to my external monitor and I boot up my laptop, I would like it to only output to the external monitor when entering the Xorg display server. If my laptop is not connected to an external monitor it should output to the laptop display instead. I am not sure how to achieve this. Without any configuration I get output to both my laptop display and external monitor when entering the Xorg display server after boot. I tried to add the following to my .xinitrc file:

intern=eDP-1-1
extern=DP-2

if xrandr | grep "$extern disconnected"; then
    xrandr --output "$extern" --off --output "$intern" --auto
else
    xrandr --output "$intern" --off --output "$extern" --auto
fi

This does result in the Xorg display server getting shown on only my external monitor when entering Xorg after boot, but when I try to switch back to my laptop monitor I get a black screen on my laptop monitor with only the cursor showing. I do not have this problem when I boot up my laptop without having the external monitor connected. Then I can switch back and forth between the two monitors without any issues. It should be mentioned that I have the same problem with the black screen when switching to my laptop monitor without the addition to .xinitrc and with my external monitor connected at boot up.

I am not sure if the addition to .xinitrc is the right solution or if there are better ways to do this.

Edit: I have created a separate topic for my problem with the black screen here. In this topic I would just like to know if my addition to .xinitrc is the proper way to only output to the external monitor on boot up if the external monitor is connected or if there are better ways.

Last edited by Nilas (2021-06-18 09:26:54)

Offline

#2 2021-06-18 09:34:41

Nilas
Member
Registered: 2020-11-10
Posts: 46

Re: Output only to external monitor when starting Xorg

Is it possible to use the Xorg configuration files instead to make my laptop only output to the external monitor when starting Xorg? My solution with the addition to the .xinitrc file does not seem optimal since my laptop will first output to both monitors and then switch to only one monitor, instead of directly just outputting to one monitor. What would be the right way to achieve this?

Offline

#3 2021-06-18 11:47:39

seth
Member
Registered: 2012-09-03
Posts: 51,145

Re: Output only to external monitor when starting Xorg

You can use a config file to control whether an output is enabled, but I'm not aware of conditioning this ("use this but only if that isn't there")
So you'll have to use some form of script. Make sure to not fork xrandr calls in the initrc.

Online

#4 2021-06-18 13:11:24

Nilas
Member
Registered: 2020-11-10
Posts: 46

Re: Output only to external monitor when starting Xorg

Why is it a bad idea to fork xrandr calls in the .xinitrc?

Offline

#5 2021-06-18 13:18:18

seth
Member
Registered: 2012-09-03
Posts: 51,145

Re: Output only to external monitor when starting Xorg

Because you'll create undeterministic behavior, eg. if you

xrandr --output FOO --mode 1234x567 &
exec windowmanager

it's not determinable which randr configuration the WM encounters and even if it listens to randr events, the actual change might get lost inbetween.

This goes for many server configurations, eg. setxkbmap or xset and other clients like compositors or shortcut daemons.

Online

Board footer

Powered by FluxBB