From b4f63cbbec563e46ef01899b7292e301e961ec1d Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Feb 2016 23:01:15 +0100 Subject: [PATCH] input: ignore --input-cursor for events injected by input commands Apparently useful for window embedding. Fixes #2750. --- DOCS/interface-changes.rst | 2 ++ input/input.c | 28 +++++++++++++++++++++------- input/input.h | 6 ++++++ player/command.c | 12 ++++++------ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 8a38bcc1ce..4217de86fc 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -34,6 +34,8 @@ Interface changes - make "volume" and "mute" properties changeable even if no audio output is active (this gives not-ideal behavior if --softvol=no is used) - add "volume-max" and "mixer-active" properties + - ignore --input-cursor option for events injected by input commands like + "mouse", "keydown", etc. --- mpv 0.15.0 --- - change "yadif" video filter defaults --- mpv 0.14.0 --- diff --git a/input/input.c b/input/input.c index d1c69a9587..ff7dcea67e 100644 --- a/input/input.c +++ b/input/input.c @@ -604,7 +604,8 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale) mp_input_queue_cmd(ictx, cmd); } -static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale) +static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale, + bool force_mouse) { struct input_opts *opts = ictx->opts; @@ -615,7 +616,7 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale) release_down_cmd(ictx, false); return; } - if (!opts->enable_mouse_movements && MP_KEY_IS_MOUSE(unmod)) + if (!opts->enable_mouse_movements && MP_KEY_IS_MOUSE(unmod) && !force_mouse) return; if (unmod == MP_KEY_MOUSE_LEAVE || unmod == MP_KEY_MOUSE_ENTER) { update_mouse_section(ictx); @@ -643,7 +644,14 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale) void mp_input_put_key(struct input_ctx *ictx, int code) { input_lock(ictx); - mp_input_feed_key(ictx, code, 1); + mp_input_feed_key(ictx, code, 1, false); + input_unlock(ictx); +} + +void mp_input_put_key_artificial(struct input_ctx *ictx, int code) +{ + input_lock(ictx); + mp_input_feed_key(ictx, code, 1, true); input_unlock(ictx); } @@ -662,7 +670,7 @@ void mp_input_put_axis(struct input_ctx *ictx, int direction, double value) if (value == 0.0) return; input_lock(ictx); - mp_input_feed_key(ictx, direction, value); + mp_input_feed_key(ictx, direction, value, false); input_unlock(ictx); } @@ -697,13 +705,19 @@ bool mp_input_vo_keyboard_enabled(struct input_ctx *ictx) } void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y) +{ + input_lock(ictx); + if (ictx->opts->enable_mouse_movements) + mp_input_set_mouse_pos_artificial(ictx, x, y); + input_unlock(ictx); +} + +void mp_input_set_mouse_pos_artificial(struct input_ctx *ictx, int x, int y) { input_lock(ictx); MP_DBG(ictx, "mouse move %d/%d\n", x, y); - if ((ictx->mouse_vo_x == x && ictx->mouse_vo_y == y) || - !ictx->opts->enable_mouse_movements) - { + if (ictx->mouse_vo_x == x && ictx->mouse_vo_y == y) { input_unlock(ictx); return; } diff --git a/input/input.h b/input/input.h index 6462555326..41432eb54d 100644 --- a/input/input.h +++ b/input/input.h @@ -132,6 +132,9 @@ void mp_input_src_feed_cmd_text(struct mp_input_src *src, char *buf, size_t len) // with modifiers applied. MP_INPUT_RELEASE_ALL is also a valid value. void mp_input_put_key(struct input_ctx *ictx, int code); +// Like mp_input_put_key(), but ignore mouse disable option for mouse buttons. +void mp_input_put_key_artificial(struct input_ctx *ictx, int code); + // Like mp_input_put_key(), but process all UTF-8 characters in the given // string as key events. void mp_input_put_key_utf8(struct input_ctx *ictx, int mods, struct bstr t); @@ -143,6 +146,9 @@ void mp_input_put_axis(struct input_ctx *ictx, int direction, double value); // Update mouse position (in window coordinates). void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y); +// Like mp_input_set_mouse_pos(), but ignore mouse disable option. +void mp_input_set_mouse_pos_artificial(struct input_ctx *ictx, int x, int y); + void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y); // Return whether we want/accept mouse input. diff --git a/player/command.c b/player/command.c index c95e7d1315..997d60591c 100644 --- a/player/command.c +++ b/player/command.c @@ -5046,7 +5046,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re 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); + mp_input_set_mouse_pos_artificial(mpctx->input, x, y); break; } if (button < 0 || button >= 20) {// invalid button @@ -5055,8 +5055,8 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re } 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); + mp_input_set_mouse_pos_artificial(mpctx->input, x, y); + mp_input_put_key_artificial(mpctx->input, button); break; } @@ -5071,21 +5071,21 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re if (cmd->id == MP_CMD_KEYDOWN) code |= MP_KEY_STATE_DOWN; - mp_input_put_key(mpctx->input, code); + mp_input_put_key_artificial(mpctx->input, code); break; } case MP_CMD_KEYUP: { const char *key_name = cmd->args[0].v.s; if (key_name[0] == '\0') { - mp_input_put_key(mpctx->input, MP_INPUT_RELEASE_ALL); + mp_input_put_key_artificial(mpctx->input, MP_INPUT_RELEASE_ALL); } else { int code = mp_input_get_key_from_name(key_name); if (code < 0) { MP_ERR(mpctx, "%s is not a valid input name.\n", key_name); return -1; } - mp_input_put_key(mpctx->input, code | MP_KEY_STATE_UP); + mp_input_put_key_artificial(mpctx->input, code | MP_KEY_STATE_UP); } break; }