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

Alexey Ivanov aivanov at openjdk.java.net
Mon May 9 21:04:14 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

src/java.desktop/share/classes/java/awt/SystemTray.java line 297:

> 295:                 // no tray icons present so do nothing
> 296:                 return;
> 297:             }

According to the spec, [`SystemTray.getTrayIcons()`](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/SystemTray.html#getTrayIcons()) never returns `null`. So the condition could be removed completely.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 38:

> 36: import java.awt.image.BaseMultiResolutionImage;
> 37: import java.awt.image.BufferedImage;
> 38: import java.awt.*;

Could you please expand wildcard imports? And sort the imports too?

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 73:

> 71:             System.out.println("SystemTray is not supported");
> 72:             return;
> 73:         }

This should be the first statement in main. If icons aren't supported, there's no need to create the instruction frame. The test will still wait for user's response but no tray icon is added.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 79:

> 77:         for (int size = 16; size <= 34; size++) {
> 78:             createIcon(size, images);
> 79:         }

You should go up to 48 at least, which corresponds to 300% scale in Windows settings; it's not as uncommon these days on UHD laptops.

The step could be 4: `size += 4`, it's the number of pixels an icon scales with each step 25% of scale in Windows settings. Windows still allows setting an arbitrary scale but it's discouraged, so we may assume the scale is changed via the main Settings app.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 84:

> 82: 
> 83:         SystemTray tray = SystemTray.getSystemTray();
> 84:         TrayIcon icon = new TrayIcon((Image) multiResolutionImage);

You can change the type of `multiResolutionImage` to `Image` to avoid casting when creating `TrayIcon`. The fact that it's a `MultiResolutionImage` isn't used down the code.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 100:

> 98:             tray.remove(icon);
> 99:             System.exit(0);
> 100:         });

You shouldn't call `System.exit` from a jtreg test.

The icon should probably be removed after pressing Pass or Fail button, this is likely what prevents the test from exiting.

The popup menu isn't important for this test case.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 115:

> 113:         g.setColor(Color.WHITE);
> 114:         g.fillRect(0, 0, size, size);
> 115:         g.setFont(new Font("Dialog", Font.BOLD, 12));

It could be more effective to create `Font` once and use it for rendering text for each icon size but it's not really important for a short-lived test.

test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 126:

> 124:         g.dispose();
> 125:     }
> 126: }

Usually, files end with a new line.

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

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



More information about the client-libs-dev mailing list