Windows QPA: Fix tray icon becoming visible before show
Use the NIS_HIDDEN flag of the NOTIFYICONDATA structure to prevent it from becoming visible before show when calling NIM_ADD with the icon data. Fixes: QTBUG-73185 Change-Id: If5cc5a4930a889623a5cac84138185ad04765ece Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>bb10
parent
19d1fdc5a5
commit
4aa0bcf5f5
|
|
@ -103,6 +103,13 @@ static void setIconContents(NOTIFYICONDATA &tnd, const QString &tip, HICON hIcon
|
|||
qStringToLimitedWCharArray(tip, tnd.szTip, sizeof(tnd.szTip) / sizeof(wchar_t));
|
||||
}
|
||||
|
||||
static void setIconVisibility(NOTIFYICONDATA &tnd, bool v)
|
||||
{
|
||||
tnd.uFlags |= NIF_STATE;
|
||||
tnd.dwStateMask = NIS_HIDDEN;
|
||||
tnd.dwState = v ? 0 : NIS_HIDDEN;
|
||||
}
|
||||
|
||||
// Match the HWND of the dummy window to the instances
|
||||
struct QWindowsHwndSystemTrayIconEntry
|
||||
{
|
||||
|
|
@ -193,12 +200,15 @@ QWindowsSystemTrayIcon::~QWindowsSystemTrayIcon()
|
|||
void QWindowsSystemTrayIcon::init()
|
||||
{
|
||||
qCDebug(lcQpaTrayIcon) << __FUNCTION__ << this;
|
||||
ensureInstalled();
|
||||
m_visible = true;
|
||||
if (!setIconVisible(m_visible))
|
||||
ensureInstalled();
|
||||
}
|
||||
|
||||
void QWindowsSystemTrayIcon::cleanup()
|
||||
{
|
||||
qCDebug(lcQpaTrayIcon) << __FUNCTION__ << this;
|
||||
m_visible = false;
|
||||
ensureCleanup();
|
||||
}
|
||||
|
||||
|
|
@ -333,6 +343,18 @@ void QWindowsSystemTrayIcon::ensureCleanup()
|
|||
m_toolTip.clear();
|
||||
}
|
||||
|
||||
bool QWindowsSystemTrayIcon::setIconVisible(bool visible)
|
||||
{
|
||||
if (!isInstalled())
|
||||
return false;
|
||||
NOTIFYICONDATA tnd;
|
||||
initNotifyIconData(tnd);
|
||||
tnd.uID = q_uNOTIFYICONID;
|
||||
tnd.hWnd = m_hwnd;
|
||||
setIconVisibility(tnd, visible);
|
||||
return Shell_NotifyIcon(NIM_MODIFY, &tnd) == TRUE;
|
||||
}
|
||||
|
||||
bool QWindowsSystemTrayIcon::sendTrayMessage(DWORD msg)
|
||||
{
|
||||
NOTIFYICONDATA tnd;
|
||||
|
|
@ -340,6 +362,8 @@ bool QWindowsSystemTrayIcon::sendTrayMessage(DWORD msg)
|
|||
tnd.uID = q_uNOTIFYICONID;
|
||||
tnd.hWnd = m_hwnd;
|
||||
tnd.uFlags = NIF_SHOWTIP;
|
||||
if (msg != NIM_DELETE && !m_visible)
|
||||
setIconVisibility(tnd, m_visible);
|
||||
if (msg == NIM_ADD || msg == NIM_MODIFY)
|
||||
setIconContents(tnd, m_toolTip, m_hIcon);
|
||||
if (!Shell_NotifyIcon(msg, &tnd))
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ private:
|
|||
bool ensureInstalled();
|
||||
void ensureCleanup();
|
||||
bool sendTrayMessage(DWORD msg);
|
||||
bool setIconVisible(bool visible);
|
||||
HICON createIcon(const QIcon &icon);
|
||||
|
||||
QIcon m_icon;
|
||||
|
|
@ -92,6 +93,7 @@ private:
|
|||
HICON m_hIcon = nullptr;
|
||||
mutable QPointer<QWindowsPopupMenu> m_menu;
|
||||
bool m_ignoreNextMouseRelease = false;
|
||||
bool m_visible = false;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
|
|
|||
Loading…
Reference in New Issue