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.
Unified · Split
| @@ -1532,7 +1532,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 1531 unmodified lines | ||
| 1532 | 1532 | } |
| 1533 | 1533 | break; |
| 1534 | 1534 | } |
| 1535 | − case WM_SYSCOMMAND: | |
| 1535 | + case WM_SYSCOMMAND: { | |
| 1536 | 1536 | switch (wParam & 0xFFF0) { |
| 1537 | 1537 | case SC_SCREENSAVE: |
| 1538 | 1538 | case SC_MONITORPOWER: |
| @@ -1550,7 +1550,18 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, · 11 unmodified lines | ||
| 1550 | 1550 | } |
| 1551 | 1551 | break; |
| 1552 | 1552 | } |
| 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 | + } | |
| 1553 | 1563 | break; |
| 1564 | + } | |
| 1554 | 1565 | case WM_NCACTIVATE: |
| 1555 | 1566 | // Cosmetic to remove blinking window border when initializing window |
| 1556 | 1567 | if (!w32->opts->border) |
| @@ -2031,7 +2042,7 @@ static MP_THREAD_VOID gui_thread(void *ptr) · 474 unmodified lines | ||
| 2031 | 2042 | goto done; |
| 2032 | 2043 | } |
| 2033 | 2044 | |
| 2034 | − w32->menu_ctx = mp_win32_menu_init(); | |
| 2045 | + w32->menu_ctx = mp_win32_menu_init(w32->window); | |
| 2035 | 2046 | update_dark_mode(w32); |
| 2036 | 2047 | update_corners_pref(w32); |
| 2037 | 2048 | if (w32->opts->window_affinity) |
| @@ -25,6 +25,8 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "menu.h" |
| 26 | 26 | |
| 27 | 27 | struct menu_ctx { |
| 28 | + HWND hwnd; | |
| 29 | + bool updated; | |
| 28 | 30 | HMENU menu; |
| 29 | 31 | void *ta_data; // talloc context for MENUITEMINFOW.dwItemData |
| 30 | 32 | }; |
| @@ -178,9 +180,11 @@ static void build_menu(void *talloc_ctx, HMENU hmenu, struct mpv_node *node) · 147 unmodified lines | ||
| 178 | 180 | } |
| 179 | 181 | } |
| 180 | 182 | |
| 181 | −struct menu_ctx *mp_win32_menu_init(void) | |
| 183 | +struct menu_ctx *mp_win32_menu_init(HWND hwnd) | |
| 182 | 184 | { |
| 183 | 185 | struct menu_ctx *ctx = talloc_ptrtype(NULL, ctx); |
| 186 | + ctx->hwnd = hwnd; | |
| 187 | + ctx->updated = false; | |
| 184 | 188 | ctx->menu = CreatePopupMenu(); |
| 185 | 189 | ctx->ta_data = talloc_new(ctx); |
| 186 | 190 | return ctx; |
| @@ -218,6 +222,17 @@ void mp_win32_menu_update(struct menu_ctx *ctx, struct mpv_node *data) · 31 unmodified lines | ||
| 218 | 222 | talloc_free_children(ctx->ta_data); |
| 219 | 223 | |
| 220 | 224 | 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 | + } | |
| 221 | 236 | } |
| 222 | 237 | |
| 223 | 238 | const char* mp_win32_menu_get_cmd(struct menu_ctx *ctx, UINT id) |
| @@ -23,7 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | struct mpv_node; |
| 24 | 24 | struct menu_ctx; |
| 25 | 25 | |
| 26 | −struct menu_ctx *mp_win32_menu_init(void); | |
| 26 | +struct menu_ctx *mp_win32_menu_init(HWND hwnd); | |
| 27 | 27 | void mp_win32_menu_uninit(struct menu_ctx *ctx); |
| 28 | 28 | void mp_win32_menu_show(struct menu_ctx *ctx, HWND hwnd); |
| 29 | 29 | void mp_win32_menu_update(struct menu_ctx *ctx, struct mpv_node *data); |