Using Multiple Monitors with Different Resolutions on Xorg (X11) Linux

Wainaina Gichuhi
8 min readApr 30, 2023

--

Setting up multiple monitors with different resolutions on any Linux distribution can be hectic for any user who has never setup a multi-monitor setup.

Four monitors setup
Four monitors setup. source: https://i.redd.it/oip4ngy964v51.jpg

For GNOME users, the gnome-control-center has a display settings option which can have disappointing results on Xorg (x11). While xrandr is effective, the resolution and scaling resets after a reboot.

The good news is that there is a permanent solution that never resets on restart. This tutorial will guide you on how to set a multi-monitor setup that does not reset on Xorg (x11).

A note from the Marketing department:

Wayland is likely the future of Linux as Xorg is slowly losing support.

If you are running on Wayland, check out this tutorial:

Please note:

The word monitor and display will be used interchangeably in this tutorial.

This solution works for Xorg (x11) server only.

Set the stage!

Begin by having displays arranged physically in your preferred order. Also note the display you want to use as your primary display as that’s where the configuration starts (That’s the way I prefer it, but you can start on any monitor).

For example, here is a four-monitor setup.

Four-monitor setup
Four-monitor setup

Prerequisite

Ensure that xrandr is installed. To check whether it is installed, run the command below on the terminal.

xrandr -q

