Ventto / mons

POSIX Shell script to quickly manage monitors on X

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DPI creeping up by 1 on every execution

dkambersky opened this issue · comments

Hi,

I have a weird issue using mons. Whenever I switch monitors with the utility, the xrandr used DPI creeps up by 1, resulting in everything newly opened being unreasonably large after a while.

For reference, my laptop's display is a 13.3" 1080p screen for which I usually use a dpi of 120x120. The external monitor I'm connecting is a 20" 1050p one with 96x96 dpi.

This screenshot shows the bug in action (from what I see, it seems to be detecting the physical dimensions as smaller and smaller?): https://i.imgur.com/uPXV1og.jpg

Might be a problem with xrandr auto-detect, but when I use normal xrandr commands (e.g. xrandr --output eDP-1-1 --auto --output HDMI-0 --auto --right-of eDP-1-1) this bug doesn't occur.

commented

Hi @dkambersky,
Thanks for the feedback.

The --dpi setting that you can set with xrandr is an indication to applications, it doesn't configure the hardware. So, forcing DPI value with 96x96 will be a workaround.

Yeah, I'm aware, though a lot of the applications I use actually take note of it - i3wm, urxvt (hence the huge fonts in the screenshot, among other things). I just don't want it creeping up to ridiculous values, I'm not expecting it to be a DPI scaling silver bullet.

Do you need any more info from me? It might be that the physical dimensions detected are getting smaller, I don't really know what depends on what there.

EDIT: I should probably clarify that the screenshot is of a fullscreen terminal on a 1680*1050 display, the fonts are usually a fraction of the size.

commented

Me neither.

As you said, the DPI increasing happens when you switch monitors, it means performing the -s option and then -o.

While I am investigating, you should use the following command to adjust the DPI value:

xrandr --dpi <value>

Nevertheless, a first workaround would be to run xrandr --dpi 96 or using xdpyinfo directly.

Hi, thanks for the fix! However, it's still not working correctly for me, but I suspect that might be a fault of some auto-detection not neccessarily done by mons - my secondary (120dpi) monitor gets detected as 165x166 dpi, and the primary (96dpi) gets detected as 166x166 for some reason - at least it doesn't creep up with every execution anymore.

Would passing the target DPI as a flag to mons be something that's possible? This utility is otherwise awesome, so I'd love to use it in place of my hacky xrandr script, but it's causing some of my most used GUI elements to be ridiculously oversized.

commented

@dkambersky, thanks again for testing.

Could you please give me your monitor size information ?

eDP1-1 (laptop, 13.3", 1080p display, I usually use 120dpi on it):

  • Resolution 1920x1080
  • Physical size 294mm x 165mm

HDMI-0 (external, 20", 1680x1050, 96dpi)

  • Resolution 1680x1050
  • Physical size 434mm x 270mm

here's xrandr's output with the monitor plugged in, after mons -e left. In this state xdpyinfo reports a DPI of 166x166 (occasionally 165x166). Switching back to only the laptop's monitor does not change the DPI.

Thanks for looking into this!

commented

The DPI value given by mons is correct but does not fit for applications.
Actually, there is a huge difference between xdpyinfo and xrandr regarding monitor physical sizes.
Information from xrandr are correct.

Sample:

$ xrandr | grep ' connect'
eDP1 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 344mm x 194mm

$ xdpyinfo | grep '^screen' -A1
screen #0:
  dimensions:    1920x1080 pixels (508x285 millimeters)

Physical sizes:

  • xrandr: 344mm x 194mm (correct)
  • xdpyinfo: 508mm x 285mm

DPI calculation (from xdpyinfo sources):

    /*
     * there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
     *
     *     dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
     *         = N pixels / (M inch / 25.4)
     *         = N * 25.4 pixels / M inch
     */

DPI results:

  • xrandr: 1920 x 25.4 / 344 = 141 (correct, but displaying issues)
  • xdpyinfo: 1920 x 25.4 / 508 = 96

I suspect X library to give real and 96dpi-like physical sizes.
Those from xdpyinfo are 96dpi-like sizes.

Finally, to fix that DPI issue, three options:

  • Finding and adding an option to xrandr command to avoid increasing the value
  • (or) Adding an option to mons for setting arbitrarily a value (if not used 96 by default)
  • (or) Force 96 by default into mons after switching second to primary mode

So be it. I will add a DPI option to mons.

Thanks!

commented

Feel free to report issue.