Bug 572262 - [win32] consistently enable SWT dpi awareness settings
Summary: [win32] consistently enable SWT dpi awareness settings
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.19   Edit
Hardware: PC Windows 10
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-24 07:22 EDT by Rolf Theunissen CLA
Modified: 2022-11-28 07:20 EST (History)
6 users (show)

See Also:
sravankumarl: review+


Attachments
Big menu/title fonts but unreadable everything else (60.88 KB, image/png)
2021-11-16 13:56 EST, Ed Merks CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rolf Theunissen CLA 2021-03-24 07:22:59 EDT
In Bug 533135 dpi awareness is added for win32. However, the dpi awareness is not consistently configured.

This functionality is added by configuring a (external) java.exe.manifest. The dpi awareness settings changed with the different Java versions.

Java 8, uses dpi aware system [1], Java 9 uses dpi aware per monitor [2], Java 11 uses dpi aware per monitor v2 (with fallback to per monitor and system) [3].

Also the Eclipse launcher uses its own settings, namely dpi aware system [4].

Moreover, dpi awareness is not only configured in the manifest, but it can also be configured via API [5]. Modern Windows 10 system even support mixed mode DPI scaling [6]. Also SWT uses this API to configure DPI aware system for Vista and higher, see OS.java static initialize block.

The result of this is that SWT behaves differently when launched with different Java versions. For the Eclipse case, it is even dependent on how the JVM is selected (as library or executable with the -vm option), see also Bug 571209.

To get dpi awareness consistently enabled:
- Validate if the manifest workaround of Bug 533135 is still needed, and update documentation accordingly.
- eclipse.exe.manifest should be updated to the proper dpi awareness settings.
- OS.java should be made robust for different manifest configurations, i.e. use the correct API calls.

Be aware that these changes can make Bug 571209 more prominent.

[1] https://bugs.openjdk.java.net/browse/JDK-8073320
[2] https://github.com/AdoptOpenJDK/openjdk-jdk9u/blob/master/jdk/src/java.base/windows/native/launcher/java.manifest
[3] https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/windows/native/launcher/java.manifest
[4] https://git.eclipse.org/c/equinox/rt.equinox.framework.git/tree/features/org.eclipse.equinox.executable.feature/library/win32/eclipse.exe.manifest
[5] https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows
[6] https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-improvements-for-desktop-applications
Comment 1 Rolf Theunissen CLA 2021-03-25 08:11:30 EDT
@Niraj would you be able to help out here?
Comment 2 Niraj Modi CLA 2021-11-11 04:51:32 EST
Just a back-ground on the current 'dpiAware' and 'dpiAwareness' settings in javaw.exe.manifest:
On Windows10 when we change the Display Scale factor to say 175% from the default 150%, SWT receives SWT.ZoomChanged event from the native.

On SWT.ZoomChanged event Eclipse notifies user to re-start Eclipse to proper scale at increased zoom value.

Receiving SWT.ZoomChanged event was possible only with mentioned 'dpiAware' and 'dpiAwareness' settings.
-----------------------------------------------------------------------------
To experiment with, we can still configure an external 'javaw.exe.manifest' on Windows, sharing the exact steps below:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=533135#c5

As per comment 0, since Java 8 to Java 9 to Java 11 these dpi setting are updated.
And SWT seems to be using 

Let us know if you find a better javaw.exe.manifest configuration, I will also check my side on this. Thanks!
Comment 3 Rolf Theunissen CLA 2021-11-11 05:09:08 EST
I think that the main issues is with the eclipse.exe.manifest file used to create the eclipse launcher in equinox framework. This manifest is not up to date with the recommended java.exe.manifest as provided by SWT.

