I want to enable a sub-display only when I use it, so I ran the command xrandr --output HDMI-A-0 --auto, but I had to run it twice to get it to work. Why is that?
Are you logged in under Wayland or gnome/xfce? I ask because Wayland doesn't use the Xorg service, which needs to start for xrander to work. That would be why you have to enter it twice the first time. It is starting the service, then you can access it. Maybe adding it to startup applications so you only have to enter the command once.
Gday @Hackgets
I was thinking adding --force?
or even --primary then reverse --noprimary, but this may change default settings of screens..
i looked the following link, & in section #3
There is a good BASH script to maybe help..
#!/bin/sh
intern=LVDS1
extern=VGA1
if xrandr | grep "$extern disconnected"; then
xrandr --output "$extern" --off --output "$intern" --auto
else
xrandr --output "$intern" --off --output "$extern" --auto
fi
Note: To leave the default monitor enabled when an external monitor is connected, replace the else clause with xrandr --output "$intern" --primary --auto --output "$extern" --right-of "$intern" --auto
Also a wrapper for Xrandr called xrasengan.
& you can use something like this,
$ xrasengan --force -on DisplayPort-0 -off HDMI-0
Thanks @Ocka ! I found that the cause of this problem was that my PC had one HDMI and one DP port and I was using both. Then I decided to use a more primitive workaround.