Skip to content
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

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct App

String mMainWindowTitle = "Asset Cooker";
void* mMainWindowHwnd = nullptr;
void* mNotifMenuHmenu = nullptr;
bool mMainWindowIsMinimized = false;
bool mExitRequested = false;
bool mExitReady = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Strings.h"

constexpr uint32 cNotifCallbackID = 0x8001; // ie. WM_APP + 1
constexpr uint32 cNotifMenuExit = 0x8101;
constexpr uint32 cNotifMenuPauseCooking = 0x8102;

enum class NotifType
{
Expand Down
42 changes: 42 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,28 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
#endif
}
break;
case WM_COMMAND:
switch (wParam)
{
case cNotifMenuPauseCooking:
gCookingSystem.SetCookingPaused(!gCookingSystem.IsCookingPaused());
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
Expand All @@ -530,7 +552,27 @@ 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;
bool isCookingPaused = gCookingSystem.IsCookingPaused();
ret = InsertMenuA(hMenu, 0, MF_BYPOSITION | MF_STRING, cNotifMenuPauseCooking, isCookingPaused ? "Resume cooking" : "Pause cooking");
gAssert(ret);
ret = InsertMenuA(hMenu, -1, MF_BYPOSITION | MF_STRING, cNotifMenuExit, "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);
}
Loading