summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-22 14:48:37 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-24 22:06:17 +0000
commit4aa0bcf5f5266b33faf236e8c914fcf5379abf5b (patch)
tree304ab2a3788369a7275cad6044c5582ad3a26799 /src/plugins
parent19d1fdc5a52039d771d520d0f6c5b98a0e0c4c60 (diff)
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>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/windows/qwindowssystemtrayicon.cpp26
-rw-r--r--src/plugins/platforms/windows/qwindowssystemtrayicon.h2
2 files changed, 27 insertions, 1 deletions
diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp
index 3c27f2914d..2b728338ae 100644
--- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp
+++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp
@@ -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))
diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.h b/src/plugins/platforms/windows/qwindowssystemtrayicon.h
index a8adb9641f..44e1bcc761 100644
--- a/src/plugins/platforms/windows/qwindowssystemtrayicon.h
+++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.h
@@ -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