ipc: add enable_event and disable_event commands

This was requested.
This commit is contained in:
wm4 2014-12-24 14:32:02 +01:00
parent 7f36d1532e
commit 51abca8afd
2 changed files with 41 additions and 0 deletions

View File

@ -156,6 +156,14 @@ extra commands can also be used as part of the protocol:
lead to breakages with future mpv releases. Instead, make a feature request,
and ask for a proper event that returns the information you need.
``enable_event``, ``disable_event``
Enables or disables the named event. Mirrors the ``mpv_request_event`` C
API function. If the string ``all`` is used instead of an event name, all
events are enabled or disabled.
By default, most events are enabled, and there is not much use for this
command.
``suspend``
Suspend the mpv main loop. There is a long-winded explanation of this in
the C API function ``mpv_suspend()``. In short, this prevents the player

View File

@ -424,6 +424,39 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent,
} else if (!strcmp("resume", cmd)) {
mpv_resume(arg->client);
rc = MPV_ERROR_SUCCESS;
} else if (!strcmp("enable_event", cmd) ||
!strcmp("disable_event", cmd))
{
bool enable = !strcmp("enable_event", cmd);
if (cmd_node->u.list->num != 2) {
rc = MPV_ERROR_INVALID_PARAMETER;
goto error;
}
if (cmd_node->u.list->values[1].format != MPV_FORMAT_STRING) {
rc = MPV_ERROR_INVALID_PARAMETER;
goto error;
}
char *name = cmd_node->u.list->values[1].u.string;
if (strcmp(name, "all") == 0) {
for (int n = 0; n < 64; n++)
mpv_request_event(arg->client, n, enable);
rc = MPV_ERROR_SUCCESS;
} else {
int event = -1;
for (int n = 0; n < 64; n++) {
const char *evname = mpv_event_name(n);
if (evname && strcmp(evname, name) == 0)
event = n;
}
if (event < 0) {
rc = MPV_ERROR_INVALID_PARAMETER;
goto error;
}
rc = mpv_request_event(arg->client, event, enable);
}
} else {
mpv_node result_node;