0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

input: mark a command as canceled if it is explicitly dropped

In certain situations (including but not limited to begin window dragging),
it is desired to cancel the current command completely. However, commands
which have on_updown flag set require the command to be invoked in this
situation. There is currently no way to know if the command is triggered
normally or triggered because it is dropped.

This adds a canceled state to mp_cmd which indicates this.
This commit is contained in:
nanahi 2024-06-06 00:35:37 -04:00 committed by avih
parent a8d95fd51a
commit de97cb0964
2 changed files with 5 additions and 1 deletions

View File

@ -112,6 +112,7 @@ typedef struct mp_cmd {
bool is_mouse_button : 1;
bool repeated : 1;
bool mouse_move : 1;
bool canceled : 1;
int mouse_x, mouse_y;
struct mp_cmd *queue_next;
double scale; // for scaling numeric arguments

View File

@ -551,7 +551,8 @@ static void update_mouse_section(struct input_ctx *ictx)
// If the drop_current parameter is set to true, then don't send the key-up
// command. Unless we've already sent a key-down event, in which case the
// input receiver (the player) must get a key-up event, or it would get stuck
// thinking a key is still held down.
// thinking a key is still held down. In this case, mark the command as
// canceled so that it can be distinguished from a normally triggered command.
static void release_down_cmd(struct input_ctx *ictx, bool drop_current)
{
if (ictx->current_down_cmd && ictx->current_down_cmd->emit_on_up &&
@ -559,6 +560,8 @@ static void release_down_cmd(struct input_ctx *ictx, bool drop_current)
{
memset(ictx->key_history, 0, sizeof(ictx->key_history));
ictx->current_down_cmd->is_up = true;
if (drop_current)
ictx->current_down_cmd->canceled = true;
queue_cmd(ictx, ictx->current_down_cmd);
} else {
talloc_free(ictx->current_down_cmd);