Code Review Videos > How I Fixed > My Ubuntu Triple Monitor Setup

My Ubuntu Triple Monitor Setup

A good few years back now I made a post on the previous iteration of this site about my problems with Portrait mode in Ubuntu. I still run a similar set of screens, but my triple monitor setup has slightly changed since then.

What I will say is that in Ubuntu 22.x onwards (currently just updated to 23.04), things have been mostly very good. But that is because I have a set of scripts that do things to make the desktop setup as close to “just works” as possible.

Out of the box, my experience has been that Windows is still the king when it comes to the most robust triple monitor plug-n-play. Apple is also good. Ubuntu needs a bit of hand holding.

My Current Hardware

OK, so the first thing is that I strongly suspect the average Ubuntu user is a nerd. Like me. Someone who has been using PCs for a long time and has been accumulating hardware for many years.

Or to put it another way, I am guessing most Ubuntu users with multiple monitors are not the kind of people who have two, three, or more identical monitors.

Personally in my current setup I have a super nice Gigabyte 32 inch 4K screen at 144hz (which isn’t a brag, it is important to this post shortly), then a Dell 27 inch 4k screen that only does 60hz, and an even older Dell 24 inch screen I use in portrait mode for my terminals.

For this setup I have also very recently (read: after the stupid Covid / bitcoin graphics card price insanity) upgraded to a RTX 4060. It’s not a brilliant card, and I only got the 8gb version so it’s pants for AI, but it is a significant upgrade from the GTX 970 I was rocking for the last, what, ten years?

Ubuntu + Nvidia Graphics Drivers

To cut a long story short, I switched from AMD graphics cards to Nvidia graphics cards years back as I heard Nvidia played nicer with Linux.

I don’t know if that is (or is still) the case as I haven’t used an AMD card in a very long time now. But generally, in recent releases of Ubuntu, the Nvidia driver experience has been very good.

So much so that in upgrading from 22.x to 23.x, the only command I had to run was:

sudo ubuntu-drivers installCode language: Shell Session (shell)

And I suspect I wouldn’t have even needed to do that, but I had switched to a manual graphics card driver setup to install the CUDA stuff for playing with AI, and that seemed to make a real mess of automated graphics card driver updates. Basically I made a mess, then had to uninstall that, run the above command and Ubuntu started recognising my card properly once more.

Painless enough.

Triple Monitor Setup With Ubuntu Display Settings

On to the meat and potatoes of this post.

If you have a single monitor, or maybe even two in plain old ‘horizontal’ mode setup, you might just be good to go without further hassle.

I don’t have that.

my triple monitor desktop from 2020ish

As I say, that’s a very old photo now but it’s pretty accurate still.

Here’s how Ubuntu sees my setup:

ubuntu triple monitor setup

You can then click on each monitor individually to see the settings:

ubuntu gigabyte monitor settings

This mostly works, but I use the screen marked #1 as my work monitor.

What this means is I have a couple of cables going into that monitor. From my desktop I have a full size display port cable, and then from my work laptop I have a mini display port cable.

That means I can use the monitors in-built menu buttons to ‘toggle’ between the two. It’s not a particularly graceful experience, but it works well enough.

Mostly then, I have my Ubuntu system running two monitors, and my work laptop running on that third monitor plus the laptop screen.

Again, why this is important is that I essentially have two profiles.

Sometimes, when swapping between the screen profiles at the end of the working day, everything goes wrong.

Ubuntu Triple Monitor Setup With ARandR

For most users and common display configurations, the “Ubuntu Display Settings” menu provides a user-friendly and straightforward way to manage display settings.

It’s a more accessible option for users who are not comfortable with the command line.

However, if you have specific needs, require advanced configurations, or need to automate display-related tasks, xrandr can be a powerful and essential tool.

The “problem” is that xrandr is a command line utility. Whilst that’s a good thing is many ways, personally for things like this that I don’t need to know the ins-and-outs, I much prefer a GUI. I guess I’m getting old.

Fortunately, I am not the only one.

ARandR provides a much nicer visual interface to configure XRandR.

ARandR is not installed by default, but installing it is very straightforward:

sudo apt install arandrCode language: Shell Session (shell)

Here’s my two different layouts:

Don’t ask me why the window pane is so big for these two, the resizing options wouldn’t work. Some irony there.

These are really just two different xrandr scripts.

On Ubuntu you can find the underlying scripts in your ~/.screenlayout directory.

If you use Nautilus (the file explorer / file manager) to browse to your home directory, then press ctrl + h to show hidden files, you should see many new directories, of which .screenlayout (starting with the dot) will be one.

My XRandR Scripts

Here’s the two scripts I use:

#!/bin/sh
xrandr --output DP-0 --off --output DP-1 --off --output DP-2 --off --output DP-3 --off --output HDMI-0 --mode 1920x1200 --pos 3840x0 --rotate left --output DP-4 --primary --mode 3840x2160 --pos 0x0 --rotate normal --output DP-5 --offCode language: Bash (bash)

