Skip to content

Instantly share code, notes, and snippets.

@kesyog
Last active December 1, 2023 12:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kesyog/e02066550d681fe4b9e65c1ff5018465 to your computer and use it in GitHub Desktop.
Save kesyog/e02066550d681fe4b9e65c1ff5018465 to your computer and use it in GitHub Desktop.
Configuring multiple displays with i3

Configuring multiple displays with i3

Motivation

I've run into a few common issues running i3 on a laptop with external monitors.

  • When running i3, external monitors aren't always detected properly.
  • When running multiple displays with different resolutions, text scaling is inconsistent.
  • I'd like to be able to automatically change configurations if I unplug my external monitor(s), plug in a projector, etc.

Solutions

tl;dr: Configure xrandr, set font scaling for X11, and use autorandr.

See references for more detailed info.

Configure xrandr to manage display resolutions and positions

Based on this article, setting different dpi per-monitor in a way that is universally supported by all applications is tricky if not impossible.

The workaround seems to be to set one universal dpi and then run all displays at resolutions that look good at that dpi, possibly with the help of scaling.

Scaling can lead to performance issues. For me, running multiple applications side-by-side on a scaled display often led to virtually unusable stuttering.

Some example xrandr configs below. Use autorandr to save and automatically load configurations.

Examples

Some past configs I've used that might be a good reference of what to do/not do.

One QHD external monitor and one 4K UHD display

Rather than scaling the external monitor by 1.5 to UHD resolution, I just ran everything at QHD.

xrandr \
  --output eDP-1-1 --primary --mode 2560x1440 --pos 2560x0 \
  --output eDP-1 --primary  --mode 2560x1440 --pos 2560x0 \
  --output DP-3 --mode 2560x1440 --pos 0x0 \
  > /dev/null 2>&1
One FHD external monitor and one 4K UHD display

Scale the external monitor up to UHD. This led to performance issues on the scaled monitor when running multiple applications. I may have been better off running the laptop display (eDP) at 1920x1200.

xrandr \
  --output eDP-1-1 --primary --mode 3840x2160 --pos 3840x0 \
  --output eDP-1 --primary  --mode 3840x2160 --pos 3840x0 \
  --output DP-3 --mode 1920x1200 --scale 2x2 --pos 0x0 \
  > /dev/null 2>&1

Set dpi in X Resources

According to the Arch wiki, this only needs to be done if you're not using a desktop manager that sets it up for you. I needed to for i3.

I added this line to my ~/.Xresources config:

Xft.dpi: 160

I used the actual dpi of my external monitor as a starting point and adjusted it until I was happy with how applications were scaled.

Utilities

  • autorandr: Automatically load previously-saved xrandr configurations based on your current setup. Can be configured to automatically respond to monitor plug/unplug events on-the-fly.
  • arandr: drag-and-drop GUI that can be helpful as a starting point for visualizing and generating xrandr configurations.

References

@arhanjain
Copy link

this was really helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment