Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double HiDPI scaling when started on JetBrains JDK #7780

Open
cristatus opened this issue Sep 22, 2024 · 10 comments
Open

Double HiDPI scaling when started on JetBrains JDK #7780

cristatus opened this issue Sep 22, 2024 · 10 comments
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers os:linux UI User Interface

Comments

@cristatus
Copy link

Apache NetBeans version

Apache NetBeans 23 release candidate

What happened

Netbeans 23 launcher auto-detects HiDPI and set's GDK_SCALE=2. However, some jdk especially 21 and JBR distributions handle scaling naively. Setting GDK_SCALE=2 in launch script results in 4x scaling.

Language / Project Type / NetBeans Component

No response

How to reproduce

Use temurin jdk 21 or Jetbrain JDK 21 and luanch netbeans 23. The netbeans UI on HiDPI screen with 2x scale looks like 4x scaled.

Did this work correctly in an earlier version?

Apache NetBeans 22

Operating System

Arch Linux

JDK

21

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

Yes

@cristatus cristatus added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Sep 22, 2024
@mbien mbien added the UI User Interface label Sep 22, 2024
@mbien
Copy link
Member

mbien commented Sep 22, 2024

GDK_SCALE might be a workaround from JDK 8 times, before JEP 263. Although the JDK does check the value too:
https://github.com/openjdk/jdk/blob/ab06a878f888827026424530781f0af414a8a611/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c#L41-L52

If scaling is now detected correctly on JDK 17+ the extra launcher logic should be probably removed. There are going to be some edge cases with multi screen setups where not all screens need scaling etc. If it turns out that it is still needed, we might have to set -Dsun.java2d.uiScale.enabled=false too whenever GDK_SCALE is set to prevent double scaling issues.

btw NetBeans is currently only tested on OpenJDK re-distributions, experience may vary if you run it on forks

@mbien mbien added the os:linux label Oct 9, 2024
@sijskes
Copy link
Contributor

sijskes commented Feb 13, 2025

Would it be possible, to change this logic into setting J2D_UISCALE=2 ?

When i'm developing a desktop application, that 'exec's another GUI application, like via xdg-open, the environment of that process inherits the GDK_SCALE, and in for instance 'atril' (pdf viewer) this results in 4x scaling.

I've tested it with J2D_UISCALE, and for now good results.

I does not work without both J2D_UISCALE or GDK_SCALE, because then the fonts are really small.

Removing this logic is an option too. All java programs on my X11-ubuntu-mate desktop suffer from small fonts, so i've set J2D_UISCALE=2 in my profile script.

Because of the logic in JDK 21 (others i have not checked) the JDK ignores the GDK_SCALE when J2D_UISCALE is set.

Maybe we need to suggest to HiDPI users for this combinations of factors to set the variable in the profile (during netbeans startup)?

I'm not sure if this next stage in X11-ubuntu-mate scaling signalling is a permanent one, and if it is valid on on other platforms than Ubuntu 24.04.2 LTS (noble). I've had severe UI scaling issues in the past with older JDK's and older desktops.

I'm willing to test new versions of the startup script.

versions:
Ubuntu 24.04.2 LTS
Product Version: Apache NetBeans IDE 25-rc1
Java: 21.0.6; OpenJDK 64-Bit Server VM 21.0.6+7-Ubuntu-124.04.1
Runtime: OpenJDK Runtime Environment 21.0.6+7-Ubuntu-124.04.1
System: Linux version 6.8.0-53-generic running on amd64; UTF-8; en_US (nb)

@mbien
Copy link
Member

mbien commented Feb 13, 2025

@sijskes if you don't set J2D_UISCALE via your profile, will NB scale correctly with 2x?

When i'm developing a desktop application, that 'exec's another GUI application, like via xdg-open, the environment of that process inherits the GDK_SCALE, and in for instance 'atril' (pdf viewer) this results in 4x scaling.

you could probably set the scaling env var to 1 if you invoke the application, no?

In any case this sounds like a separate issue to me. Going to rename this issue to make it more clear that this is about JDK forks which try to influence scaling and behave differently to OpenJDK distributions.

other related issue: #6185

@mbien mbien changed the title Fix automatic HiDPI scaling on Linux Double HiDPI scaling when started on JetBrains JDK Feb 13, 2025
@sijskes
Copy link
Contributor

sijskes commented Feb 13, 2025

@sijskes if you don't set J2D_UISCALE via your profile, will NB scale correctly with 2x?

yes

When i'm developing a desktop application, that 'exec's another GUI application, like via xdg-open, the environment of that process inherits the GDK_SCALE, and in for instance 'atril' (pdf viewer) this results in 4x scaling.

you could probably set the scaling env var to 1 if you invoke the application, no?

yes i could. or remove the variable from the environment. But if the application then runs on a platform that uses GDK_SCALE it wouldnt scale correctly.

In any case this sounds like a separate issue to me. Going to rename this issue to make it more clear that this is about JDK forks which try to influence scaling and behave differently to OpenJDK distributions.

Ok, shall i open another?

@mbien
Copy link
Member

mbien commented Feb 13, 2025

if you don't set J2D_UISCALE via your profile, will NB scale correctly with 2x?

yes

in that case it sounds like it could be handled by the same mechanism proposed in the above linked issue

@sijskes
Copy link
Contributor

sijskes commented Feb 13, 2025

if you don't set J2D_UISCALE via your profile, will NB scale correctly with 2x?

yes

in that case it sounds like it could be handled by the same mechanism proposed in the above linked issue

No, it doesn't. Setting GDK_SCALE, causes X programs, invoked from program under development, to inherit this, and give 4x scaling. Removing GDK_SCALE during invocation is no option, because program invoked, at deployment stage, might need GDK_SCALE.

Using J2D_UISCALE instead of GDK_SCALE limits the impact of the behaviour to java programs only. and actually works correctly for java programs.

@mbien
Copy link
Member

mbien commented Feb 13, 2025

the launcher could check both env vars

@sijskes
Copy link
Contributor

sijskes commented Feb 13, 2025

the launcher could check both env vars

Shouldnt an IDE offer a environment very similar to deployment? What your are implying is fixing the IDE bugs in the software developed.

@mbien
Copy link
Member

mbien commented Feb 13, 2025

I have nothing against J2D_UISCALE or GDK_SCALE, switching to the first might be now an option since JDK requirement is 17+ but testing has to confirm it. What the launcher should likely not do is to overwrite already set env vars when they were customized - this applies to both vars.

@sijskes
Copy link
Contributor

sijskes commented Feb 13, 2025

I have nothing against J2D_UISCALE or GDK_SCALE, switching to the first might be now an option since JDK requirement is 17+ but testing has to confirm it. What the launcher should likely not do is to overwrite already set env vars when they were customized - this applies to both vars.

I solved it by using "export J2D_UISCALE=2" in profile script. That has the least amount of impact, and works. Moving over to #8243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix needs:triage Requires attention from one of the committers os:linux UI User Interface
Projects
None yet
Development

No branches or pull requests

3 participants