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 1 commit
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
5 changes: 4 additions & 1 deletion src/CookingSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ struct CookingSystem : NoCopy
CookingLogEntry& AllocateCookingLogEntry(CookingCommandID inCommandID);

bool mSlowMode = false; // Slows down cooking, for debugging.

// Experimental, used by main.cpp
void QueueErroredCommands();

private:
friend struct CookingCommand;
friend void gDrawCookingQueue();
Expand All @@ -346,7 +350,6 @@ struct CookingSystem : NoCopy
void AddTimeOut(CookingLogEntry* inLogEntry);
void TimeOutUpdateThread(std::stop_token inStopToken);
void QueueDirtyCommands();
void QueueErroredCommands();

VMemArray<CookingRule> mRules = { 1024ull * 1024, 4096 };
StringPool mStringPool = { 64ull * 1024 };
Expand Down
5 changes: 5 additions & 0 deletions src/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include "Strings.h"

constexpr uint32 cNotifCallbackID = 0x8001; // ie. WM_APP + 1
// Not used yet but could be used as an ID mask to dispatch events.
[[maybe_unused]]
constexpr uint32 cNotifMenuId = 0x8100;
Copy link
Owner

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?

Copy link
Contributor Author

@Eiyeron Eiyeron Dec 3, 2024

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.

constexpr uint32 cNotifMenuExit = 0x8101;
constexpr uint32 cNotifMenuCookErrored = 0x8102;

enum class NotifType
{
Expand Down
41 changes: 41 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 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
Expand All @@ -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");
Copy link
Owner

@jlaumon jlaumon Dec 3, 2024

Choose a reason for hiding this comment

The 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 enable_utf8.manifest (but does need checking, because some of then don't work!)

Just try InsertMenuA(..., (const char*)u8"Cook errored 😭") and see what happens :D

Copy link
Contributor Author

@Eiyeron Eiyeron Dec 3, 2024

Choose a reason for hiding this comment

The 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);
}
Loading