summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-02-26 19:38:01 -0500
committersfan5 <sfan5@live.de>2024-03-01 18:25:12 +0100
commit092f556898ae456ccfe41d77a7bf5b216bc4c0ab (patch)
tree0da2b8350f2b13e5617f53d1c7660b6c514387fa
parentc2129c18f8ecac4133aec59526434ad10f7f6896 (diff)
downloadmpv-092f556898ae456ccfe41d77a7bf5b216bc4c0ab.tar.bz2
mpv-092f556898ae456ccfe41d77a7bf5b216bc4c0ab.tar.xz
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.
-rw-r--r--input/input.c16
-rw-r--r--video/out/w32_common.c7
-rw-r--r--video/out/x11_common.c2
3 files changed, 10 insertions, 15 deletions
diff --git a/input/input.c b/input/input.c
index cafb40085b..804cb4bd00 100644
--- a/input/input.c
+++ b/input/input.c
@@ -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;
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index 49a15b4a78..e00d35c8c4 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -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;
}
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index a77499df65..ccb478b716 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -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)