Ventto / mons

POSIX Shell script to quickly manage monitors on X
MIT License
632 stars 39 forks source link

DPI creeping up by 1 on every execution #13

Closed dkambersky closed 6 years ago

dkambersky commented 6 years ago

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.

Ventto commented 6 years ago

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.

dkambersky commented 6 years ago

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.

Ventto commented 6 years ago

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.

dkambersky commented 6 years ago

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.

Ventto commented 6 years ago

@dkambersky, thanks again for testing.

Could you please give me your monitor size information ?

dkambersky commented 6 years ago

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

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

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!

Ventto commented 6 years ago

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:

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:

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:

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

dkambersky commented 6 years ago

Thanks!

Ventto commented 6 years ago

Feel free to report issue.