Skip to content

Commit

Permalink
8286872: Refactor add/modify notification icon (TrayIcon)
Browse files Browse the repository at this point in the history
Backport-of: 9f562ef7546c80e6ddce7b932f3f5ca17c741d21
  • Loading branch information
GoeLin committed Nov 11, 2022
1 parent cd4cc5d commit f29ade7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.cpp
Expand Up @@ -496,11 +496,7 @@ MsgRouting AwtTrayIcon::WmTaskbarCreated() {
// Update the icon image
item->m_trayIcon->UpdateImage();
}
BOOL result = item->m_trayIcon->SendTrayMessage(NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result) {
item->m_trayIcon->SendTrayMessage(NIM_SETVERSION);
}
item->m_trayIcon->AddTrayIcon();
}
m_bDPIChanged = false;
return mrDoDefault;
Expand Down Expand Up @@ -748,7 +744,7 @@ void AwtTrayIcon::SetToolTip(LPCTSTR tooltip)
_tcscpy_s(m_nid.szTip, TRAY_ICON_TOOLTIP_MAX_SIZE, tooltip);
}

SendTrayMessage(NIM_MODIFY);
ModifyTrayIcon();
}

void AwtTrayIcon::_SetToolTip(void *param)
Expand Down Expand Up @@ -816,10 +812,10 @@ void AwtTrayIcon::_UpdateIcon(void *param)
JNI_CHECK_PEER_GOTO(self, ret);
trayIcon = (AwtTrayIcon *)pData;

BOOL result = trayIcon->SendTrayMessage(jupdate == JNI_TRUE ? NIM_MODIFY : NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result && jupdate == JNI_FALSE) {
trayIcon->SendTrayMessage(NIM_SETVERSION);
if (jupdate == JNI_TRUE) {
trayIcon->ModifyTrayIcon();
} else {
trayIcon->AddTrayIcon();
}
ret:
env->DeleteGlobalRef(self);
Expand Down Expand Up @@ -868,7 +864,7 @@ void AwtTrayIcon::DisplayMessage(LPCTSTR caption, LPCTSTR text, LPCTSTR msgType)
_tcscpy_s(m_nid.szInfo, TRAY_ICON_BALLOON_INFO_MAX_SIZE, text);
}

SendTrayMessage(NIM_MODIFY);
ModifyTrayIcon();
m_nid.uFlags &= ~NIF_INFO;
}

Expand Down
15 changes: 14 additions & 1 deletion src/java.desktop/windows/native/libawt/windows/awt_TrayIcon.h
Expand Up @@ -52,7 +52,6 @@ class AwtTrayIcon: public AwtObject {

virtual void Dispose();

BOOL SendTrayMessage(DWORD dwMessage);
void LinkObjects(JNIEnv *env, jobject peer);
void UnlinkObjects();

Expand Down Expand Up @@ -154,6 +153,20 @@ class AwtTrayIcon: public AwtObject {
TrayIconListItem* m_next;
};

BOOL SendTrayMessage(DWORD dwMessage);

INLINE void AddTrayIcon() {
BOOL result = SendTrayMessage(NIM_ADD);
// 6270114: Instructs the taskbar to behave according to the Shell version 5.0
if (result) {
SendTrayMessage(NIM_SETVERSION);
}
}

INLINE void ModifyTrayIcon() {
SendTrayMessage(NIM_MODIFY);
}

static bool m_bDPIChanged;

public:
Expand Down

1 comment on commit f29ade7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.