summaryrefslogtreecommitdiffstats
path: root/input
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 /input
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.
Diffstat (limited to 'input')
-rw-r--r--input/input.c16
1 files changed, 10 insertions, 6 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;