Skip to content

Instantly share code, notes, and snippets.

@juanjux
Last active February 12, 2021 22:35
Show Gist options
  • Save juanjux/79b8ac0e8546cca76d02ef647229cf54 to your computer and use it in GitHub Desktop.
Save juanjux/79b8ac0e8546cca76d02ef647229cf54 to your computer and use it in GitHub Desktop.
how to set xrandr for multihead X systems mixing normal and high DPI screens
#!/bin/sh
# Note: this works well on Gnome3. KDE 5.7 seems to have issues with the
# framebuffer (toolbars are over the place). 5.9 works well except for
# the desktop background image on the scaled monitor (0 fucks given) but
# for KDE you have to add the xrandr command in another config file:
# http://askubuntu.com/questions/299241/how-to-reset-kde-display-settings-after-a-move-to-a-new-machine
#
# tldr: upscale the lowdpi screen to match the resolution of the hdpi one
# and create a virtual framebuffer resolution that is the size of the combined
# resolutions
#
# 1. Gnome: Install and open gnome-tweak-tool. Go to Windows and set Window scaling to
# 2 or whatever is needed so things doesn't look too small on the HDPI screen. Ignore the lowdpi
# screen for the moment. DONT touch the fonts scaling factor, we'll set that one with xrandr
# dpi. If we aren't unsure about the currently set DPI check with:
# xdpyinfo | grep resolution
# On KDE you can go to systemsettings -> displays -> scale display.
#
# 2. Now the xrandr command. We'll scale the lower resolution display to match the
# higher one. With a 1920x1080 monitor and a 3200x1800 laptop the scale
# factor is 1.66 both in width and height. It's important to keep the same scaling on
# both axes of things will look bad. It doesn't matter if the final resolution of the scaled
# monitor is higher on some ax than the hdpi one.
# Laptop hidpi display: eDP-1 (we can see the names with xrandr without parameters)
# A: hidpi width res: 3200
# B: hidpi height res: 1800
# FHD monitor: DP-1
# C: lowdpi width res: 1920
# D: lowdpi height res: 1080
# 3. Calculate the resolution of the framebuffer (the virtual resolution of both
# displays combined):
#
# - Monitors side by side: width is the sum of both widths or A+C (3200+3200 in our
# case = 6400), height is the same as one (or the higher one of both monitors have
# different heights after reescaling) so 6400x1800 in this case.
#
# - Monitor one on top of other: 3200x(1800x2) so 3200x3600
#
# 4. Calculate the positions. The resoluion with X starts at "0x0" being the top
# left corner of the framebuffer. When we specify the position of a screen to xranr
# its also the top left corner of the screen so:
#
# (0x0) (3200x0) (6400x0)
# Horizontal: | FHD_Monitor | | HDPI scren |
#
# FHD is 0x0, HDPI is 3200x0
#
#
# Vertical: | FHD monitor |
# '-------------'
# ---------------
# | HDPI display |
#
# FHD is 0x0, HDPI is 1800x0
#
# So for an horizontal layout the command would be:
xrandr --output eDP-1 --auto --pos 3200x0 --dpi 272 --output DP-1 --auto --dpi 272 --scale 1.66x1.66 --pos 0x0 --fb 6400x1800
# Note that we need to use the same DPI for both monitors even while the FHD one is only
# really scaled.
#
# Now add that command to your ~/.xprofile config file so they're loaded on every X
# start and restart the system or X. DONT configure any font size before restarting
# since changes could have not applied to all programs.
#
# After the restart you can configure the font sizes of your programs. They should show
# more or less the same on both monitors (bigger on the bigger one, obviously) and now
# you only need to configure the font sizes of your programs once. There is a good
# guide here with settings for different programs:
# https://wiki.archlinux.org/index.php/HiDPI
#
# If the fonts on the FHD look too sharp or too blurry adjust the sharpness setting
# on the monitor.
@rileyrg
Copy link

rileyrg commented Feb 12, 2021

It's not that you need the same DPI - you have no choice. Xrandr only allows one global dpi setting for both monitors. The whole thing is a horror trying to figure out - hence google found you :)

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