Skip to content

Commit

Permalink
fix menu data init
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Feb 5, 2024
1 parent 1b07a84 commit 7920d8a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ static void set_clipboard(const char *text) {

// create HMENU and register window procedure
static void plugin_register(int64_t wid) {
ctx->hmenu = CreatePopupMenu();
ctx->hmenu_ctx = talloc_new(ctx);

ctx->hwnd = (HWND)wid;
ctx->wnd_proc =
(WNDPROC)SetWindowLongPtrW(ctx->hwnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
Expand Down Expand Up @@ -198,6 +195,8 @@ static void handle_client_message(mpv_event *event) {
// create and init plugin context
static void create_plugin_ctx(mpv_handle *mpv) {
ctx = talloc_zero(NULL, plugin_ctx);
ctx->hmenu = CreatePopupMenu();
ctx->hmenu_ctx = talloc_new(ctx);
ctx->mpv = mpv;

ctx->dispatch = mp_dispatch_create(ctx);
Expand All @@ -217,6 +216,10 @@ MPV_EXPORT int mpv_open_cplugin(mpv_handle *handle) {

create_plugin_ctx(handle);

mpv_node node = {0};
if (mpv_get_property(handle, MENU_DATA_PROP, MPV_FORMAT_NODE, &node) >= 0)
update_menu(ctx, &node);

mpv_observe_property(handle, 0, "window-id", MPV_FORMAT_INT64);
mpv_observe_property(handle, 0, MENU_DATA_PROP, MPV_FORMAT_NODE);

Expand Down

0 comments on commit 7920d8a

Please sign in to comment.