Skip to content

u/LukeShu

In this archive from May 2012 to Dec 2023

0
posts
194
comments
0
media
996
score

Top comments

I'm not familiar with Wayland, everything that follows is for Xorg.


X11 itself:

  • Core X11 has a notion of multiple "screens"... ignore that, it's a red herring, having separate screens is a pain, everyone ditched that in favor of the "Xinerama" extension which lets you combine multiple physical "outputs" in to one logical X11 "screen", this is what you want.
  • The X11 "RandR" extension 1.2 added the ability to set the DPI of a screen (remember the screen encompasses the several physical outputs, so this isn't terribly useful for dealing with a DPI discrepancy between outputs).
  • The X11 "RandR" extension 1.3 added the ability to set per-output scaling.

With that in mind, the correct thing to do is "obviously" to set the X screen to the highest DPI of any monitor you might plug in, and set it to scale down the output to any monitors that have a lower DPI. So with my ThinkPad with a 157DPI built-in monitor and an 96DPI external monitor, I'd say:

# render DPI                   = 157
# eDP1 (laptop monitor) DPI    = 157
# HDMI1 (external monitor) DPI =  96
xrandr \
    --dpi 157x157 \                     # renderDPI
    --output eDP1 --scale 1x1 \         # renderDPI/monitorDPI = 157/157 = 1
    --output HDMI1 --scale 1.635x1.635  # renderPDI/monitorDPI = 157/ 96 ≈ 1.635

So the "render DPI" is 157 and all applications render at 157DPI, but then it gets scaled for the lower DPI external monitor.

Now, even though the X11 screen has the DPI set, a lot of programs won't pick up on that automatically:

  • Xft font rendering: Essentially all programs use the Xft library to do font rendering. Even programs that don't support HiDPI can at least have the text made HiDPI even if the widgets aren't. Configure this with the Xft.dpi item in the X Resources database: echo 'Xft.dpi: 157x157' | xrdb -merge.
  • Qt4: Does not support HiDPI, except for Xft font rendering.
  • Qt5: Most Qt5 programs automatically detect the X11 screen DPI, but some only auto-detect the DPI if you set export QT_AUTO_SCREEN_SCALE_FACTOR=1; IDK where the discrepancy comes from.
  • GTK+ 2: Does not support HiDPI, except for Xft font rendering.
  • GTK+ 3: Supports HiDPI, except only at integer multiples of 96DPI. This is set with the integer environment variable GDK_SCALE, which tells it what to multiply 96DPI by. Oh, and you'll need to also set the floating-point environment variable GDK_DPI_SCALE=((1/$GDK_SCALE)), because otherwise it doesn't play nice with setting Xft.dpi (because why would they want GTK+ 3 to play nice with other toolkits by default?).
  • Tk: Kinda supports HiDPI; the toolkit itself supports HiDPI, but none of the built-in themes for the X11 backend support HiDPI, so text and canvas areas will be HiDPI, but you'll have tiny scrollbars and such.
  • FLTK: 1.3 (current stable release) does not support HiDPI, but 1.4 (nightlies) does, and uses Xft.dpi as the screen DPI. If you feel like re-compiling all FLTK applications you use, you can take advantage of that.

So because of motherfucking GTK+ 3, you need to go up to the next multiple of 96DPI after the highest DPI monitor, then scale it down.

So, in total, for my 157DPI laptop monitor and 96DPI external monitor, I'd say:

# render DPI                   = 192
# eDP1 (laptop monitor) DPI    = 157
# HDMI1 (external monitor) DPI =  96
xrandr \
    --dpi 192x192 \                      # renderDPI
    --output eDP1 --scale 1.223x1.223 \  # renderDPI/monitorDPI = 192/157 ≈ 1.223
    --output HDMI1 --scale 2x2           # renderDPI/monitorDPI = 192/ 96 = 2
echo 'Xft.dpi: 192x192' | xrdb -merge    # renderDPI
export GDK_SCALE=2                       # renderDPI/96 = 192/96 = 2
export GDK_DPI_SCALE=0.5                 # 1/GDK_SCALE = 1/2 = 0.5
export QT_AUTO_SCREEN_SCALE_FACTOR=1     # 1=true, 0=false

I have a pair of scripts to automate the above: get-dpi and fix-dpi.

51 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.