RFR: JDK-8255439: System Tray icons get corrupted when windows scaling changes [v3]

Harshitha Onkar duke at openjdk.java.net
Mon May 9 17:00:50 UTC 2022


On Sun, 8 May 2022 19:36:33 GMT, Harshitha Onkar <duke at openjdk.java.net> wrote:

>> In Windows, when desktop scaling is changed the tray icons was distorted/blurred a bit each time scaling changes.
>> 
>> With the proposed fix, the tray icon scales according to on-the-fly DPI scale settings. A test case has been added which adds a MRI icon to system tray, to observe the icon scaling when DPI is changed. Since the scale cannot be programmatically changed (for dynamic on-the-fly scale changes), I have used a manual test case to test this scenario.
>> 
>> When DPI changes usually two messages are sent by windows -
>> 
>> - [WM_DPICHANGED](https://docs.microsoft.com/en-us/windows/win32/hidpi/wm-dpichanged)
>> - [WMPOSCHANGING](https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-windowposchanging)
>> 
>> I'm triggering an update on tray icons on receiving WMPOSCHANGING msg through the Tray icon's Window Procedure. Triggering an update on WM_DPICHANGED was still causing the icons to be distorted, hence WMPOSCHANGING is being used as the message to trigger the update.
>
> Harshitha Onkar has updated the pull request incrementally with one additional commit since the last revision:
> 
>   formatting changes

Following are the approaches tried for Tray icon issue fix –

**1.	Using WM_DPICHANGED** – issue with this approach is the delay in scale values update as @kevinrushforth pointed out earlier.

**2.	Using DisplayChangedListener** -   To deal with delay in scale updates, @aivanov-jdk suggested to try DisplayChangedListener approach. This worked well, but tray icon distortion was still observed when the scales were changed in quick succession and especially when scaled down to 125%. 

Details of this approach -
•	Implemented a DisplayChangedListener on WTrayIconPeer 
•	Added displayChangedListener to local graphics environment to listen for DPI changes in WTrayIconPeer 
•	Override the displayChanged() so that WTrayIconPeer’s updateImage() is called whenever the DPI changes for the 
        default/main display.

**3.	Using WM_WINDOWPOSCHANGING** – With present testing, there is no distortion observed when an update to tray icon is triggered on this message.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8441



More information about the client-libs-dev mailing list