| @@ -123,7 +123,6 @@ struct hook_handler { · 122 unmodified lines |
| 123 | uint64_t user_id; // user-chosen ID | 123 | uint64_t user_id; // user-chosen ID |
| 124 | int priority; // priority for global hook order | 124 | int priority; // priority for global hook order |
| 125 | int64_t seq; // unique ID, != 0, also for fixed order on equal priorities | 125 | int64_t seq; // unique ID, != 0, also for fixed order on equal priorities |
| 126 | bool legacy; // old cmd based hook API | | |
| 127 | bool active; // hook is currently in progress (only 1 at a time for now) | 126 | bool active; // hook is currently in progress (only 1 at a time for now) |
| 128 | }; | 127 | }; |
| 129 | | 128 | |
| @@ -178,29 +177,13 @@ static int invoke_hook_handler(struct MPContext *mpctx, struct hook_handler *h) · 48 unmodified lines |
| 178 | h->active = true; | 177 | h->active = true; |
| 179 | | 178 | |
| 180 | uint64_t reply_id = 0; | 179 | uint64_t reply_id = 0; |
| 181 | void *data; | 180 | mpv_event_hook *m = talloc_ptrtype(NULL, m); |
| 182 | int msg; | 181 | *m = (mpv_event_hook){ |
| 183 | if (h->legacy) { | 182 | .name = talloc_strdup(m, h->type), |
| 184 | mpv_event_client_message *m = talloc_ptrtype(NULL, m); | 183 | .id = h->seq, |
| 185 | *m = (mpv_event_client_message){0}; | 184 | }, |
| 186 | MP_TARRAY_APPEND(m, m->args, m->num_args, "hook_run"); | 185 | reply_id = h->user_id; |
| 187 | MP_TARRAY_APPEND(m, m->args, m->num_args, | 186 | int r = mp_client_send_event(mpctx, h->client, reply_id, MPV_EVENT_HOOK, m); |
| 188 | talloc_asprintf(m, "%llu", (long long)h->user_id)); | | |
| 189 | MP_TARRAY_APPEND(m, m->args, m->num_args, | | |
| 190 | talloc_asprintf(m, "%llu", (long long)h->seq)); | | |
| 191 | data = m; | | |
| 192 | msg = MPV_EVENT_CLIENT_MESSAGE; | | |
| 193 | } else { | | |
| 194 | mpv_event_hook *m = talloc_ptrtype(NULL, m); | | |
| 195 | *m = (mpv_event_hook){ | | |
| 196 | .name = talloc_strdup(m, h->type), | | |
| 197 | .id = h->seq, | | |
| 198 | }, | | |
| 199 | reply_id = h->user_id; | | |
| 200 | data = m; | | |
| 201 | msg = MPV_EVENT_HOOK; | | |
| 202 | } | | |
| 203 | int r = mp_client_send_event(mpctx, h->client, reply_id, msg, data); | | |
| 204 | if (r < 0) { | 187 | if (r < 0) { |
| 205 | MP_WARN(mpctx, "Sending hook command failed. Removing hook.\n"); | 188 | MP_WARN(mpctx, "Sending hook command failed. Removing hook.\n"); |
| 206 | hook_remove(mpctx, h); | 189 | hook_remove(mpctx, h); |
| @@ -261,11 +244,8 @@ static int compare_hook(const void *pa, const void *pb) · 54 unmodified lines |
| 261 | } | 244 | } |
| 262 | | 245 | |
| 263 | void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name, | 246 | void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name, |
| 264 | uint64_t user_id, int pri, bool legacy) | 247 | uint64_t user_id, int pri) |
| 265 | { | 248 | { |
| 266 | if (legacy) | | |
| 267 | MP_WARN(mpctx, "The old hook API is deprecated! Use the libmpv API.\n"); | | |
| 268 | | | |
| 269 | struct command_ctx *cmd = mpctx->command_ctx; | 249 | struct command_ctx *cmd = mpctx->command_ctx; |
| 270 | struct hook_handler *h = talloc_ptrtype(cmd, h); | 250 | struct hook_handler *h = talloc_ptrtype(cmd, h); |
| 271 | int64_t seq = ++cmd->hook_seq; | 251 | int64_t seq = ++cmd->hook_seq; |
| @@ -275,7 +255,6 @@ void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name, · 3 unmodified lines |
| 275 | .user_id = user_id, | 255 | .user_id = user_id, |
| 276 | .priority = pri, | 256 | .priority = pri, |
| 277 | .seq = seq, | 257 | .seq = seq, |
| 278 | .legacy = legacy, | | |
| 279 | }; | 258 | }; |
| 280 | MP_TARRAY_APPEND(cmd, cmd->hooks, cmd->num_hooks, h); | 259 | MP_TARRAY_APPEND(cmd, cmd->hooks, cmd->num_hooks, h); |
| 281 | qsort(cmd->hooks, cmd->num_hooks, sizeof(cmd->hooks[0]), compare_hook); | 260 | qsort(cmd->hooks, cmd->num_hooks, sizeof(cmd->hooks[0]), compare_hook); |
| @@ -5411,33 +5390,6 @@ static void cmd_write_watch_later_config(void *p) · 5129 unmodified lines |
| 5411 | mp_write_watch_later_conf(mpctx); | 5390 | mp_write_watch_later_conf(mpctx); |
| 5412 | } | 5391 | } |
| 5413 | | 5392 | |
| 5414 | static void cmd_hook_add(void *p) | | |
| 5415 | { | | |
| 5416 | struct mp_cmd_ctx *cmd = p; | | |
| 5417 | struct MPContext *mpctx = cmd->mpctx; | | |
| 5418 | | | |
| 5419 | if (!cmd->cmd->sender) { | | |
| 5420 | MP_ERR(mpctx, "Can be used from client API only.\n"); | | |
| 5421 | cmd->success = false; | | |
| 5422 | return; | | |
| 5423 | } | | |
| 5424 | mp_hook_add(mpctx, cmd->cmd->sender, cmd->args[0].v.s, cmd->args[1].v.i, | | |
| 5425 | cmd->args[2].v.i, true); | | |
| 5426 | } | | |
| 5427 | | | |
| 5428 | static void cmd_hook_ack(void *p) | | |
| 5429 | { | | |
| 5430 | struct mp_cmd_ctx *cmd = p; | | |
| 5431 | struct MPContext *mpctx = cmd->mpctx; | | |
| 5432 | | | |
| 5433 | if (!cmd->cmd->sender) { | | |
| 5434 | MP_ERR(mpctx, "Can be used from client API only.\n"); | | |
| 5435 | cmd->success = false; | | |
| 5436 | return; | | |
| 5437 | } | | |
| 5438 | mp_hook_continue(mpctx, cmd->cmd->sender, cmd->args[0].v.i); | | |
| 5439 | } | | |
| 5440 | | | |
| 5441 | static void cmd_mouse(void *p) | 5393 | static void cmd_mouse(void *p) |
| 5442 | { | 5394 | { |
| 5443 | struct mp_cmd_ctx *cmd = p; | 5395 | struct mp_cmd_ctx *cmd = p; |
| @@ -5950,11 +5902,6 @@ const struct mp_cmd_def mp_cmds[] = { · 506 unmodified lines |
| 5950 | | 5902 | |
| 5951 | { "write-watch-later-config", cmd_write_watch_later_config }, | 5903 | { "write-watch-later-config", cmd_write_watch_later_config }, |
| 5952 | | 5904 | |
| 5953 | { "hook-add", cmd_hook_add, { OPT_STRING("arg0", v.s, 0), | | |
| 5954 | OPT_INT("arg1", v.i, 0), | | |
| 5955 | OPT_INT("arg2", v.i, 0) }}, | | |
| 5956 | { "hook-ack", cmd_hook_ack, { OPT_INT("arg0", v.i, 0) }}, | | |
| 5957 | | | |
| 5958 | { "mouse", cmd_mouse, { OPT_INT("x", v.i, 0), | 5905 | { "mouse", cmd_mouse, { OPT_INT("x", v.i, 0), |
| 5959 | OPT_INT("y", v.i, 0), | 5906 | OPT_INT("y", v.i, 0), |
| 5960 | OPT_INT("button", v.i, 0, OPTDEF_INT(-1)), | 5907 | OPT_INT("button", v.i, 0, OPTDEF_INT(-1)), |