Back to Hardcore Linux Series - Screen Resolution

Getting back into Xmonad meant running into a classic Linux hurdle: screen resolution not sticking. In this post I walk through diagnosing why my 5K2K monitor defaulted to the wrong mode and how I fixed it with xrandr and the right config file, so the display comes up correctly every time I log in.

Back to Hardcore Linux Series - Screen Resolution

This is the first in what I hope it is going to be a set of articles of the things I had to do to get my Linux desktop setup to work with Xmonad.


A little bit of history about myself. Xmonad was my window manager for all my college years and really enjoyed it. I only stopped using it once I moved to the states and my only computer was a macOS. Now that I got a nice shiny big-ass screen, I decided it was time to go back to my origins and setup Xmonad again.

Upon the initial load of an Xmonad session, the first "problem" showed up. My display looked like crap, primarily caused by a non-optimal resolution. The display is a 5K2K resolution screen and xrandr stated it was using 2560x1080 for some reason.

Fortunately, xrandr displayed that the resolution I wanted was available: 5120x2160. In order to test whether it would work or not it's always better to run a simple bash command with a fallback. If for any reason the resolution wouldn't work it would be reverted to a known state.

$ xrandr --output "HDMI-0" --mode "5120x2160" && sleep 15 && xrandr --output "HDMI-0" --mode "2560x1080" # HDMI-0 is my display's xrandr output

As it worked, I wanted to make the changes permanent. My first idea was to use ~/.xsession as the location to do this. Given what ChatGPT stated:

Best place: ~/.xsession (before your final exec window-manager).
That way, resolution is applied every time your session starts, regardless of desktop environment.

Alternative: You can put it in ~/.xprofile if your display manager sources it (many do, like GDM and LightDM). But if you’re starting X manually, it may not run.

But I'm not launching Xmonad from a ~/.xsession, but rather leveraging the session selector. This caused my changes to .xsession to be completely ignored.

Adding the corresponding line to ~/.xprofile did the trick - make sure that the file is configured as executable:

#!/bin/bash

# Configure HDMI-0 output resolution to 5K2K
xrandr --output "HDMI-0" --mode "5120x2160"

That's all for today. I hope I have the willpower to keep writing this short extracts in my journey to get Xmonad and my Linux desktop setup the way I want it.

Comments powered by Talkyard.