Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: implement VO dragging deadzone #14251

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/input-builtin-dragging.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--input-builtin-dragging` option
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
14 changes: 12 additions & 2 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,12 @@ Input
option is applied only during (lib)mpv initialization, and if disabled then it
will not be not possible to enable them later. May be useful to libmpv clients.

``--input-builtin-dragging=<yes|no>``
Enable the built-in window-dragging behavior (default: yes). Setting it to no
disables the built-in dragging behavior. Note that unlike the ``window-dragging``
option, this option only affects VOs which support the ``begin-vo-dragging``
command, and does not disable window dragging initialized with the command.

``--input-cmdlist``
Prints all commands that can be bound to keys.

Expand Down Expand Up @@ -4236,8 +4242,7 @@ Input

``--input-cursor=<yes|no>``
Permit mpv to receive pointer events reported by the video output
driver. Necessary to use the OSC, or to select the buttons in DVD menus.
Support depends on the VO in use.
driver. Necessary to use the OSC. Support depends on the VO in use.

``--input-cursor-passthrough=<yes|no>``
Tell the backend windowing system to allow pointer events to passthrough
Expand Down Expand Up @@ -4304,6 +4309,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>``
kasper93 marked this conversation as resolved.
Show resolved Hide resolved
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
48 changes: 44 additions & 4 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ struct input_ctx {
int last_doubleclick_key_down;
double last_doubleclick_time;

// 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;

// Mouse position on the consumer side (as command.c sees it)
int mouse_x, mouse_y;
int mouse_hover; // updated on mouse-enter/leave
Expand Down Expand Up @@ -175,11 +181,13 @@ 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;
bool default_bindings;
bool builtin_bindings;
bool builtin_dragging;
bool enable_mouse_movements;
bool vo_key_input;
bool test;
Expand All @@ -197,6 +205,7 @@ const struct m_sub_options input_config = {
{"input-cmdlist", OPT_PRINT(mp_print_cmd_list)},
{"input-default-bindings", OPT_BOOL(default_bindings)},
{"input-builtin-bindings", OPT_BOOL(builtin_bindings)},
{"input-builtin-dragging", OPT_BOOL(builtin_dragging)},
{"input-test", OPT_BOOL(test)},
{"input-doubleclick-time", OPT_INT(doubleclick_time),
M_RANGE(0, 1000)},
Expand All @@ -207,6 +216,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 @@ -219,11 +229,13 @@ 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,
.default_bindings = true,
.builtin_bindings = true,
.builtin_dragging = true,
.vo_key_input = true,
.allow_win_drag = true,
.preprocess_wheel = true,
Expand Down Expand Up @@ -733,6 +745,7 @@ static void feed_key(struct input_ctx *ictx, int code, double scale,
if (code == MP_INPUT_RELEASE_ALL) {
MP_TRACE(ictx, "release all\n");
release_down_cmd(ictx, false);
ictx->dragging_button_down = false;
return;
}
if (code == MP_TOUCH_RELEASE_ALL) {
Expand Down Expand Up @@ -771,13 +784,22 @@ static void feed_key(struct input_ctx *ictx, int code, double scale,
1, 1);
} else if (code == MP_MBTN_LEFT) {
// This is a mouse left botton down event which isn't part of a doubleclick.
// Initialize vo dragging in this case.
mp_cmd_t *cmd = mp_input_parse_cmd(ictx, bstr0("begin-vo-dragging"), "<internal>");
queue_cmd(ictx, cmd);
// 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;
}
if (code & MP_KEY_STATE_UP) {
code &= ~MP_KEY_STATE_UP;
if (code == MP_MBTN_LEFT) {
// This is a mouse left botton up event. Mark the dragging mouse button up.
ictx->dragging_button_down = false;
}
}
}

void mp_input_put_key(struct input_ctx *ictx, int code)
Expand Down Expand Up @@ -853,9 +875,11 @@ static void set_mouse_pos(struct input_ctx *ictx, int x, int y)
{
MP_TRACE(ictx, "mouse move %d/%d\n", x, y);

if (ictx->mouse_vo_x == x && ictx->mouse_vo_y == y) {
if (ictx->mouse_raw_x == x && ictx->mouse_raw_y == y) {
return;
}
ictx->mouse_raw_x = x;
ictx->mouse_raw_y = y;

if (ictx->mouse_mangle) {
struct mp_rect *src = &ictx->mouse_src;
Expand Down Expand Up @@ -894,6 +918,22 @@ static void set_mouse_pos(struct input_ctx *ictx, int x, int y)
queue_cmd(ictx, cmd);
}
}

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 &&
ictx->opts->builtin_dragging)
{
// Begin built-in VO dragging if the mouse moves while the dragging button is down.
ictx->dragging_button_down = false;
// Prevent activation of MBTN_LEFT key binding if VO dragging begins.
release_down_cmd(ictx, true);
// Prevent activation of MBTN_LEFT_DBL if VO dragging begins.
ictx->last_doubleclick_time = 0;
mp_cmd_t *drag_cmd = mp_input_parse_cmd(ictx, bstr0("begin-vo-dragging"), "<internal>");
queue_cmd(ictx, drag_cmd);
}
}

void mp_input_set_mouse_pos_artificial(struct input_ctx *ictx, int x, int y)
Expand Down
Loading