You are not logged in.
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
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
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
Why is it a bad idea to fork xrandr calls in the .xinitrc?
Offline
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