HiDPI configuration

HiDPI modes

  1. JRE-managed HiDPI mode (default on macOS since JDK7, on Windows since 2018.2/JBR8, on Linux since 2019.2/JBR11). JBR stands for JetBrains Runtime, Java runtime based on OpenJDK and maintained by JetBrains.

    Enabled via the VM option: -Dsun.java2d.uiScale.enabled=true
    (Help | Edit Custom VM Options).

    In this mode the UI scaling is defined by the product of the two scale factors: the user scale (managed by the IDE) and the system scale (managed by the JBR).

  2. IDE-managed HiDPI mode (legacy mode).

    Enabled via the VM option:  -Dsun.java2d.uiScale.enabled=false
    (Help | Edit Custom VM Options).

    In this mode the UI scaling is defined only by the user scale factor (managed by the IDE).

Two types of scale factors

  1. The user scale factor is derived from the IDE main font size:

    Settings > Appearance and Behavior > Appearance > Use custom font

    The font size is presented in relative points in the JRE-managed HiDPI mode (the real font size in pixels can be bigger). In this mode the default font size defines the user scale as 1.0.

    In the IDE-managed HiDPI mode the font size is presented in absolute points (matching the real font size in pixels). In this mode the default font size depends on the desktop scaling and it defines the user scale that can differ from 1.0. (Note that the font size in the editor is not affected by the main font size and is configured separately).

    It's possible to force the user scale factor by providing the VM option below. In this case the font size is untied from the user scale what may cause UI imperfections (and so this option is not recommended other than for debugging purposes).

    -Dide.ui.scale=<floating point value>
    (e.g. -Dide.ui.scale=1.25).

  2. The system scale factor is configured on the OS level. However, it's possible to force the system scale factor by providing the VM option (mostly used for debugging purposes):

    -Dsun.java2d.uiScale=<floating point value>
    (e.g. -Dsun.java2d.uiScale=1.75).

    It's possible to inspect the current IDE scaling settings via Help | Find Action: "Show HiDPI Info" (available in -Didea.is.internal=true mode, and by default since 2019.2.1).

    The instructions below relate to the system scale factor settings.

Linux

JBR 8

Single-monitor DPI is supported. DPI is defined by Xft.dpi X resource value.

To get:

$ xrdb -q | grep -i dpi

To set:

$ xrandr --dpi <dpi>

It can also be set via your Linux Desktop settings, or via gnome-tweak-tools.

JBR 11

The system scale factor in the JRE-managed HiDPI mode is determined by the following settings, in order:

  1. If the system scale factor is forced via -Dsun.java2d.uiScale property - it's just used.

  2. The following GSettings are considered (use dconf-editor to edit):

    Per-monitor DPI key (Wayland, not well supported yet):
    ubuntu.user-interface/scale-factor

    Global DPI key:
    org.gnome.desktop.interface/scaling-factor

    (These keys, used since OpenJDK 9, are currently disabled in JBR 11:
    com.canonical.Unity.Interface/text-scale-factor
    org.gnome.desktop.interface/text-scaling-factor
    ).

  3. If GDK_SCALE environment variable is set, the above scale factor is multiplied by it.

    See: https://developer.gnome.org/gtk3/stable/gtk-x11.html .

    This can be unexpected and there're the following options to cope with it:
    • Compensate it via setting GDK_DPI_SCALE env variable (since 2019.2.1).
    • Unset GDK_SCALE before starting the IDE. 
    • Force the system scale factor (see 1).
    • Switch to the legacy IDE-managed HiDPI mode (see the "HiDPI modes" section).
  1. If none of the above settings is defined, then the system scale is derived from the Xft.dpi value (e.g. 192 dpi will define 2.0 scale factor).

    GDK_SCALE is applied to Xft.dpi as well (since 2019.2.1, see 3).

    Note, currently fractional scale factor is not supported on Linux in the JRE-managed HiDPI mode. So if Xft.dpi defines a fraction scale, then the IDE is automatically switched to the legacy IDE-managed HiDPI mode (and the GDK_SCALE is not applied).

  2. If none of the above settings is defined, then the system scale factor is set to 1.0.

    On Linux desktop environments other than Gnome, IDE still behaves like GDK application obeying the HiDPI settings above.

    Guide: https://wiki.archlinux.org/index.php/HiDPI .

Windows

Per-monitor DPI is supported since JBR 8. Configured as scale factor in Display Settings system dialog.

