I want to use the CLI to switch the “primary” property between my monitors. I have the built-in screen of my laptop and an external screen connected by HDMI.
I found a lot of advice for using xrandr (on Ubuntu forum mainly, though I’m on Manjaro). However, it doesn’t work for me.
Here’s (what I think is) the relevant part of the output of:
> xrandr
Screen 0: minimum 320 x 200, current 1920 x 2160, maximum 16384 x 16384
eDP-1 connected 1920x1080+0+1080 (normal left inverted right x axis y axis) 344mm x 193mm
1920x1080 144.00*+ 60.02 59.97 59.96 59.93
1680x1050 59.95 59.88
% [...] %
320x175 85.27
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00*+ 74.97 50.00 59.94
1600x900 60.00
% [...] %
720x400 70.08
DP-1-0 disconnected (normal left inverted right x axis y axis)
DP-1-1 disconnected (normal left inverted right x axis y axis)
… just trying to give direction - I don’t know how to do what you want to do …
You’ll need to figure this (above) out first.
look at what the term in the brackets returns -
xrandr --listactivemonitors
the output of which you then feed to awk
for me, it returns two lines (I currently have only one monitor connected) -
the 4th field you are trying to catch is on the second line of two in total …
it’s likely four lines in total for two monitors … and so on
what you are after is on each second line - awk looks at the first line first (I guess)
so: the result will start with an empty line which probably needs to be taken care of
However, now that it’s fixed it gives the same result as the other two commands (which makes sense, I guess): command succesful, no text output in the terminal, and no effect on which screen is primary.
As an advice, multiple bugs related to multi monitors support were only fixed for Wayland, it might be good to use it, and if you insist on using cli then you can do it via kscreen-doctor command.
Well, CLI is not, in my opinion, the complicated option. I switch primary monitor at least 15 times a day (because I don’t use the same primary for video games and working), so doing it via GUI requires at least 5 clicks on various small buttons on the screen(s). A command takes about 1.5s to launch via KRunner, so to me that’s the simple and efficient option.
Yup, amazing, it works perfectly. For anyone else trying to do this, the command I’m using from now on is: