Skip to content

Commit

Permalink
input: implement VO dragging deadzone
Browse files Browse the repository at this point in the history
This adds the --input-dragging-deadzone option, which adds a deadzone
for the built-in VO deagging. This prevents accidental VO dragging.
  • Loading branch information
na-na-hi authored and kasper93 committed Jun 4, 2024
1 parent a23098b commit a6683ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions DOCS/interface-changes/input-dragging-deadzone.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--input-dragging-deadzone` option
5 changes: 5 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,11 @@ Input
for mouse key bindings and scripts which read mouse positions for platforms
which do not support ``--native-touch=no`` (e.g. Wayland).

``--input-dragging-deadzone=<N>``
Begin the built-in window dragging when the mouse moves outside a deadzone of
``N`` pixels while the mouse button is being held down (default: 3). This only
affects VOs which support the ``begin-vo-dragging`` command.

OSD
---

Expand Down
12 changes: 11 additions & 1 deletion input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct input_ctx {

// VO dragging state
bool dragging_button_down;
int mouse_drag_x, mouse_drag_y;
// Raw mouse position before transform
int mouse_raw_x, mouse_raw_y;

Expand Down Expand Up @@ -180,6 +181,7 @@ struct input_opts {
// Autorepeat config (be aware of mp_input_set_repeat_info())
int ar_delay;
int ar_rate;
int dragging_deadzone;
bool use_alt_gr;
bool use_gamepad;
bool use_media_keys;
Expand Down Expand Up @@ -212,6 +214,7 @@ const struct m_sub_options input_config = {
{"input-media-keys", OPT_BOOL(use_media_keys)},
{"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)},
{"input-touch-emulate-mouse", OPT_BOOL(touch_emulate_mouse)},
{"input-dragging-deadzone", OPT_INT(dragging_deadzone)},
#if HAVE_SDL2_GAMEPAD
{"input-gamepad", OPT_BOOL(use_gamepad)},
#endif
Expand All @@ -224,6 +227,7 @@ const struct m_sub_options input_config = {
.doubleclick_time = 300,
.ar_delay = 200,
.ar_rate = 40,
.dragging_deadzone = 3,
.use_alt_gr = true,
.enable_mouse_movements = true,
.use_media_keys = true,
Expand Down Expand Up @@ -779,6 +783,9 @@ static void feed_key(struct input_ctx *ictx, int code, double scale,
// This is a mouse left botton down event which isn't part of a doubleclick.
// Mark the dragging mouse button down in this case.
ictx->dragging_button_down = true;
// Store the current mouse position for deadzone handling.
ictx->mouse_drag_x = ictx->mouse_raw_x;
ictx->mouse_drag_y = ictx->mouse_raw_y;
}
ictx->last_doubleclick_key_down = code;
ictx->last_doubleclick_time = now;
Expand Down Expand Up @@ -909,7 +916,10 @@ static void set_mouse_pos(struct input_ctx *ictx, int x, int y)
}
}

if (ictx->dragging_button_down) {
bool mouse_outside_dragging_deadzone =
abs(ictx->mouse_raw_x - ictx->mouse_drag_x) >= ictx->opts->dragging_deadzone ||
abs(ictx->mouse_raw_y - ictx->mouse_drag_y) >= ictx->opts->dragging_deadzone;
if (ictx->dragging_button_down && mouse_outside_dragging_deadzone) {
// Begin built-in VO dragging if the mouse moves while the dragging button is down.
ictx->dragging_button_down = false;
mp_cmd_t *drag_cmd = mp_input_parse_cmd(ictx, bstr0("begin-vo-dragging"), "<internal>");
Expand Down

0 comments on commit a6683ea

Please # to comment.