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

Alexey Ivanov aivanov at openjdk.java.net
Thu May 12 19:02:41 UTC 2022


On Thu, 12 May 2022 00:02:35 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:
> 
>   trayicon update triggered on taskbar reload

Yeah, this version works correctly on both test systems that I have.

I think the solution could be simplified. First of all, there's no need to call `UpdateTrayIconHandler` if DPI hasn't changed. A handler for `WM_DPICHANGED` sets a flag; then `WmTaskbarCreated` uses the flag to call updateImage.

`WmTaskbarCreated` iterates over all the icons, you can use this loop to call `WTrayIconPeer.updateImage`. This way all the icons will be updated on the toolkit thread. I'm not sure whether the handler should still sent both `NIM_MODIFY` and `NIM_ADD`; the former should be enough for DPI change (called from `updateNativeImage`), and the latter should be enough for the case where the Taskbar is really recreated.

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

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



More information about the client-libs-dev mailing list