| @@ -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 | |
| 192 | const struct m_sub_options input_config = { | 193 | const 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_GAMEPAD | 212 | #if HAVE_SDL2_GAMEPAD |
| 211 | {"input-gamepad", OPT_BOOL(use_gamepad)}, | 213 | {"input-gamepad", OPT_BOOL(use_gamepad)}, |
| 212 | #endif | 214 | #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); |