History

win32: make context menu items accessible from the window menu

This makes the context menu items accessible from the window menu, which can be opened by either right-clicking on the title bar or left-clicking on the mpv icon on the title bar.

nanahi committed 2 years ago

Commit 861908c1 parent ee2e1403 files · +30 −4Browse files

Unified · Split

3 files
  1. video/out/w32_common.c +13 −2
  2. video/out/win32/menu.c +16 −1
  3. video/out/win32/menu.h +1 −1
video/out/w32_common.c+13−2
@@ -1532,7 +1532,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 1531 unmodified lines
15321532 }
15331533 break;
15341534 }
1535− case WM_SYSCOMMAND:
1535+ case WM_SYSCOMMAND: {
15361536 switch (wParam & 0xFFF0) {
15371537 case SC_SCREENSAVE:
15381538 case SC_MONITORPOWER:
@@ -1550,7 +1550,18 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 11 unmodified lines
15501550 }
15511551 break;
15521552 }
1553+ // All custom items must use ids of less than 0xF000. The context menu items are
1554+ // also larger than WM_USER, which excludes SCF_ISSECURE.
1555+ if (wParam > WM_USER && wParam < 0xF000) {
1556+ const char *cmd = mp_win32_menu_get_cmd(w32->menu_ctx, LOWORD(wParam));
1557+ if (cmd) {
1558+ mp_cmd_t *cmdt = mp_input_parse_cmd(w32->input_ctx, bstr0(cmd), "");
1559+ mp_input_queue_cmd(w32->input_ctx, cmdt);
1560+ return 0;
1561+ }
1562+ }
15531563 break;
1564+ }
15541565 case WM_NCACTIVATE:
15551566 // Cosmetic to remove blinking window border when initializing window
15561567 if (!w32->opts->border)
@@ -2031,7 +2042,7 @@ static MP_THREAD_VOID gui_thread(void *ptr) · 474 unmodified lines
20312042 goto done;
20322043 }
20332044
2034− w32->menu_ctx = mp_win32_menu_init();
2045+ w32->menu_ctx = mp_win32_menu_init(w32->window);
20352046 update_dark_mode(w32);
20362047 update_corners_pref(w32);
20372048 if (w32->opts->window_affinity)
video/out/win32/menu.c+16−1
@@ -25,6 +25,8 @@ · 24 unmodified lines
2525 #include "menu.h"
2626
2727 struct menu_ctx {
28+ HWND hwnd;
29+ bool updated;
2830 HMENU menu;
2931 void *ta_data; // talloc context for MENUITEMINFOW.dwItemData
3032 };
@@ -178,9 +180,11 @@ static void build_menu(void *talloc_ctx, HMENU hmenu, struct mpv_node *node) · 147 unmodified lines
178180 }
179181 }
180182
181−struct menu_ctx *mp_win32_menu_init(void)
183+struct menu_ctx *mp_win32_menu_init(HWND hwnd)
182184 {
183185 struct menu_ctx *ctx = talloc_ptrtype(NULL, ctx);
186+ ctx->hwnd = hwnd;
187+ ctx->updated = false;
184188 ctx->menu = CreatePopupMenu();
185189 ctx->ta_data = talloc_new(ctx);
186190 return ctx;
@@ -218,6 +222,17 @@ void mp_win32_menu_update(struct menu_ctx *ctx, struct mpv_node *data) · 31 unmodified lines
218222 talloc_free_children(ctx->ta_data);
219223
220224 build_menu(ctx->ta_data, ctx->menu, data);
225+ if (!ctx->updated) {
226+ append_menu(GetSystemMenu(ctx->hwnd, FALSE), MIIM_FTYPE, MFT_SEPARATOR, 0, NULL, NULL, NULL);
227+ append_menu(GetSystemMenu(ctx->hwnd, FALSE), MIIM_STRING | MIIM_SUBMENU, 0, 0,
228+ build_title(ctx->ta_data, "mpv", NULL), ctx->menu, NULL);
229+ ctx->updated = true;
230+ } else if (data->format != MPV_FORMAT_NODE_ARRAY) {
231+ // recreate ctx->menu because it is destroyed here
232+ GetSystemMenu(ctx->hwnd, TRUE);
233+ ctx->menu = CreatePopupMenu();
234+ ctx->updated = false;
235+ }
221236 }
222237
223238 const char* mp_win32_menu_get_cmd(struct menu_ctx *ctx, UINT id)
video/out/win32/menu.h+1−1
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 struct mpv_node;
2424 struct menu_ctx;
2525
26−struct menu_ctx *mp_win32_menu_init(void);
26+struct menu_ctx *mp_win32_menu_init(HWND hwnd);
2727 void mp_win32_menu_uninit(struct menu_ctx *ctx);
2828 void mp_win32_menu_show(struct menu_ctx *ctx, HWND hwnd);
2929 void mp_win32_menu_update(struct menu_ctx *ctx, struct mpv_node *data);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t