Linux on HiDPI attachment
mouse 603 · person cloud · link
Last update
2018-12-14
2018
12-14
«retina screen/monitor/display high resolution»

Here are my settings for my slimbook pro2 with a QHD+ 3200x1800 HiDPI display:

XFCE

Go to: Settings Manager > Appearance > Fonts > DPI = 192

X Server

Use Pitagora's theorem to determine screen size:

1
2
3
echo 'scale=5;sqrt(3200^2+1800^2)'   | bc  # 3671.51195 px
echo 'scale=5;(13.3/3671)*3200*25.4' | bc  #  294.23360 mm
echo 'scale=5;(13.3/3671)*1800*25.4' | bc  #  165.50640 mm

then tell them to Xorg:

1
2
3
4
5
# /etc/X11/xorg.conf -- generate one with: Xorg -configure
Section "Monitor"
  # check "xdpyinfo | grep -B 2 resolution" for curret DPI
  DisplaySize 294 165 # in millimeters
EndSection

You can also set the DPI manually with: xrandr --dpi 144.

GRUB

Download the terminus-32.pf21 (see attachment) and then:

1
2
echo 'GRUB_FONT="/boot/grub/terminus-32.pf2"' >> /etc/default/grub
update-grub

WINE

Run winecfg and change the dpi setting found in the Graphics tab.

Oracle Java >= 9

1
2
3
4
5
java \
  -Dsun.java2d.uiScale=2     \
  -Dsun.java2d.dpiaware=true \
  -Dsun.java2d.xrender=true  \
  -jar application.jar

Linux console

1
dpkg-reconfigure console-setup # and choose terminus 16x32

XTerm

Put in your ~/.Xresources:

1
2
3
4
! xterm ttf font (so it scales on hidpi displays)
XTerm*renderFont: true
XTerm*faceName: Monospace
XTerm*faceSize: 18

then load it via xrdb -merge ~/.Xresources.


Multiple displays

To have a non-HiDPI monitor (on DP1) right of an internal HiDPI display (eDP1), one could run:

  • extending:
1
xrandr --output eDP-1 --auto --output DP-1 --auto --scale 2x2 --right-of eDP-1

or use this automated script (see attachment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh

# https://gist.github.com/wvengen/178642bbc8236c1bdb67
#
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
# see also https://wiki.archlinux.org/index.php/HiDPI
# you may run into https://bugs.freedesktop.org/show_bug.cgi?id=39949
#                  https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/883319

EXT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^eDP | head -n 1`
INT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^DP | head -n 1`

ext_w=`xrandr | sed 's/^'"${EXT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
ext_h=`xrandr | sed 's/^'"${EXT}"' [^0-9]* [0-9]\+x\([0-9]\+\).*$/\1/p;d'`
int_w=`xrandr | sed 's/^'"${INT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
off_w=`echo $(( ($int_w-$ext_w)/2 )) | sed 's/^-//'`

xrandr --output "${INT}" --auto --pos ${off_w}x${ext_h} --scale 1x1 --output "${EXT}" --auto --scale 2x2 --pos 0x0 --right-of "${INT}"
  • panning:
1
2
3
4
5
6
7
# panning with AxB HiDPI, CxD external, ExF scale factor, external on the right:
xrandr --output eDP-1 --auto --output HDMI-1 --auto \
  --panning [C*E]x[D*F]+[A]+0 --scale [E]x[F] --right-of eDP-1

# example with 4k (3840x2160) + FullHD (1920x1080) on the right
xrandr --output eDP-1 --auto --output DP-1 --auto \
  --panning 3840x2160+3840+0 --scale 2x2 --right-of eDP-1
  • manual positioning:
1
2
3
4
5
6
7
8
9
# AxB HiDPI, CxD external, [ExF] scaling factor, external above:
xrandr --output eDP-1 --auto --pos 0x(DxF) \
  --output HDMI-1 --auto --scale [E]x[F] --pos 0x0 \
  --fb [max(A, (C*E))]x[B+(D*F)]

# example with 2560x1440 + 1920x1080 above
xrandr --output eDP-1 --auto --pos 0x1458 \
  --output HDMI-1 --scale 1.35x1.35 --auto --pos 0x0 \
  --fb 2592x2898

and adjust the sharpness parameter on your monitor settings to adjust the blur level introduced with scaling.


Source: Archlinux Wiki