[Xcb] Framebuffer size vs Window size.

Uli Schlachter psychon at znc.in
Sat Jan 22 08:30:20 UTC 2022


Hi,

On 20.01.22 15:37, Carlo Wood wrote:
[...]> But it is hard to believe that on X11
> this scale is non-existant (or always 1).
[...]

X11 is older than I am. I can tell you how X11 works with monitors that
can only display 16 colors at a time. Back then, no one was thinking
about HiDPI. So yes, there is no scaling factor in X11.

Random data point: https://wiki.archlinux.org/title/HiDPI

This all looks complicated and "everything brings its own setting".

The only X11-things in there that I can find are:

Setting Xft.dpi
This is actually (originally) meant to be a font-only thing and has
nothing to do with "scaling everything". Yet, these days it does. With
some programs.

Messing with the DPI as reported by the X11 server, but apparently this
is deprecated, because programs stopped interpreting this value:

> older versions of i3 (before 2017) and Chromium (before 2017) used to
> do this.

I also like the "Multiple displays" sections, because apparently no one
thought of this when hacking solutions (and yet, even your mail already
recognizes this problem already):

> The HiDPI setting applies to the whole desktop, so non-HiDPI external
> displays show everything too large. However, note that setting
> different scaling factors for different monitors is already supported
> in Wayland.

If you really want to do something in your program, you could use the
RandR extension to get information about all monitors. This allows you
to get the pixel size and the physical size (in mm) of the outputs. This
allows to compute a DPI value and do something based on that.

You can experiment with the "xrandr" utility to see what information is
available. For example:

$ xrandr --listactivemonitors
Monitors: 2
 0: +*HDMI-1 1920/477x1080/268+0+0  HDMI-1
 1: +DP-2 1280/376x1024/301+1920+0  DP-2

This output is maximally confusing, so let's look at some other RandR
command that provides other information (which just so happens to be the
same coordinates as the above for my system):

$ xrandr --current | grep ' connected'
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x
axis y axis) 477mm x 268mm
DP-2 connected 1280x1024+1920+0 (normal left inverted right x axis y
axis) 376mm x 301mm

My DP-2 monitor (actually: CRTC) has a resolution of 1280x1024 pixels.
Its top left corner is at 1920x0 in X11's coordinate space. Its physical
size is claimed to be about 37 cm x 30 cm. The same numbers appear in
the output of --listactivemonitors, just in a less intuitive format.

If you want to get this information programmatically, look at
xcb_randr_get_monitors(). More details can be found here:
https://github.com/freedesktop/xorg-xorgproto/blob/master/randrproto.txt

However, usually, the computed DPI will not be a multiple of 96. Do you
want scaling factors of 1.763? Also, what do you do when two monitors
show the same pixel area (clone mode), but they have different physical
sizes? What do you do when your window is "between two monitors" and
visible on both of them? What about monitors with different DPIs in X
and Y direction? Lots of fun with edge cases.

Cheers,
Uli
-- 
“I’m Olaf and I like warm hugs.”


More information about the Xcb mailing list