Compare commits

...

1 Commits

Author SHA1 Message Date
Selva Nair 44288aae4b Change WM_RBUTTONUP to WM_CONTEXTMENU
Required for correct behavior under right click as well as
keyboard event (Shift-F10) for context menu.

The location of the context menu is now taken from the
message as the cursor position may not match when triggered by
keyboard event.

Fixes Github #763

Signed-off-by: Selva Nair <selva.nair@gmail.com>
2025-09-09 09:28:09 +03:00
3 changed files with 9 additions and 6 deletions

4
main.c
View File

@ -513,7 +513,7 @@ HandleCopyDataMessage(const COPYDATASTRUCT *copy_data)
} }
else if (copy_data->dwData == WM_OVPN_RESCAN) else if (copy_data->dwData == WM_OVPN_RESCAN)
{ {
OnNotifyTray(WM_OVPN_RESCAN); OnNotifyTray(0, WM_OVPN_RESCAN);
} }
else else
{ {
@ -653,7 +653,7 @@ WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
case WM_NOTIFYICONTRAY: case WM_NOTIFYICONTRAY:
OnNotifyTray(lParam); /* Manages message from tray */ OnNotifyTray(wParam, lParam); /* Manages message from tray */
break; break;
case WM_COPYDATA: /* custom messages with data from other processes */ case WM_COPYDATA: /* custom messages with data from other processes */

9
tray.c
View File

@ -427,17 +427,20 @@ PositionTrayToolTip(LONG x, LONG y)
* Handle mouse clicks on tray icon * Handle mouse clicks on tray icon
*/ */
void void
OnNotifyTray(LPARAM lParam) OnNotifyTray(WPARAM wParam, LPARAM lParam)
{ {
POINT pt; POINT pt;
/* Use LOWORD(lParam) as HIWORD() contains the icon id if uVersion >= 4 */ /* Use LOWORD(lParam) as HIWORD() contains the icon id if uVersion >= 4 */
switch (LOWORD(lParam)) switch (LOWORD(lParam))
{ {
case WM_RBUTTONUP: case WM_CONTEXTMENU:
RecreatePopupMenus(); RecreatePopupMenus();
/* wParam contains the upper left corner of the anchor point */
pt.x = (int)LOWORD(wParam);
pt.y = (int)HIWORD(wParam);
GetCursorPos(&pt);
SetForegroundWindow(o.hWnd); SetForegroundWindow(o.hWnd);
TrackPopupMenu(hMenu, TPM_RIGHTALIGN, pt.x, pt.y, 0, o.hWnd, NULL); TrackPopupMenu(hMenu, TPM_RIGHTALIGN, pt.x, pt.y, 0, o.hWnd, NULL);
PostMessage(o.hWnd, WM_NULL, 0, 0); PostMessage(o.hWnd, WM_NULL, 0, 0);

2
tray.h
View File

@ -49,7 +49,7 @@ void RecreatePopupMenus(void);
void CreatePopupMenus(); void CreatePopupMenus();
void OnNotifyTray(LPARAM); void OnNotifyTray(WPARAM, LPARAM);
void OnDestroyTray(void); void OnDestroyTray(void);