input, player: new command for mouse event

New command `mouse <x> <y> [<button> [single|double]]` is introduced.
This will update mouse position with given coordinate (`<x>`, `<y>`),
and additionally, send single-click or double-click event if `<button>`
is given.
This commit is contained in:
xylosper 2015-01-24 05:45:13 +09:00 committed by wm4
parent a0a40eb287
commit 4a1a0e98d8
4 changed files with 45 additions and 0 deletions

View File

@ -374,6 +374,23 @@ List of Input Commands
essentially like ``quit``. Useful for the client API: playback can be
stopped without terminating the player.
``mouse <x> <y> [<button> [single|double]]``
Send a mouse event with given coordinate (``<x>``, ``<y>``).
Second argument:
<button>
The button number of clicked mouse button. This should be one of 0-19.
If ``<button>`` is omitted, only the position will be updated.
Third argument:
<single> (default)
The mouse event represents regular single click.
<double>
The mouse event represents double-click.
Input Commands that are Possibly Subject to Change
--------------------------------------------------

View File

@ -186,6 +186,13 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_HOOK_ADD, "hook_add", { ARG_STRING, ARG_INT, ARG_INT } },
{ MP_CMD_HOOK_ACK, "hook_ack", { ARG_STRING } },
{ MP_CMD_MOUSE, "mouse", {
ARG_INT, ARG_INT, // coordinate (x, y)
OARG_INT(-1), // button number
OARG_CHOICE(0, ({"single", 0},
{"double", 1})),
}},
{0}
};

View File

@ -83,6 +83,8 @@ enum mp_command_type {
MP_CMD_DROP_BUFFERS,
MP_CMD_MOUSE,
/// Audio Filter commands
MP_CMD_AF,
MP_CMD_AO_RELOAD,

View File

@ -39,6 +39,7 @@
#include "osdep/timer.h"
#include "common/common.h"
#include "input/input.h"
#include "input/keycodes.h"
#include "stream/stream.h"
#include "demux/demux.h"
#include "demux/stheader.h"
@ -4711,6 +4712,24 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
mp_hook_run(mpctx, cmd->sender, cmd->args[0].v.s);
break;
case MP_CMD_MOUSE: {
const int x = cmd->args[0].v.i, y = cmd->args[1].v.i;
int button = cmd->args[2].v.i;
if (button == -1) {// no button
mp_input_set_mouse_pos(mpctx->input, x, y);
break;
}
if (button < 0 || button >= 20) {// invalid button
MP_ERR(mpctx, "%d is not a valid mouse button number.\n", button);
return -1;
}
const bool dbc = cmd->args[3].v.i;
button += dbc ? MP_MOUSE_BASE_DBL : MP_MOUSE_BASE;
mp_input_set_mouse_pos(mpctx->input, x, y);
mp_input_put_key(mpctx->input, button);
break;
}
default:
MP_VERBOSE(mpctx, "Received unknown cmd %s\n", cmd->name);
return -1;