| @@ -187,6 +187,7 @@ struct input_opts { · 186 unmodified lines |
| 187 | 187 | bool test; |
| 188 | 188 | bool allow_win_drag; |
| 189 | 189 | bool preprocess_wheel; |
| 190 | + bool touch_emulate_mouse; |
| 190 | 191 | }; |
| 191 | 192 | |
| 192 | 193 | const struct m_sub_options input_config = { |
| @@ -207,6 +208,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines |
| 207 | 208 | {"input-vo-keyboard", OPT_BOOL(vo_key_input)}, |
| 208 | 209 | {"input-media-keys", OPT_BOOL(use_media_keys)}, |
| 209 | 210 | {"input-preprocess-wheel", OPT_BOOL(preprocess_wheel)}, |
| 211 | + {"input-touch-emulate-mouse", OPT_BOOL(touch_emulate_mouse)}, |
| 210 | 212 | #if HAVE_SDL2_GAMEPAD |
| 211 | 213 | {"input-gamepad", OPT_BOOL(use_gamepad)}, |
| 212 | 214 | #endif |
| @@ -227,6 +229,7 @@ const struct m_sub_options input_config = { · 14 unmodified lines |
| 227 | 229 | .vo_key_input = true, |
| 228 | 230 | .allow_win_drag = true, |
| 229 | 231 | .preprocess_wheel = true, |
| 232 | + .touch_emulate_mouse = true, |
| 230 | 233 | }, |
| 231 | 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 | 930 | return; |
| 928 | 931 | ictx->touch_points[idx].x = x; |
| 929 | 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 | 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 | 949 | ictx->num_touch_points, id, x, y); |
| 944 | 950 | MP_TARRAY_APPEND(ictx, ictx->touch_points, ictx->num_touch_points, |
| 945 | 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 | 957 | notify_touch_update(ictx); |
| 947 | 958 | } |
| 948 | 959 | input_unlock(ictx); |
| @@ -967,6 +978,9 @@ void mp_input_remove_touch_point(struct input_ctx *ictx, int id) · 18 unmodified lines |
| 967 | 978 | if (idx != -1) { |
| 968 | 979 | MP_TRACE(ictx, "Touch point %d remove (id %d)\n", idx, id); |
| 969 | 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 | 984 | notify_touch_update(ictx); |
| 971 | 985 | } |
| 972 | 986 | input_unlock(ictx); |