-
Notifications
You must be signed in to change notification settings - Fork 1
feat : add new feature doubleClick LMB, context menu RMB update : Demo project update, add pseudo animation #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System; | ||
|
|
||
| namespace NotificationIcon.NET | ||
| { | ||
| /// <summary> | ||
| /// Event arguments for tray icon click events (e.g. double-click). | ||
| /// </summary> | ||
| public class TrayIconClickEventArgs : EventArgs | ||
| { | ||
| /// <summary> | ||
| /// The <see cref="NotifyIcon"/> that was clicked. | ||
| /// </summary> | ||
| public NotifyIcon Icon { get; } | ||
|
|
||
| public TrayIconClickEventArgs(NotifyIcon icon) | ||
| { | ||
| Icon = icon; | ||
| } | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at end of file |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,9 @@ private struct Tray | |
| { | ||
| [MarshalAs(UnmanagedType.LPWStr)] | ||
| public string iconPath; | ||
| [MarshalAs(UnmanagedType.LPWStr)] | ||
| public string? tooltip; | ||
| public IntPtr doubleClickCb; | ||
| public IntPtr menus; | ||
| } | ||
|
|
||
|
|
@@ -106,8 +109,10 @@ protected override IHeapAlloc AllocateTray(nint menuItemsPtr) | |
| Tray tray = new() | ||
| { | ||
| iconPath = IconPath, | ||
| tooltip = Tooltip, | ||
| doubleClickCb = GetOrCreateNativeDoubleClickCallback(), | ||
| menus = menuItemsPtr | ||
| }; | ||
| return HeapAlloc<Tray>.Copy(tray); | ||
| } | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline at end of file |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| cmake_minimum_required(VERSION 3.0.0) | ||
|
|
||
| cmake_minimum_required(VERSION 3.5.0) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason to raise the minimum? |
||
| project(notification_icon VERSION 2.0.0) | ||
|
|
||
| add_library(notification_icon SHARED "src/main.c") | ||
| if(UNIX AND NOT APPLE) | ||
| find_package(PkgConfig REQUIRED) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ SOFTWARE. | |||||
| #define UNICODE | ||||||
|
|
||||||
| #include <windows.h> | ||||||
| #include <windowsx.h> | ||||||
| #include <shellapi.h> | ||||||
|
|
||||||
| #define EXPORT __declspec(dllexport) | ||||||
|
|
@@ -40,6 +41,8 @@ static HWND hwnd; | |||||
| static HMENU hmenu = NULL; | ||||||
| static LONG isTrayLoopRunning = 0; | ||||||
|
|
||||||
| static struct tray* _current_tray = NULL; | ||||||
|
|
||||||
| static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { | ||||||
| switch (msg) { | ||||||
| case WM_CLOSE: | ||||||
|
|
@@ -49,11 +52,18 @@ static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARA | |||||
| PostQuitMessage(0); | ||||||
| return 0; | ||||||
| case WM_TRAY_CALLBACK_MESSAGE: | ||||||
| if (lparam == WM_LBUTTONUP || lparam == WM_RBUTTONUP) { | ||||||
| POINT p; | ||||||
| if (!GetCursorPos(&p)) { | ||||||
| break; | ||||||
| { | ||||||
| UINT mouseEvent = LOWORD(lparam); | ||||||
| if (mouseEvent == WM_LBUTTONDBLCLK) { | ||||||
| if (_current_tray != NULL && _current_tray->double_click_cb != NULL) { | ||||||
| _current_tray->double_click_cb(_current_tray); | ||||||
| } | ||||||
| return 0; | ||||||
| } | ||||||
| if (mouseEvent == WM_RBUTTONUP) { | ||||||
| POINT p; | ||||||
| p.x = GET_X_LPARAM(wparam); | ||||||
| p.y = GET_Y_LPARAM(wparam); | ||||||
| SetForegroundWindow(hwnd); | ||||||
| if (hmenu == NULL) { | ||||||
| break; | ||||||
|
|
@@ -69,6 +79,7 @@ static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARA | |||||
| return 0; | ||||||
| } | ||||||
| break; | ||||||
| } | ||||||
| case WM_COMMAND: | ||||||
| { | ||||||
| UINT menuItemId = (UINT)wparam; | ||||||
|
|
@@ -127,6 +138,7 @@ static HMENU _tray_menu(struct tray_menu* m, UINT* id) { | |||||
| } | ||||||
|
|
||||||
| EXPORT void tray_update(struct tray* tray) { | ||||||
| _current_tray = tray; | ||||||
| HMENU prevmenu = hmenu; | ||||||
| UINT id = ID_TRAY_FIRST; | ||||||
| hmenu = _tray_menu(tray->menu, &id); | ||||||
|
|
@@ -137,6 +149,12 @@ EXPORT void tray_update(struct tray* tray) { | |||||
| DestroyIcon(nid.hIcon); | ||||||
| } | ||||||
| nid.hIcon = icon; | ||||||
| nid.uFlags |= NIF_TIP; | ||||||
| if (tray->tooltip != NULL) { | ||||||
| wcscpy_s(nid.szTip, sizeof(nid.szTip) / sizeof(WCHAR), (LPCWSTR)tray->tooltip); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use _TRUNCATE to prevent crashes if the tooltip is too long, and
Suggested change
|
||||||
| } else { | ||||||
| nid.szTip[0] = L'\0'; | ||||||
| } | ||||||
| Shell_NotifyIcon(NIM_MODIFY, &nid); | ||||||
|
|
||||||
| if (prevmenu != NULL) { | ||||||
|
|
@@ -166,10 +184,14 @@ EXPORT INT32 tray_init(struct tray* tray) { | |||||
| nid.cbSize = sizeof(NOTIFYICONDATA); | ||||||
| nid.hWnd = hwnd; | ||||||
| nid.uID = 0; | ||||||
| nid.uFlags = NIF_ICON | NIF_MESSAGE; | ||||||
| nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; | ||||||
| nid.uCallbackMessage = WM_TRAY_CALLBACK_MESSAGE; | ||||||
| Shell_NotifyIcon(NIM_ADD, &nid); | ||||||
|
|
||||||
| // Enable version 4 to receive WM_LBUTTONDBLCLK and extended cursor position in wparam | ||||||
| nid.uVersion = NOTIFYICON_VERSION_4; | ||||||
| Shell_NotifyIcon(NIM_SETVERSION, &nid); | ||||||
|
|
||||||
| tray_update(tray); | ||||||
| return 0; | ||||||
| } | ||||||
|
|
@@ -217,5 +239,4 @@ EXPORT void tray_exit() { | |||||
| while (tray_loop(1) == 0) | ||||||
| { } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the
Createmethod should accept a delegate. Users can simply subscribe to the DoubleClick event themselves using the returnedNotifyIconinstance.