I used to chuckle smugly whenever Liam wrote an article about yet another game that launches on the wrong monitor. That was never an issue for me on my single monitor set up, so continual woe for him was continual wry humour for me.
But in April this year, I did my first PC upgrade in over five years. It was a big upgrade, featuring both an epic graphics card and a shiny new Acer Predator monitor. But now I had a dilema... what do I do with the old 22" monitor I was using beforehand? You guessed it, I connected it up and placed it off to one side, the better to keep Chrome and Steam in view while gaming.
And of course, I immediately joined the "Wrong Monitor" crowd. If I'd known how frustrating this was, I'd have kept that smug grin off my face earlier. Clearly, karma likes to hit schadenfreude when it's down and Liam can consider this article my written and profuse apology.
It was pure torment. The order I connected them in was irrelevant. Display settings was irrelevant. Various xrandr endevours ended in frustration. In fact, the only thing I found that would make a difference was a tick box in Nvida Settings called "Make this the primary display for the X screen":
But while that largely worked, it didn't stick between reboots, even when you hit "Save to X configuration File". It saved, but the tick always reverted to the wrong monitor regardless. Infuriating!
But that led, eventually, after far too much googling, to a potential solution. It's courtesy of this Ask Ubuntu answer, which I'll summarise here too. It's really straightforward. In fact, if you already know the device names of your monitors, you can skip straight to the final step!
1. First, install the arandr tool, which is a little GUI app to show monitor device names:
sudo apt-get install arandr
2. Then run it:
arandr
...and note the name of the monitor you wish to be primary. For me that was DP-5.
3. Finally, run xrandr to make that monitor the primary display:
xrandr --output DP-5 --primary
As noted in the original article, you can easily put that exact command into your Startup Applications directly to run this every time you log in to your PC.
For me, problem solved. If this works for you, be sure to upvote Etron's answer on Ask Ubuntu!
However, some have reported that this is only half the battle! There is one more step you might want to try. Having run all of the above, you might also need to:
- Browse to ~/.config/ and take a copy of your original monitors.xml file (just in case!)
- Delete the original - the next step will recreate it anyway.
- Open your system's control panel and choose displays (or in Ubuntu's case, run unity-control-centre display), then hit "apply" to create a new monitors.xml.
You can open this file in a text editor (such as gedit, geany or nano) and just make sure that only one of the entries has a "yes" against its "primary" field.
Also, GOL editor BTRE has a novel approach to this problem, using a custom xorg.conf. I've included his personal xorg.conf in a spoiler below. Note that his xorg.conf is for his mesa set up and doesn't actually include any options regarding primary monitor. For example, he has a TV set up in there which is disabled by default, but ready to be used if he activates it manually. So if you go down this road, make sure to add
Option "Primary" "true"
...to one of your "Monitor" sections!
But if all else fails, or if you don't like the idea of running xrandr in a startup script on every login, maybe this will work for you.
Section "Monitor"
Identifier "DisplayPort-0"
Option "Primary" "true"
Option "DPMS" "false"
EndSection
Section "Monitor"
Identifier "DisplayPort-1"
Option "RightOf" "DisplayPort-0"
Option "DPMS" "false"
EndSection
Section "Monitor"
Identifier "TV"
# Option "Ignore" "true"
Option "Disable" "true"
Option "RightOf" "DVI-D-0"
Option "DPMS" "false"
EndSection
BTRE's note: The above is in /etc/X11/xorg.conf.d/10-monitor.conf The important bits are "Primary" and the positioning "RightOf", the rest is just stuff that may not apply to you (I prefer not to use DPMS and have a TV hooked up on HDMI I'd rather not get used until needed). This is just stuff you can find out more about in the Arch wiki.
If you have an alternative and/or bulletproof method, please (please!) share it in the comments. But so far, for me, the xrandr procedure I outline here has worked a treat.
Unity games in particular seem to offset the mouse slightly...If this happens consistently, please file a bug report. :)
There is no bulletproof method, since you're setting only the default. Any app can still ignore it and implement its own logic. This might be better with Wayland.
Yeah, that's a really good point. What's odd though is that Liam is having trouble with DOTA2, but it works okay for me. Similarly, MayeulC noted above that there are issues with Payday2, but again, I'm alright. It's just so inconsistent. Maybe you're right about Wayland, but that still feels years away (for Nvidia people at least).
Gotcha. Honestly, I'd have given KDE a shot if I'd known that. But I'm glad this fixes it for me, since I do prefer gnome to KDE. Although, my last KDE trip was back in the early KDE4 days so that's probably not a fair comparison.
I haven't used GNOME since like 3.22 or something, but last time I tried, KDE had way~ better multiscreen support.
Here's the older versions of the scripts. Haven't finalized the newer version. I gave up on GDM presession and am now writing the script for /etc/X11/xinit/xinitrc.d/ as it works from there. Note the set -- command is flawed, but you get the idea.
https://github.com/drlamb/caen-gdmscripts/blob/master/Default-presession
EDIT: Just in case anyone is interested, I have done a little housekeeping and uploaded my xorg.conf:
http://icculus.org/~hamish/configs/xorg.conf
Last edited by Hamish on 20 September 2017 at 3:52 pm UTC
For streaming games to a steam-link, can I somehow configure it to just mirror one specific monitor? I currently use an arandr script to switch to single-monitor, but don't really like this approach.
Well, you're assuming the application doesn't capture the mouse and doesn't behave weirdly when moved between monitors.Well, I'm assuming Alt+Tab is a thing (are there desktops where it's not?), but point taken about potential weird behavior when moving between windows.
I rarely use my 2nd monitor for playing games and when I need it I add the line "export DISPLAY=0:1" to the start script.
2 X screens never failed me regardless of game engine or wine.
Last edited by Avehicle7887 on 21 September 2017 at 10:53 am UTC
I'm not at home this week so unable to post my xorg config however, I run my 2 displays as 2 separate x screens which means whatever happens on one screen will not affect the other. The only limitations are that you can't drag windows from one another.
2 X screens never failed me regardless of game engine or wine.
Similar to how Hamish runs his set up. I'd miss dragging screens over - I run Chrome and the Steam client off to the side when I'm gaming, but I prefer to work on the much bigger Acer screen when I'm not, so I just drag my Chrome browser over. Sure, I could kill it and restart, but for me, that's nowhere near as optimal.
The solution in this article has been perfect for me so far. Hopefully it helps someone else.
There is no bulletproof method, since you're setting only the default. Any app can still ignore it and implement its own logic. This might be better with Wayland.
Yeah, that's a really good point. What's odd though is that Liam is having trouble with DOTA2, but it works okay for me. Similarly, MayeulC noted above that there are issues with Payday2, but again, I'm alright. It's just so inconsistent. Maybe you're right about Wayland, but that still feels years away (for Nvidia people at least).
In general, it's better to have your primary screen on the left side. Apps which override the default behavior usually use the monitor with 0,0 coordinates. This might explain some of the differences (different people have primary monitor placed differently).
Maybe you're right about Wayland, but that still feels years away (for Nvidia people at least).
Pick a vendor with better drivers next time :) But Wayland has its share of problems, you're not missing much yet, especially for a gaming use case.
The config options for either Ubuntu or Mint, choose display, there you can set the primary monitor, and it will stick.
NVsettings, well, run as sudo and sometimes it does work. I prefer the base tool in the distro myself.
You can send the games (some) to another monitor, but sometimes it decides to move back, if you alt-tab out.
Annoying, particularly when streaming. Oh hey, that's my desktop not the game, grumble.
Mint at least also lets you keep the primary for games where you want, then move the toolbar elsewhere.
:)
Same for 3 monitors.
The config options for either Ubuntu or Mint, choose display, there you can set the primary monitor, and it will stick.
I'm not sure what you mean here. I run Ubuntu and there's no "choose display" option that I know of. Hence the article!
The GDM presession script determines which monitor configuration (according to my workplace's unique configurations) is present and disables the secondary monitor until login is achieved at which point the other script takes over and detects again what configuration is present and re-initializes the previously disabled display to be the desired dual monitor configuration.
Github
Whatever. I tend to run games windowed because with the pixel saver addon, the top bar is really unobtrusive and it's nice to see the time onscreen.
Setup a new user. I called mine "steam".
Install openbox. It's small and harmless: "sudo apt install openbox"
You can now select openbox as a session when you login. It is an EXTREMELY lightweight session that opens only to a blank screen. You can right click the blank screen to get a terminal if you need it.
From the terminal or by logging in as that user normally, install steam for that user.
Find the name of the secondary monitor you don't care about by typing "xrandr" and figuring it out from the connector. If you don't have xrandr (I think you will) then "sudo apt install xrandr".
Create and edit a file "/home/steam/.config/openbox/autostart" (Replacing "steam" with whatever you named your user).
Put the following in the startup:
xrandr --output [your monitor] --off
sleep 2
steam &
Replacing your monitor with the one you don't want. Mine was "DVI-I-1" for example. If you're not sure, try the command from a terminal. It won't save it if you screw up, you can just log out.
Now when you want to play games you login as "steam" (or whatever) using the openbox login. Your secondary monitor is shut off and never a problem with anything. Additionally, you have no openGL compositor which can sometimes cause problems, and your system is running extremely lightweight using only 300 or 400 meg or so of RAM.
if (get_application_name() == "World of Warcraft") then
-- Sleep because it takes a second for the window to open completely
os.execute("sleep " .. tonumber(2));
-- Window position. In this case, 2880px to the right (on my right screen),
-- 0 px down, 1920x1080 size
set_window_geometry(2880, 0, 1920, 1080);
end
Works like a charm. The only issue is if you rearrange your monitor (for example disconnect a screen or swap screens around) your window might end up in a weird place. But WAY more efficient than changing the primary monitor that I used to do.
I also occasionally dabble a bit in Python, I do Internet Security for a living and finally, I'm a big fan of Neil Degrasse Tyson. And not just because he has a cool first name.
See more from me