Skip to content

Commit

Permalink
input: restore ability to combine mouse buttons
Browse files Browse the repository at this point in the history
Key bindings are decided on the "down" event, so if the prefix is not
unique, the first/shortest will be used (e.g. when both "a" and "a-b"
are mapped, "a" will always be chosen).

This also breaks combining multiple mouse buttons. But it seems users
expect it to work, and it's indeed a bit strange that it shouldn't work,
as mouse bindings are emitted on the key "up" event, not "down" (if the
shorter binding didn't emit a command yet, why shouldn't it be
combinable).

Deal with this by clearing the key history when a command is actually
emitted, instead of when a command is decided. This means if both
MOUSE_BTN0 and MOUSE_BTN0-MOUSE_BTN1 are mapped, the sequence of holding
down BTN0 and then BTN1 will redecide the current command. On the other
hand, if BTN0 is released before BTN1 is pressed, the command is
emitted, and the key history is deleted. So the BTN1 press will not
trigger BTN0-BTN1.

For normal keys, nothing should change, because commands are emitted on
the "down" event already, so the key history is always cleared.

Might fix #902.

CC: @mpv-player/stable (if this fix is successful)
  • Loading branch information
wm4 authored and ghedo committed Jul 8, 2014
1 parent 8f5ebdb commit b18c2d9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ static void release_down_cmd(struct input_ctx *ictx, bool drop_current)
if (!drop_current && ictx->current_down_cmd &&
ictx->current_down_cmd->key_up_follows)
{
memset(ictx->key_history, 0, sizeof(ictx->key_history));
ictx->current_down_cmd->key_up_follows = false;
queue_add_tail(&ictx->cmd_queue, ictx->current_down_cmd);
ictx->got_new_events = true;
Expand Down Expand Up @@ -596,15 +597,10 @@ static struct mp_cmd *resolve_key(struct input_ctx *ictx, int code)
{
update_mouse_section(ictx);
struct mp_cmd *cmd = get_cmd_from_keys(ictx, NULL, code);
if (cmd && cmd->id != MP_CMD_IGNORE) {
memset(ictx->key_history, 0, sizeof(ictx->key_history));
if (!should_drop_cmd(ictx, cmd))
return cmd;
talloc_free(cmd);
return NULL;
}
talloc_free(cmd);
key_buf_add(ictx->key_history, code);
if (cmd && cmd->id != MP_CMD_IGNORE && !should_drop_cmd(ictx, cmd))
return cmd;
talloc_free(cmd);
return NULL;
}

Expand Down Expand Up @@ -673,6 +669,8 @@ static void interpret_key(struct input_ctx *ictx, int code, double scale)
return;
}

memset(ictx->key_history, 0, sizeof(ictx->key_history));

cmd->scale = scale;

if (cmd->key_up_follows)
Expand Down

0 comments on commit b18c2d9

Please sign in to comment.