RFR: JDK-8255439: System Tray icons get corrupted when windows scaling changes [v3]
Phil Race
prr at openjdk.java.net
Mon May 9 21:10:58 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
Changes requested by prr (Reviewer).
src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.cpp line 238:
> 236: if (updateTrayFn != NULL) {
> 237: env->CallStaticVoidMethod(systemTrayClass,
> 238: updateTrayFn);
Most of these JNI methods can leave an exception pending
https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#findclass
https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#getstaticmethodid
https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#callstatictypemethod-routines-callstatictypemethoda-routines-callstatictypemethodv-routines
I think you should be calling ExceptionClear() because subsequent methods should not be called with an exception pending. And this is a windows thread attached to the VM and it never "returns to Java" but will be called back to handle later events.
src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.cpp line 262:
> 260: // (generated when DPI changes)
> 261: case WM_WINDOWPOSCHANGING:
> 262: if (hwnd == AwtTrayIcon::sm_msgWindow) {
I'd just like to be sure .. this message is not sent when an application window is moved, right ?
It is just sent to the tray icon window .. and so happens only if someone did something like re-orged tray icons ..
or the dpi changes ? In other words I'd like to be sure it is a rare event.
test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 72:
> 70: if (!SystemTray.isSupported()) {
> 71: System.out.println("SystemTray is not supported");
> 72: return;
Hmm. When you get here, you already displayed the instructions window, and in the jtreg harness, the user will not see this message. They'll just not see the tray icon and assume it failed.
I think you should be making use of the "forcePass()" code in PassFailJFrame
test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java line 99:
> 97: exitItem.addActionListener(e -> {
> 98: tray.remove(icon);
> 99: System.exit(0);
Even if it is manual etc, we don't call System.exit() in jtreg tests .. we just shut down all the windows and dispose them so there is nothing to keep the main thread from exiting.
If this is called, I don't know why Kevin didn't see the app exit.
I suspect it cannot have been and he exited via some other path which left windows in existence which meant the toolkit thread didn't exit.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8441
More information about the client-libs-dev
mailing list