The output should show all the connected displays and their profiles (your output will be different) and may look something like this:

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
DP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 521mm x 293mm
1920x1080 60.00 + 59.94* 50.00 29.97 25.00 23.98
1920x1080i 60.00 50.00 59.94
1680x1050 59.88
1600x900 60.00
1280x1024 60.02
1280x800 59.91
1152x864 75.00
1024x768 70.07 60.00
800x600 72.19 60.32
720x576 50.00
720x480 59.94
640x480 75.00 60.00
DP-2 disconnected (normal left inverted right x axis y axis
HDMI-1 disconnected (normal left inverted right x axis y axis
HDMI-2 disconnected (normal left inverted right x axis y axis

This output shows that there is one connected display (DP-1) and three disconnected displays (DP-2, HDMI-1, HDMI-2). Ensure that all your displays are connected; I’ve disconnected some to reduce the output above.

Laptop (internal) displays are named “eDP-x” where x is a random number like 1,2, etc.

If the xrandr command does not output anything, you can install it using your favorite or default package manager.

For Debian/Ubuntu based distros:

sudo apt install x11-xserver-utils 

Arch based distros:

sudo pacman -S xorg-xrandr 

Fedora

sudo dnf install xorg-x11-server-utils 

Let’s roll!

  1. Run the xrandr -q command to list available display modes for each connected display with its resolution, refresh rate, and other details. Note the display name and resolution for each monitor.

In our setup example, we have 4 monitors (DP-1, DP-2, HDMI-1, HDMI-2) with respective native resolutions of (3840x2160, 2880x1620, 2048x1080, 1920x1080). DP-1 will serve as our primary monitor.

Connected monitor modes
Connected monitor modes

2. Using your favorite text editor e.g. gedit, vim, nano, code, etc. create configuration file named 09-monitors.conf inside the /etc/X11/xorg.conf.d/ directory (create the directory if it does not exist).

sudo $EDITOR /etc/X11/xorg.conf.d/09-monitors.conf

Replace $EDITOR with your favorite text editor.

The command should still work if the $EDITOR variable is set in you login shell or environment.

3. Inside the file, create a Section container for each monitor to set settings such as the screen resolution, refresh rate, rotation, and other display settings.

Section "Monitor" 

### Monitor Identity - Typically HDMI-1 or eDP-1

Identifier "HDMI-1"

### Setting Resolution and Modes

Option "PreferredMode" "1920x1080"

### Positioning the Monitor

## Basic

Option "LeftOf" "DP-0"

## Advanced

Option "Position" "0 1080"

Option "Primary" "true"

EndSection

#: Represents a comment

Identifier “HDMI-1”: Unique name for a device, monitor, or screen section. Check xrandr –q ouput above.

Option “PreferredMode” “1920x1080”: Used to set the preferred resolution for a specific Monitor section in this case 1920x1080. The list of available resolutions/modes that the monitor supports are listed under each monitor after running the xrandr –q command.

Resolutions illustration showing width and height pixels

Option “LeftOf” “DP-0”: Used to specify the relative position of a specific Monitor section with respect to another monitor. This option indicates that the monitor associated with this Monitor section is located to the left of the monitor identified by DP-0. This should correspond to the physical arrangement of the displays/monitors. Either “LeftOf”, “RightOf”, “Above” or “Below” can be used for this Option directive.

If you specify position using LeftOf, RightOf, Above or Below for monitor 1 relative to monitor 2 (Say, monitor 1 is LeftOf monitor 2), it is not mandatory to specify the opposite position in the monitor 2 Section (Say, monitor 2 is RightOf monitor 1).

Option “Position” “0 1080”: Used to specify the position of a specific Monitor section relative to the origin of the virtual screen. The values “0 1080” indicate that the top-left corner of the monitor is located at the horizontal coordinate 0 and the vertical coordinate 1080 pixels. This option is used in conjunction with other Option directives such as LeftOf, RightOf, Above, Below, and SamePositionAs to specify the relative positions of multiple monitors in a multi-monitor setup.

Virtual screen plane
Virtual screen plane
Monitors arranged around the origin of the virtual screen plane
Monitors arranged around the origin of the virtual screen plane

Option “Primary” “true”: Used to specify that a specific Monitor section should be considered the primary monitor in a multi-monitor setup.

In the configuration file, we can have a Monitor and Screen section. The Monitor section is used to define the physical properties of a display, while the Screen section is used to define the logical properties of a virtual screen made up of one or more physical displays. This tutorial focuses Monitor section only.

Note: There are more options including setting a specific refresh rate or forcing a specific resolution. You can check them out here:

4. Based on our physical arrangement above, we shall begin by setting the configuration for the primary monitor (Monitor 3 or DP-1).

Monitor 3 (DP-1)

Section "Monitor" 

Identifier "DP-1"

Option "PreferredMode" "3840x2160"

Option "Primary" "true"

Option "Position" "0 0"

Option "LeftOf" "HDMI-2"

Option "RightOf" "HDMI-1"

Option "Below" "DP-2"

EndSection

Monitor 1 (DP-2)

Section "Monitor" 

Identifier "DP-2"

Option "PreferredMode" "2880x1620"

Option "Position" "0 -1620"

EndSection

Monitor 2 (HDMI-1)

Section "Monitor" 

Identifier "HDMI-1"

Option "PreferredMode" "2048x1080"

Option "Position" "-2048 0"

EndSection

Monitor 4 (HDMI-2)

Section "Monitor" 

Identifier " HDMI-2"

Option "PreferredMode" "1920x1080"

Option "Position" "3840 0"

EndSection

Here is the entire /etc/X11/xorg.conf.d/09-monitors.conf for our setup above (yours will be different).

Section "Monitor" 

Identifier "DP-1"

Option "PreferredMode" "3840x2160"

Option "Primary" "true"

Option "Position" "0 0"

Option "LeftOf" "HDMI-2"

Option "RightOf" "HDMI-1"

Option "Below" "DP-2"

EndSection


Section "Monitor"

Identifier "DP-2"

Option "PreferredMode" "2880x1620"

Option "Position" "0 -1620"

EndSection


Section "Monitor"

Identifier "HDMI-1"

Option "PreferredMode" "2048x1080"

Option "Position" "-2048 0"

EndSection


Section "Monitor"

Identifier "HDMI-2"

Option "PreferredMode" "1920x1080"

Option "Position" "3840 0"

EndSection

5. Save the file and restart the system to apply the configuration.

But wait! Where is the scaling configuration?

Confused-older-man
Source: https://health.wyo.gov/wp-content/uploads/2017/05/confused-older-man.jpg

Ah! Yes, my bad. That’s why you read thus far.

If you find this guide resourceful, a clap or subscribe will do me some good. 😉

Scaling on Xorg (x11)

The monitor configuration file above does not have a scaling option. You could use Gnome Tweaks or KDE Display Configuration to scale up everything. However, this scaling affects all monitors simultaneously on x11. To set independent monitor scaling, use the xrandr command.

For instance, you can set a scaling of 1 for Monitor 3 (DP-1) like:

xrandr --output "DP -1" --scale 0.9999x0.9999  

Use a 4 decimal number and ensure the last digit is a nine to prevents the mouse pointer from flickering after scaling. For instance, 1.5 scaling would be 1.499.

To make this setting permanent (persist after reboot), create a shell script file with the command(s) to set the scaling for each monitor you want to scale. Every monitor’s scale command should be in a new line.

xrandr --output "DP-1" --scale 0.9999x0.9999 

xrandr --output "HDMI-1" --scale 0.9999x0.9999

xrandr --output "HDMI-2" --scale 0.9999x0.9999

xrandr --output "DP-2" --scale 0.9999x0.9999

If your setup includes an laptop (internal) display, ensure the command to scale the laptop display is the first in the file. Failing to scale the laptop display first makes it impossible to scale it after scaling other monitors (In my experience).

Save the file in the $HOME/.config/autostart/ directory. Change the script mode to executable.

chmod +x scale_script.sh

To execute the shell script on login;

  1. Create/move the file scale_script.desktop to the $HOME/.config/autostart/ folder with the below content. This file will execute the shell script on login.
[Desktop Entry] 

Type=Application

Exec=/bin/bash -c "~/.config/autostart/scale_script.sh"

Hidden=false

NoDisplay=false

X-GNOME-Autostart-enabled=true

Name="Auto Monitor Scaling"

Comment="Set proper automatic scaling for monitors on login"

“~/.config/autostart/scale_script.sh” should match the path of the shell script file you created with the scaling commands.

$HOME and ~/ represent the home directory.

2. Save the file and then restart your system to put the script in action.

For those would rather use the graphical interface, follow the procedure for your desktop environment.

GNOME

On GNOME, you can use Tweaks (Gnome tweaks tool) to have scripts start automatically on log in. Check out the short steps in this guide:

KDE

On KDE, you can configure which applications or scripts will execute as soon as you log into Plasma Desktop Workspace using KDE’s System Settings > Autostart. Check out the short steps in this guide:

Remember to reboot the system after applying the changes in either DE.

And that’s it!

Your permanent monitor resolution settings should be working. Remember, you can always edit the config files to change the resolutions, refresh rates or scaling as you like.

I’d like also to hear from you, did the tutorial work for you? If not, where are the challenges, regards!

--

--