History

input: add --input-touch-emulate-mouse option

This adds --input-touch-emulate-mouse option, which controls whether to enable legacy touch handling where touch inputs are emulated as mouse inputs. This establishes a primary touch point (the one with the lowest index) as the emulated mouse position, and MBTN_LEFT up/down with the appearance of the first touch point and the disappearance of the last touch point. This fixes some problems with touch handling on Wayland, for example attempting to pinch results in a double click.

nanahi committed 2 years ago

Commit 77809fa1 parent 46cca1a3 files · +22 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/input-touch-emulate-mouse.txt +1 −0
  2. DOCS/man/options.rst +7 −0
  3. input/input.c +14 −0
DOCS/interface-changes/input-touch-emulate-mouse.txt+1−0
@@ -0,0 +1 @@
1add --input-touch-emulate-mouse option
DOCS/man/options.rst+7−0
@@ -4281,6 +4281,13 @@ Input · 4280 unmodified lines
4281 disabled by default in libmpv as well - it should be enabled if you want4281 disabled by default in libmpv as well - it should be enabled if you want
4282 the mpv default key bindings.4282 the mpv default key bindings.
4283 4283
4284``--input-touch-emulate-mouse=<yes|no>``
4285 When multi-touch support is enabled (either required by the platform,
4286 or enabled by ``--native-touch``), emulate mouse move and button presses
4287 for the touch events (default: yes). This is useful for compatibility
4288 for mouse key bindings and scripts which read mouse positions for platforms
4289 which do not support ``--native-touch=no`` (e.g. Wayland).
4290
4284OSD4291OSD
4285---4292---
4286 4293
input/input.c+14−0
@@ -187,6 +187,7 @@ struct input_opts { · 186 unmodified lines
187 bool test;187 bool test;
188 bool allow_win_drag;188 bool allow_win_drag;
189 bool preprocess_wheel;189 bool preprocess_wheel;
190 bool touch_emulate_mouse;
190};191};
191 192
192const struct m_sub_options input_config = {193const struct m_sub_options input_config = {
@@ -207,6 +208,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines
207 {"input-vo-keyboard", OPT_BOOL(vo_key_input)},208 {"input-vo-keyboard", OPT_BOOL(vo_key_input)},
208 {"input-media-keys", OPT_BOOL(use_media_keys)},209 {"input-media-keys", OPT_BOOL(use_media_keys)},
209 {"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)},210 {"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)},
211 {"input-touch-emulate-mouse", OPT_BOOL(touch_emulate_mouse)},
210#if HAVE_SDL2_GAMEPAD212#if HAVE_SDL2_GAMEPAD
211 {"input-gamepad", OPT_BOOL(use_gamepad)},213 {"input-gamepad", OPT_BOOL(use_gamepad)},
212#endif214#endif
@@ -227,6 +229,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines
227 .vo_key_input = true,229 .vo_key_input = true,
228 .allow_win_drag = true,230 .allow_win_drag = true,
229 .preprocess_wheel = true,231 .preprocess_wheel = true,
232 .touch_emulate_mouse = true,
230 },233 },
231 .change_flags = UPDATE_INPUT,234 .change_flags = UPDATE_INPUT,
232};235};
@@ -927,6 +930,9 @@ static void update_touch_point(struct input_ctx *ictx, int idx, int id, int x, i · 694 unmodified lines
927 return;930 return;
928 ictx->touch_points[idx].x = x;931 ictx->touch_points[idx].x = x;
929 ictx->touch_points[idx].y = y;932 ictx->touch_points[idx].y = y;
933 // Emulate mouse input from the primary touch point (the first one added)
934 if (ictx->opts->touch_emulate_mouse && idx == 0)
935 set_mouse_pos(ictx, x, y);
930 notify_touch_update(ictx);936 notify_touch_update(ictx);
931}937}
932 938
@@ -943,6 +949,11 @@ void mp_input_add_touch_point(struct input_ctx *ictx, int id, int x, int y) · 10 unmodified lines
943 ictx->num_touch_points, id, x, y);949 ictx->num_touch_points, id, x, y);
944 MP_TARRAY_APPEND(ictx, ictx->touch_points, ictx->num_touch_points,950 MP_TARRAY_APPEND(ictx, ictx->touch_points, ictx->num_touch_points,
945 (struct touch_point){id, x, y});951 (struct touch_point){id, x, y});
952 // Emulate MBTN_LEFT down if this is the only touch point
953 if (ictx->opts->touch_emulate_mouse && ictx->num_touch_points == 1) {
954 set_mouse_pos(ictx, x, y);
955 feed_key(ictx, MP_MBTN_LEFT | MP_KEY_STATE_DOWN, 1, false);
956 }
946 notify_touch_update(ictx);957 notify_touch_update(ictx);
947 }958 }
948 input_unlock(ictx);959 input_unlock(ictx);
@@ -967,6 +978,9 @@ void mp_input_remove_touch_point(struct input_ctx *ictx, int id) · 18 unmodified lines
967 if (idx != -1) {978 if (idx != -1) {
968 MP_TRACE(ictx, "Touch point %d remove (id %d)\n", idx, id);979 MP_TRACE(ictx, "Touch point %d remove (id %d)\n", idx, id);
969 MP_TARRAY_REMOVE_AT(ictx->touch_points, ictx->num_touch_points, idx);980 MP_TARRAY_REMOVE_AT(ictx->touch_points, ictx->num_touch_points, idx);
981 // Emulate MBTN_LEFT up if there are no touch points left
982 if (ictx->opts->touch_emulate_mouse && ictx->num_touch_points == 0)
983 feed_key(ictx, MP_MBTN_LEFT | MP_KEY_STATE_UP, 1, false);
970 notify_touch_update(ictx);984 notify_touch_update(ictx);
971 }985 }
972 input_unlock(ictx);986 input_unlock(ictx);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t