aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/util/systray.cpp
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/api/util/systray.cpp
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Wasabi/api/util/systray.cpp')
-rw-r--r--Src/Wasabi/api/util/systray.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/Src/Wasabi/api/util/systray.cpp b/Src/Wasabi/api/util/systray.cpp
new file mode 100644
index 00000000..921d21d7
--- /dev/null
+++ b/Src/Wasabi/api/util/systray.cpp
@@ -0,0 +1,93 @@
+#include <precomp.h>
+#ifdef WIN32
+#include <windows.h>
+#include <shellapi.h>
+#endif
+#include "systray.h"
+#include <bfc/assert.h>
+#include <bfc/wasabi_std.h>
+
+Systray::Systray(HWND wnd, int uid, int msg, HICON smallicon)
+{
+ id = uid;
+ hwnd = wnd;
+ message = msg;
+ icon = smallicon;
+ /*int r = */addIcon();
+ // always asserts with desktop with no systray support (litestep, WINE, etc...)
+ // ASSERT(r == TRUE);
+}
+
+Systray::~Systray()
+{
+ /*int r = */deleteIcon();
+ // always asserts with desktop with no systray support (litestep, WINE, etc...)
+ // ASSERT(r == TRUE);
+}
+
+void Systray::setTip(const wchar_t *_tip)
+{
+ tip = _tip;
+ tip.trunc(64);
+ if (!tip.isempty())
+ {
+ /*int r = */setTip();
+ // always asserts with desktop with no systray support (litestep, WINE, etc...)
+ // ASSERT(r == TRUE);
+ }
+}
+
+bool Systray::addIcon()
+{
+#ifdef WIN32
+ NOTIFYICONDATAW tnid = {0};
+ tnid.cbSize = sizeof(NOTIFYICONDATAW);
+ tnid.uID = id;
+ tnid.hWnd = hwnd;
+ tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
+ tnid.uCallbackMessage = message;
+ tnid.hIcon = icon;
+ if (tip)
+ WCSCPYN(tnid.szTip, tip, sizeof(tnid.szTip)/sizeof(wchar_t));
+
+ return !!Shell_NotifyIconW(NIM_ADD, &tnid);
+#else
+ DebugString("portme Systray::addIcon\n");
+ return 1;
+#endif
+}
+
+bool Systray::setTip()
+{
+#ifdef WIN32
+ NOTIFYICONDATAW tnid = {0};
+ tnid.cbSize = sizeof(NOTIFYICONDATAW);
+ tnid.uFlags = NIF_TIP;
+ tnid.uID = id;
+ tnid.hWnd = hwnd;
+ if (tip)
+ WCSCPYN(tnid.szTip, tip, sizeof(tnid.szTip)/sizeof(wchar_t));
+
+ return !!Shell_NotifyIconW(NIM_MODIFY, &tnid);
+#else
+ DebugString("portme Systray::setTip\n");
+ return 1;
+#endif
+}
+
+
+bool Systray::deleteIcon()
+{
+#ifdef WIN32
+ NOTIFYICONDATA tnid = {0};
+ tnid.cbSize = sizeof(NOTIFYICONDATAW);
+ tnid.hWnd = hwnd;
+ tnid.uID = id;
+
+ return !!Shell_NotifyIcon(NIM_DELETE, &tnid);
+#else
+ DebugString("portme Systray::deleteIcon\n");
+ return 1;
+#endif
+}
+