1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-19 14:26:57 +00:00

input: centralize VO dragging

Currently, VO dragging logic is hardcoded into each VO, where a left mouse
button down event unconditionally begins dragging if the VO dragging test
passes. This method is extremely unflexible as the VO has no knowledge of
what is happening in the input system: while begin dragging with the second
click of a doubleclick is undesired, it cannot determine whether a click
is a double click or not because it's determined by the input system.

The better way to do it is to handle it somewhere in the downstream
consumers of the events instead, as they have more information to make
this decision. The input system is the perfect place for this as the logic
for checking doubleclick already exists. So just issue a begin-vo-dragging
command if it detects a left mouse button down which isn't also a
doubleclick in this case, and delete all hardcoded VO dragging logic
in win32, x11, and wayland.

Note that this solution hardcodes left mouse button down for now, but
because the VO dragging is now centralized, it's possible to make more
improvements, such as a deadzone mechanism to fix the conflict with
MBTN_LEFT mouse bind.
This commit is contained in:
nanahi 2024-02-26 19:38:01 -05:00 committed by sfan5
parent c2129c18f8
commit 092f556898
3 changed files with 10 additions and 15 deletions

View File

@ -740,13 +740,17 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale,
if (code & MP_KEY_STATE_DOWN) {
code &= ~MP_KEY_STATE_DOWN;
if (ictx->last_doubleclick_key_down == code &&
now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0)
now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0 &&
code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT)
{
if (code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT) {
now = 0;
interpret_key(ictx, code - MP_MBTN_BASE + MP_MBTN_DBL_BASE,
1, 1);
}
now = 0;
interpret_key(ictx, code - MP_MBTN_BASE + MP_MBTN_DBL_BASE,
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>");
mp_input_queue_cmd(ictx, cmd);
}
ictx->last_doubleclick_key_down = code;
ictx->last_doubleclick_time = now;

View File

@ -498,13 +498,6 @@ static bool handle_mouse_down(struct vo_w32_state *w32, int btn, int x, int y)
{
btn |= mod_state(w32);
mp_input_put_key(w32->input_ctx, btn | MP_KEY_STATE_DOWN);
if (btn == MP_MBTN_LEFT) {
begin_dragging(w32);
// Indicate the message was handled, so DefWindowProc won't be called
return true;
}
SetCapture(w32->window);
return false;
}

View File

@ -1333,8 +1333,6 @@ void vo_x11_check_events(struct vo *vo)
long msg[4] = {XEMBED_REQUEST_FOCUS};
vo_x11_xembed_send_message(x11, msg);
x11->last_button_event = Event;
if (Event.xbutton.button == 1)
vo_x11_begin_dragging(vo);
break;
case ButtonRelease:
if (Event.xbutton.button - 1 >= MP_KEY_MOUSE_BTN_COUNT)