That one above is what I call double.sh, and this one is triple.sh:

#!/bin/sh
xrandr --output DP-0 --mode 3840x2160 --pos 0x0 --rotate normal --output DP-1 --off --output DP-2 --off --output DP-3 --off --output HDMI-0 --mode 1920x1200 --pos 7680x78 --rotate left --output DP-4 --primary --mode 3840x2160 --pos 3840x0 --rotate normal --output DP-5 --offCode language: Bash (bash)

You can’t copy paste these and expect them to work, they are very specific to my hardware and desk setup.

I’m including them for completeness. And also to illustrate a problem.

As the #!/bin/sh line (also called the shebang or hashbang) at the top of each file indicates, these are both Bash scripts. That tells Linux how to run this script – in this case by using /bin/sh to execute the contents.

Both of these scripts have been made executable (with chmod +x):

ubuntu screen layout scripts dir

Notice the permissions on each are read / write / execute, and the execute permission is why the files turn green in my terminal.

But I don’t run these manually. Well, not via the command line anyway.

As per the other post I wrote on this subject, I have a start up script set to apply the triple monitor layout on login.

In order to persist between reboots, I used a “startup application” entry.

To get to this, hit the super key and type “Startup”, and then I entered the following:

edit start up script ubuntu triple monitor

Giving me this:

start up applications ubuntu

Right, so that works. But for reasons I am unsure about, ARandR doesn’t have an option to set the refresh rate for your screen. So by default you will get 60hz.

Set Your Refresh Rate In XRandR

As above, if I run the script, either manually, via ARandR, or as the xrandr command line command, I do get the desired outcome, but with one caveat:

ubuntu sets monitor to 60hz xrandr

I hate to be “that guy” but by Jove I spent an absolute bloody fortune on this monitor and I’m damn sure I want to use all 144hz available.

Honestly though, the difference between 60hz and 144hz is super noticable. For the longest time I had no idea how much of a nicer experience a fast refresh rate screen is compared to 60hz. I can whack up the Dell 27″ to 4K via HDMI, but it restricts it down to 30hz. The difference between 30hz and 60hz is night and day, to the point where 30hz makes me feel sick. 60hz to 144hz isn’t that big of a jump, but it is a nicer experience.

Anyway, ARandR might not be able to set the refresh rate in the GUI, but that doesn’t stop you from customising the xrandr command script it creates for you.

To change the refresh rate using xrandr, you’ll need to know the available refresh rates supported by your monitor and graphics card. You can list the available modes and their refresh rates using the following command:

xrandr

This will display a list of screen resolutions and their associated refresh rates.

ubuntu triple monitor refresh rates xrandr

Note the asterisk will be next to your currently set refresh rate. In the example above I had manually set the refresh rate back to 144hz in the Ubuntu Display Settings.

To change the refresh rate, you can use a command like this:

xrandr --output [output] --mode [resolution] --rate [refresh rate]

Replace [output] with the name of your output device (e.g., “HDMI-1” or “DP-1”), [resolution] with the desired screen resolution, and [refresh rate] with the refresh rate you want to set. For example, to set the refresh rate to 60Hz for an output named “HDMI-1” at a resolution of 1920×1080, you would use a command like this:

xrandr --output HDMI-1 --mode 1920x1080 --rate 60

Keep in mind that not all combinations of resolutions and refresh rates may be supported by your hardware. If you set an unsupported refresh rate, your monitor may not display anything, and you’ll need to revert to a working configuration. It’s essential to check the capabilities of your display and graphics hardware to ensure you’re using a supported refresh rate.

Unfortunately, This Breaks ARandR

So yeah, whilst ARandR is great for setting up your initial xrandr command in a graphical way, once you manually modify the result it … breaks ARandR.

All is not lost, however.

My fix for this has been to create two desktop icons:

ubuntu monitor desktop shortcuts

These two also reference the shell scripts in the same way, I just no longer use ARandR to choose my setup.

There’s probably a nicer set of icons to use, too. But as you can probably tell from the way this site looks, I am no designer.

OK, so the all important contents:

cat <<'EOF' > ~/Desktop/TripleMonitor.desktop

[Desktop Entry]
Version=1.0
Type=Application
Name=Triple Monitors
Comment=Configure triple monitor setup
Icon=display
Exec=/home/chris/.screenlayout/triple.sh  
Terminal=false
StartupNotify=false
EOFCode language: Shell Session (shell)

Running that exact command will create the “Tripple Monitors” icon on your desktop.

So, obviously, adapt accordingly.

You will also need to make the file both executable, and launchable.

chmod +x ~/Desktop/TripleMonitor.desktopCode language: Shell Session (shell)

And then I haven’t figured out a way to do the launchable part from the command line.

Right click the icon, and select “Allow Launching”:

ubuntu allow launching desktop icon

If that works, the little red X should go away, and now your icon should be double clickable.

And that’s it. That’s my current double and triple monitor setup on Ubuntu. Always a work in progress, but it does the job.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.