Best would be that SWT is not depending on any manifest configuration, but using API calls, such that it would work in any environment. On modern windows, this could even be a per thread setting.
Comment 4 Niraj Modi CLA 2021-11-16 06:07:00 EST
(In reply to Rolf Theunissen from comment #3)
> I think that the main issues is with the eclipse.exe.manifest file used to
> create the eclipse launcher in equinox framework. This manifest is not up to
> date with the recommended java.exe.manifest as provided by SWT.

Ok, I am planning to update eclipse.exe.manifest on same lines as SWT's java.exe.manifest to avoid differences in the dpi settings here.

I hope this should help avoid the inconsistency part that you noticed.
Let's explore/test this out first, if this doesn't work we can explore other options like below.
> Best would be that SWT is not depending on any manifest configuration, but
> using API calls, such that it would work in any environment. On modern
> windows, this could even be a per thread setting.
Comment 5 Eclipse Genie CLA 2021-11-16 06:17:17 EST
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/187779
Comment 7 Niraj Modi CLA 2021-11-16 09:36:34 EST
Hi Rolf/Ed,
Please try out the latest Eclipse IBuild:
https://download.eclipse.org/eclipse/downloads/drops4/I20211116-0600/

Let us know if things have improved.
Comment 8 Rolf Theunissen CLA 2021-11-16 13:51:40 EST
(In reply to Niraj Modi from comment #7)
> Hi Rolf/Ed,
> Please try out the latest Eclipse IBuild:
> https://download.eclipse.org/eclipse/downloads/drops4/I20211116-0600/
> 
> Let us know if things have improved.

With this change, for me, both with the eclipse.exe as well as the runtime instance (java.exe), Eclipse follows the DPI of the screen with each of the windows. 

However, launching with eclipsec.exe does not enable the per window scaling and results in a blurry screen when moving to another screen resolution. Is there a separate manifest for the eclipsec.exe executable?

Niraj, if you or somebody else can also take a look at Bug 571209, this will get more prominent and results in a deadlock in the IDE.
Comment 9 Ed Merks CLA 2021-11-16 13:55:47 EST
Oh my god, no!!!  It's horrible.  This is exactly the problem I had and needed to fix by disabling this behavior for javaw.exe.  Now I will have to fix ever single installation's *.exe manually.  This is such a no go. :-(
Comment 10 Ed Merks CLA 2021-11-16 13:56:31 EST
Created attachment 287531 [details]
Big menu/title fonts but unreadable everything else
Comment 11 Ed Merks CLA 2021-11-16 14:04:20 EST
I cannot emphasis enough that for me this makes Eclipse unusable in my multi-monitor environment.  I have 3 monitors with 100%, 150%, and 225% scaling.  Every window that I move from monitor to monitor scales such that the fonts are roughly the same physical size. 

But now Eclipse is the only application that is completely ill behaved.  If Eclipse is going to claim to be aware of DPI to the OS it will need to scale fonts and images properly, but it does not do that.  It should let the operating system do the scaling.

Please please revert this change.  Don't release like this.  I can only make Eclipse usable by manually telling the OS not to let the application do the scaling.
Comment 12 Rolf Theunissen CLA 2021-11-16 14:50:09 EST
(In reply to Ed Merks from comment #9)
> Oh my god, no!!!  It's horrible.  This is exactly the problem I had and
> needed to fix by disabling this behavior for javaw.exe.  Now I will have to
> fix ever single installation's *.exe manually.  This is such a no go. :-(

Alright, I missed to noticed that scaling doesn't happen for all widgets. With the old settings, the majority of the text seems to scale, but can get blurry. With the new settings, many widgets fail to react to the resize event (and even Eclipse might need a restart to properly deal with it).

So as opposed to what is suggested by other bug fixes (e.g Bug 533135 and https://www.eclipse.org/swt/faq.php#win10dpiawareness), SWT 4.8 did not bring per-monitor HiDPI scaling for the windows system. If SWT does not do per-monitor scaling, it should also not be enabled in the manifest. But then it should be prevented that it is enabled when loaded with a modern java JRE. (So back to the robust API suggestion that will work independent from any executable, which is the proper behavior for a library component what SWT is.) 
Enabling with system-aware DPI settings might make more sense.
Comment 13 Niraj Modi CLA 2021-11-17 01:39:48 EST
Thanks for the feedback, firstly will revert the "eclipse.exe.manfest" change.
Comment 14 Eclipse Genie CLA 2021-11-17 01:43:12 EST
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/187122
Comment 15 Ed Merks CLA 2021-11-17 01:43:58 EST
Thank you for your understanding!
Comment 17 Niraj Modi CLA 2021-11-17 03:52:05 EST
Looks like Java (In reply to Rolf Theunissen from comment #0)
> In Bug 533135 dpi awareness is added for win32. However, the dpi awareness
> is not consistently configured.
> 
> This functionality is added by configuring a (external) java.exe.manifest.
> The dpi awareness settings changed with the different Java versions.
> 
> Java 8, uses dpi aware system [1], Java 9 uses dpi aware per monitor [2],
> Java 11 uses dpi aware per monitor v2 (with fallback to per monitor and
> system) [3].

Java11 onwards, the default manifest setting from the Java side are good enough and SWT tweaking is not required any more:
https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/windows/native/launcher/java.manifest

Early 4.23 we remove this altogether the way it's already proposed in bug 560195, refer below gerrit for details:
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/157775
Comment 18 Rolf Theunissen CLA 2021-11-17 04:46:11 EST
(In reply to Niraj Modi from comment #17)
> Looks like Java (In reply to Rolf Theunissen from comment #0)
> > In Bug 533135 dpi awareness is added for win32. However, the dpi awareness
> > is not consistently configured.
> > 
> > This functionality is added by configuring a (external) java.exe.manifest.
> > The dpi awareness settings changed with the different Java versions.
> > 
> > Java 8, uses dpi aware system [1], Java 9 uses dpi aware per monitor [2],
> > Java 11 uses dpi aware per monitor v2 (with fallback to per monitor and
> > system) [3].
> 
> Java11 onwards, the default manifest setting from the Java side are good
> enough and SWT tweaking is not required any more:
> https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/
> windows/native/launcher/java.manifest
> 
> Early 4.23 we remove this altogether the way it's already proposed in bug
> 560195, refer below gerrit for details:
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/157775

Clearly, the per-monitor settings in the java manifest file are not the correct ones, as these result in the issue that Ed reported. SWT is not per-monitor aware, while the java manifest states that Java (AWT/Swing) is. 
Also, depending on the environment will only decrease consistency, not increase it.
Comment 19 Niraj Modi CLA 2022-03-04 00:01:43 EST
Moving out of 4.23