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 @@
1+add --input-touch-emulate-mouse option
DOCS/man/options.rst+7−0
@@ -4281,6 +4281,13 @@ Input · 4280 unmodified lines
42814281 disabled by default in libmpv as well - it should be enabled if you want
42824282 the mpv default key bindings.
42834283
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+
42844291 OSD
42854292 ---
42864293
input/input.c+14−0
@@ -187,6 +187,7 @@ struct input_opts { · 186 unmodified lines
187187 bool test;
188188 bool allow_win_drag;
189189 bool preprocess_wheel;
190+ bool touch_emulate_mouse;
190191 };
191192
192193 const struct m_sub_options input_config = {
@@ -207,6 +208,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines
207208 {"input-vo-keyboard", OPT_BOOL(vo_key_input)},
208209 {"input-media-keys", OPT_BOOL(use_media_keys)},
209210 {"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)},
211+ {"input-touch-emulate-mouse", OPT_BOOL(touch_emulate_mouse)},
210212 #if HAVE_SDL2_GAMEPAD
211213 {"input-gamepad", OPT_BOOL(use_gamepad)},
212214 #endif
@@ -227,6 +229,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines
227229 .vo_key_input = true,
228230 .allow_win_drag = true,
229231 .preprocess_wheel = true,
232+ .touch_emulate_mouse = true,
230233 },
231234 .change_flags = UPDATE_INPUT,
232235 };
@@ -927,6 +930,9 @@ static void update_touch_point(struct input_ctx *ictx, int idx, int id, int x, i · 694 unmodified lines
927930 return;
928931 ictx->touch_points[idx].x = x;
929932 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);
930936 notify_touch_update(ictx);
931937 }
932938
@@ -943,6 +949,11 @@ void mp_input_add_touch_point(struct input_ctx *ictx, int id, int x, int y) · 10 unmodified lines
943949 ictx->num_touch_points, id, x, y);
944950 MP_TARRAY_APPEND(ictx, ictx->touch_points, ictx->num_touch_points,
945951 (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+ }
946957 notify_touch_update(ictx);
947958 }
948959 input_unlock(ictx);
@@ -967,6 +978,9 @@ void mp_input_remove_touch_point(struct input_ctx *ictx, int id) · 18 unmodified lines
967978 if (idx != -1) {
968979 MP_TRACE(ictx, "Touch point %d remove (id %d)\n", idx, id);
969980 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);
970984 notify_touch_update(ictx);
971985 }
972986 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