Skip to content

Auto-detect HiDPI fractional scaling settings on Linux #8589

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

basil
Copy link

@basil basil commented Jun 15, 2025

The current logic to auto-detect HiDPI settings on Linux from #3113 only handles the 2x case. This PR expands it to handle fractional scaling, as described in this thread.

Taking #7780 (comment) into consideration, the launcher does not touch the scaling settings if one or both of the GDK_SCALE and J2D_UISCALE environment variables is set.

This PR was tested with both Java 17 and 21 (Eclipse Temurin) on Fedora 42 with fractional scaling enabled in KDE Plasma. Before this PR, no scaling was applied; after this PR, fractional scaling is applied and the following is logged:

Detected 158 DPI in Xft.dpi setting; using explicit setting for Java UI scaling (-J-Dsun.java2d.uiScale=2) and FlatLaf UI scaling (-J-Dflatlaf.uiScale=0.822917)

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@eirikbakke eirikbakke added the UI User Interface label Jun 16, 2025
@eirikbakke eirikbakke self-requested a review June 16, 2025 20:04
@eirikbakke
Copy link
Contributor

Thanks for this PR! So, to understand correctly, this handles fractional scaling (e.g. 150%) by using the 2x scaling at the AWT level (sun.java2d.uiScale), but then using FlatLAF's own scaling method (flatlaf.uiScale) to scale many, though not all, UI components down again by a bit less?

The downside is that the UI still looks somewhat wonky, because only some components observe flatlaf.uiScale.

On MacOS, fractional scalings are handled by the OS by scaling everything at 2x and then scaling down and anti-aliasing the entire image of the window, at the graphics card level. That tends to look much nicer. Is there no equivalent of that mechanism on GNOME/X that we can tap into?

@basil
Copy link
Author

basil commented Jun 16, 2025

The downside is that the UI still looks somewhat wonky

It does not look wonky to me with this PR.

Is there no equivalent of that mechanism on GNOME/X that we can tap into?

I don't know.

@eirikbakke
Copy link
Contributor

I emailed a GNOME developer, I will see if there's a way to do the down-scaling step at the compositing level instead. That would also have the advantage of working with multiple monitors, even if they have different desired scaling levels.

@basil
Copy link
Author

basil commented Jun 16, 2025

I am using KDE Plasma, not GNOME. I don't have any interest in expanding the scope of this PR as described. This PR is a net improvement over the status quo, which doesn't support fractional scaling at all. It follows a method that has been tested and reported as successful by myself and two other users. I'm not willing to try implementing and/or testing a different approach.

@eirikbakke
Copy link
Contributor

Sorry, I suspect the relevant settings are actually at the Wayland level, not specific to GNOME or KDE... I just suspect there exist people who might be able to immediately tell me if the compositing approach would work, and how to test it.

@basil
Copy link
Author

basil commented Jun 16, 2025

I just suspect there exist people who might be able to immediately tell me if the compositing approach would work, and how to test it.

If such an approach exists, I think that would be great information to share with anyone who is willing to try implementing and/or testing a different approach. As mentioned above, I am not willing to do so.

@neilcsmith-net
Copy link
Member

neilcsmith-net commented Jun 19, 2025

Sorry, I suspect the relevant settings are actually at the Wayland level,

@eirikbakke well, also XWayland level, which I believe has different configuration options for handling scaling too - automatic and application level? Given the range of parameters, and need to handle this right across X11 and XWayland, with potentially different settings, I have concerns about putting too much logic into the launchers themselves. See also #6185 etc.

@eirikbakke
Copy link
Contributor

eirikbakke commented Jun 19, 2025

I have concerns about putting too much logic into the launchers themselves.

Perhaps, if fractional DPI is detected, we could just print a notice with a link to a Wiki page or such, listing options that have been tried and are known to work for different setups?

also XWayland level, which I believe has different configuration options for handling scaling too - automatic and application level?

Yes, I was in the slow process of learning more about this. OpenJDK is indeed XWayland, not a full wayland app (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants