-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implemented a right-click menu for notification icon. #13
Changes from 1 commit
b7675bc
d0baad0
b465f21
16a859f
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 |
---|---|---|
|
@@ -522,6 +522,28 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
#endif | ||
} | ||
break; | ||
case WM_COMMAND: | ||
switch (wParam) | ||
{ | ||
case cNotifMenuCookErrored: | ||
gCookingSystem.QueueErroredCommands(); | ||
break; | ||
// Exit | ||
case cNotifMenuExit: | ||
gApp.RequestExit(); | ||
break; | ||
default: | ||
break; | ||
} | ||
break; | ||
case WM_UNINITMENUPOPUP: | ||
// Reset the stored handle to prevent menu recreation. | ||
if (wParam == reinterpret_cast<UINT_PTR>(gApp.mNotifMenuHmenu)) | ||
{ | ||
gApp.mNotifMenuHmenu = nullptr; | ||
} | ||
break; | ||
|
||
case cNotifCallbackID: | ||
if (lParam == WM_LBUTTONDOWN || // Click on the notif icon | ||
lParam == NIN_BALLOONUSERCLICK) // Click on the notif popup | ||
|
@@ -530,7 +552,26 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) | |
SetFocus(hWnd); // Set the focus on the window. | ||
SetForegroundWindow(hWnd); // And bring it to the foreground. | ||
} | ||
|
||
if (lParam == WM_RBUTTONDOWN && // Right click on notification icon. | ||
gApp.mNotifMenuHmenu == nullptr) // Create the menu only if it's not already open. | ||
{ | ||
// Create the menu where the mouse is placed. | ||
POINT cursorPosition = {}; | ||
BOOL ret = GetCursorPos(&cursorPosition); | ||
gAssert(ret); | ||
|
||
HMENU hMenu = CreatePopupMenu(); | ||
gApp.mNotifMenuHmenu = hMenu; | ||
ret = InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, cNotifMenuCookErrored, L"Cook errored"); | ||
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. In the rest of the code I've tried to use the A version of the Windows functions instead of the WCHAR ones. They should support receiving utf-8 strings thanks to the Just try 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. My bad, I noticed usage of W functions in the same file so I went with the flow. I'm going to change them then, thanks for pointing at it. |
||
gAssert(ret); | ||
ret = InsertMenu(hMenu, -1, MF_BYPOSITION | MF_STRING, cNotifMenuExit, L"Exit"); | ||
gAssert(ret); | ||
ret = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_BOTTOMALIGN, cursorPosition.x, cursorPosition.y, 0, hWnd, nullptr); | ||
gAssert(ret); | ||
} | ||
break; | ||
} | ||
|
||
return ::DefWindowProcW(hWnd, msg, wParam, lParam); | ||
} |
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.
Does that value mean something specific? Or it's just a value that you picked?
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 just used
0x81xx
as a pseudo-namespace where the least significant byte would be the notification menu's command ID. The upper byte would just identifying the context and masking would be easier to think about.Just some forward thinking on the spot, not really useful as is for now. Removing the mask for now.