1. Overview
In this tutorial, we’ll learn about adjusting the screen resolution in Linux. We’ll cover X11-based environments first using the xrandr command. Then, we’ll briefly look at how to do the same in popular Wayland Environments, KDE Plasma, and GNOME.
2. Changing Screen Resolution in X11
To adjust our screen resolution in X11, we can use the xrandr command. Let’s begin by running this command without any arguments:
$ xrandr
...
HDMI-A-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 476mm x 268mm
1920x1080 60.00*+ 50.00 50.00 59.94
1680x1050 59.88
...
The output shows a list of outputs and their available modes. There is a plus sign by the mode currently being used. In this case, 1920×1080 at 60 hertz. To get complete information about each mode, we can run xrandr –verbose.
We can then use this information to change our resolution to one of the listed modes:
$ xrandr --output 'HDMI-A-0' --mode '1680x1050'
We use the xrandr –output command to specify the output we want to change and then –mode to select the mode we want to use. In this case, we change our HDMI-A-0 output and use the mode 1680×1050.
2.1. Setting Custom Resolution
In addition to using the modes provided by xrandr, we can also create our own modes with custom settings. This can be useful in circumstances in which the resolution we want to use is not supported by any of the default modes.
To begin, we should first run the cvt (Coordinated Video Timings) command to get the necessary information we need:
$ cvt 720 480
# 720x480 59.71 Hz (CVT) hsync: 29.85 kHz; pclk: 26.75 MHz
Modeline "720x480_60.00" 26.75 720 744 808 896 480 483 493 500 -hsync +vsync
Here we pass our desired resolution to cvt and get the Modeline information in return.
Let’s pass the output from cvt to our xrandr command to make a new mode:
$ xrandr --newmode $(cvt 720 480 | grep -Pio 'modeline\K.*' | xargs)
We pipe the output of cvt to grep to extract just the Modeline output. Then we use xargs to parse this output as arguments that we can use with xrandr –newmode.
Now that we created our mode, we’ll need to add it to our display:
$ xrandr --addmode 'HDMI-A-0' '720x480_60.00'
In this example, we use xrandr –addmode with our desired output and mode. This will add the given mode to the list of valid modes for an output.
After this, we simply run the same command we ran earlier to set the current mode:
$ xrandr --output 'HDMI-A-0' --mode '720x480_60.00'
Our output at HDMI-A-0 should now display with the settings of our new mode. Importantly, any mode created by the user will be wiped when the X server exits. To ensure a setting is persistent between sessions, we should add the relevant lines to our ~/**.xinitrc file.
3. Changing Screen Resolution in Wayland
Wayland has different methods of changing screen resolution depending on the compositor used. We will just look at adjusting the screen resolution in two of the most popular, KWin (KDE Plasma) and Mutter (GNOME).
3.1. Adjusting Resolution in KDE Plasma
To change screen resolution in KDE Plasma, we can use kscreen-doctor from the libkscreen library.
To begin, we should first get the output name we want, along with the mode corresponding to our desired resolution.
$ kscreen-doctor --outputs
Output: 1 Hewlett Packard HP 22cwa/6CM6501C14 enabled connected HDMI Modes: 0:1920x1080@60*! 1:1680x1050@60
...
Here we use kscreen-doctor –output to print a list of outputs and their valid modes. An exclamation point is at the end of the mode currently in use.
Now that we know what the output names and valid modes are, we can change our resolution:
$ kscreen-doctor output.1.mode.1
...
kscreen.doctor: Output 1 set mode "1680x1050@60"
...
To change the mode of our output, we can use kscreen-doctor output.${OUTPUT}.mode.${MODE} with ${OUTPUT} being the name or number of our output and ${MODE} being the name or number of our desired mode.
3.2. Adjusting Resolution in GNOME
To adjust the screen resolution in GNOME, we can use the command line tool gnome-randr.
To begin, we should first run the gnome-randr command without any options:
$ gnome-randr
...
HDMI-1 HWP HP 22cwa 6CM6501C14
1920x1080@60 1920x1080 60.00*+ [x1.00+, x2.00]
[email protected] 1680x1050 59.88 [x1.00+, x2.00]
...
There are many different settings outputted by the gnome-randr command. However, we just need to look at the list of outputs and their valid modes.
Using this information, we can now change the resolution of our display:
$ gnome-randr modify 'HDMI-1' --mode '[email protected]'
setting mode to [email protected]
To modify the setting, we use gnome-randr modify with the output we want to change and –mode with the mode that has our desired resolution.
4. Conclusion
In this article, we learned how to change the resolution of a display in X11 using the xrandr command. We then briefly learned how to do similar in Wayland using kscreen-doctor for KDE Plasma and gnome-randr for GNOME.