Guide: DPI Scaling in the Windows 10 Anniversary Update .

macOS

Per-monitor DPI is supported since JDK 7. Currently, the system scale factor is either 2.0 on Retina and 1.0 on a standard display.

7 comments
Comment actions Permalink

Using linux mint 19 on a macbook pro retina mid 2015, (window of intellij and font where tooo small) used a combination of:

 -Dhidpi=false

-Dide.ui.scale=2.0

on: Help -> Edit custom vm options (idea64.vmoptions file) 

To correct retina display, adjust the font of the editor , worked fine for me

1
Comment actions Permalink

On Linux + Gnome, when I undock from my Thunderbolt dock the scale of the system changes from 100% to 200%, perfect as my laptop is a much smaller screensize with same resolution. Other apps such as Brave/Chrome instantly honor my new system scale. But IntelliJ does not, and I have to "just restart" to get the new scale to take effect. We need IntelliJ to update as soon as system scale changes, not just on launch. 

I just found this article after realizing what was going on and doing some searches and I will tinker with the options here to see what I can find out. Thanks for posting it. 

UPDATE: Found an issue filed for this via https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000629184/comments/360000394760 > https://youtrack.jetbrains.com/issue/IDEA-194145. I am engaging there now, the suggestion doesn't yet work for me yet, follow that thread for updates if you have same issue. 

Edited by Elijah Lynn
0
Avatar
Arseniy Nisnevich
Comment actions Permalink

Hi Elijah,

I've answered you in IDEA-194145.

Edited by Arseniy Nisnevich
0
Comment actions Permalink

I am running latest Intellij IDEA in WSL2. I have a 4k monitor, and have set scale to 150% on Windows. To achieve the same thing with the X Server, I have set GDK_SCALE=2 & GDK_DPI_SCALE=0.75. All gui apps running on WSL adjust fine, except for Idea which scales to 200% instead of 150%.

Below you can see the HiDPI Info. I have tried many combinations of all possible scale parameters but with no luck.

1
Avatar
Arseniy Nisnevich
Comment actions Permalink

Hi Liakoskonstantin,

I filed a new issue.

Please, vote and follow for updates. If you aren't familiar with YouTrack, see this instruction.

 

0
Comment actions Permalink

I can only underline, what Serge Baranov writes here, that fractional scaling is not yet well supported in Wayland.

I am using a 4K display with 150% scaling and when starting IDEA under Linux Mint everything looked fine. In Ubuntu everything looked blurry. The reason is, that Mint uses X11 (Cinnamon does not support Wayland yet) while Ubuntu uses Wayland by default.

I played around a lot with different settings and came to the conclusion - and this is my personal recommendation - that IDEA works best under X11 if fractional scaling is needed. If that is true for you, switch your Gnome session to X, set the fractional scaling again system-wide, and everything should be fine out of the box. Make sure you undo your previous settings changes as well (GDK*SCALE, dconf, idea64.vmoptions).

If you do not need fractional scaling I found IDEA to also look well with Wayland and 200% scaling (and factional scaling turned off).

To switch to X on Ubuntu, logout, click on the gear icon in the bottom right corner and select "Ubuntu on Xorg".

The simple reason seems to be that IDEA is Swing/AWT based, which itself is not ported to Wayland yet. Therefor XWayland is used, which itself has its limitations, especially with fractional scaling, multiple monitors or resolution changes.

Some interesting links in the context, if someone wants to dig deeper:
https://openjdk.java.net/projects/caciocavallo/ - Caciocavallo: Portable GUI Backends (OpenJDK project)
https://stackoverflow.com/a/66333053 - points to an experimental AWT implementation using Wayland
https://gitlab.freedesktop.org/xorg/xserver/-/issues/1054 - in XWayland scaling cannot be turned off on a per-application basis (open issue)
https://wiki.archlinux.org/title/Weston - Weston - can be used for experiments with Wayland

Edited by Harald Fassler
0
Comment actions Permalink

Liakoskonstantin

I think that the "Monitor Scale" parameter is the one that causes your issue. I did not try under WSL yet, but "native" Ubuntu creates me a file ~/.config/monitors.xml. If you have this file you could try to configure <scale>1.5</scale> there (+restart WSL). A further step could be to remove the GDK_SCALE setting, too.

0

Please sign in to leave a comment.

Have more questions?

Submit a request