40
40
#include "w32_common.h"
41
41
#include "win32/displayconfig.h"
42
42
#include "win32/droptarget.h"
43
+ #include "win32/menu.h"
43
44
#include "osdep/io.h"
44
45
#include "osdep/threads.h"
45
46
#include "osdep/w32_keyboard.h"
@@ -75,6 +76,8 @@ typedef enum MONITOR_DPI_TYPE {
75
76
#define rect_w (r ) ((r).right - (r).left)
76
77
#define rect_h (r ) ((r).bottom - (r).top)
77
78
79
+ #define WM_SHOWMENU (WM_USER + 1)
80
+
78
81
struct w32_api {
79
82
HRESULT (WINAPI * pGetDpiForMonitor )(HMONITOR , MONITOR_DPI_TYPE , UINT * , UINT * );
80
83
BOOL (WINAPI * pAdjustWindowRectExForDpi )(LPRECT lpRect , DWORD dwStyle , BOOL bMenu , DWORD dwExStyle , UINT dpi );
@@ -101,6 +104,9 @@ struct vo_w32_state {
101
104
HHOOK parent_win_hook ;
102
105
HWINEVENTHOOK parent_evt_hook ;
103
106
107
+ HMENU menu ;
108
+ void * menu_ctx ; // talloc context for MENUITEMINFOW.dwItemData
109
+
104
110
HMONITOR monitor ; // Handle of the current screen
105
111
char * color_profile ; // Path of the current screen's color profile
106
112
@@ -1405,10 +1411,19 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
1405
1411
if (!w32 -> terminate )
1406
1412
mp_input_put_key (w32 -> input_ctx , MP_KEY_CLOSE_WIN );
1407
1413
RevokeDragDrop (w32 -> window );
1414
+ DestroyMenu (w32 -> menu );
1408
1415
w32 -> destroyed = true;
1409
1416
w32 -> window = NULL ;
1410
1417
PostQuitMessage (0 );
1411
1418
break ;
1419
+ case WM_COMMAND : {
1420
+ const char * cmd = mp_win32_get_menu_cmd (w32 -> menu , LOWORD (wParam ));
1421
+ if (cmd ) {
1422
+ mp_cmd_t * cmdt = mp_input_parse_cmd (w32 -> input_ctx , bstr0 (cmd ), "" );
1423
+ mp_input_queue_cmd (w32 -> input_ctx , cmdt );
1424
+ }
1425
+ break ;
1426
+ }
1412
1427
case WM_SYSCOMMAND :
1413
1428
switch (wParam & 0xFFF0 ) {
1414
1429
case SC_SCREENSAVE :
@@ -1592,6 +1607,8 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
1592
1607
// the window is created. Otherwise, fallback to setting alphanumeric mode on
1593
1608
// the first keypress.
1594
1609
SetTimer (w32 -> window , (UINT_PTR )WM_CREATE , 250 , NULL );
1610
+ w32 -> menu = CreatePopupMenu ();
1611
+ w32 -> menu_ctx = talloc_new (w32 );
1595
1612
break ;
1596
1613
case WM_TIMER :
1597
1614
if (wParam == WM_CREATE ) {
@@ -1600,6 +1617,9 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
1600
1617
return 0 ;
1601
1618
}
1602
1619
break ;
1620
+ case WM_SHOWMENU :
1621
+ mp_win32_show_menu (w32 -> menu , w32 -> window );
1622
+ break ;
1603
1623
}
1604
1624
1605
1625
if (message == w32 -> tbtn_created_msg ) {
@@ -2174,6 +2194,12 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
2174
2194
case VOCTRL_BEGIN_DRAGGING :
2175
2195
w32 -> start_dragging = true;
2176
2196
return VO_TRUE ;
2197
+ case VOCTRL_SHOW_MENU :
2198
+ PostMessageW (w32 -> window , WM_SHOWMENU , 0 , 0 );
2199
+ return VO_TRUE ;
2200
+ case VOCTRL_UPDATE_MENU :
2201
+ mp_win32_update_menu (w32 -> menu_ctx , w32 -> menu , (struct mpv_node * )arg );
2202
+ return VO_TRUE ;
2177
2203
}
2178
2204
return VO_NOTIMPL ;
2179
2205
}
0 commit comments