Skip to content

Commit

Permalink
input: mark a command as canceled if it is explicitly dropped
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
na-na-hi committed Jun 6, 2024
1 parent 0509e5b commit 4497fb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions input/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,17 @@ 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 &&
(!drop_current || ictx->current_down_cmd->def->on_updown))
{
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);
Expand Down

0 comments on commit 4497fb7

Please sign in to comment.