History

command: add touch-pos property

This adds touch-pos property, which contains the information of all current touch points. The property has sub properties: touch-pos/count: the number of current touch points touch-pos/N/x,y: the position of touch point N touch-pos/N/id: unique identifier of the touch point

nanahi committed 2 years ago

Commit 46cca1a1 parent 28a4fb83 files · +59 −2Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/touch-pos.txt +1 −0
  2. DOCS/man/input.rst +30 −1
  3. player/command.c +28 −1
DOCS/interface-changes/touch-pos.txt+1−0
@@ -0,0 +1 @@
1+add `touch-pos` property
DOCS/man/input.rst+30−1
@@ -2800,7 +2800,7 @@ Property list · 2799 unmodified lines
28002800 not being opened yet or not being supported by the VO.
28012801
28022802 ``mouse-pos``
2803− Read-only - last known mouse position, normalizd to OSD dimensions.
2803+ Read-only - last known mouse position, normalized to OSD dimensions.
28042804
28052805 Has the following sub-properties (which can be read as ``MPV_FORMAT_NODE``
28062806 or Lua table with ``mp.get_property_native``):
@@ -2813,6 +2813,35 @@ Property list · 6 unmodified lines
28132813 coordinates should be ignored when this value is false, because the
28142814 video backends update them only when the pointer hovers the window.
28152815
2816+``touch-pos``
2817+ Read-only - last known touch point positions, normalized to OSD dimensions.
2818+
2819+ This has a number of sub-properties. Replace ``N`` with the 0-based touch
2820+ point index. Whenever a new finger touches the screen, a new touch point is
2821+ added to the list of touch points with the smallest unused ``N`` available.
2822+
2823+ ``touch-pos/count``
2824+ Number of active touch points.
2825+
2826+ ``touch-pos/N/x``, ``touch-pos/N/y``
2827+ Position of the Nth touch point.
2828+
2829+ ``touch-pos/N/id``
2830+ Unique identifier of the touch point. This can be used to identify
2831+ individual touch points when their indexes change.
2832+
2833+ When querying the property with the client API using ``MPV_FORMAT_NODE``,
2834+ or with Lua ``mp.get_property_native``, this will return a mpv_node with
2835+ the following contents:
2836+
2837+ ::
2838+
2839+ MPV_FORMAT_NODE_ARRAY
2840+ MPV_FORMAT_NODE_MAP (for each touch point)
2841+ "x" MPV_FORMAT_INT64
2842+ "y" MPV_FORMAT_INT64
2843+ "id" MPV_FORMAT_INT64
2844+
28162845 ``sub-ass-extradata``
28172846 The current ASS subtitle track's extradata. There is no formatting done.
28182847 The extradata is returned as a string as-is. This property is not
player/command.c+28−1
@@ -2897,6 +2897,32 @@ static int mp_property_mouse_pos(void *ctx, struct m_property *prop, · 2896 unmodified lines
28972897 return M_PROPERTY_NOT_IMPLEMENTED;
28982898 }
28992899
2900+static int get_touch_pos(int item, int action, void *arg, void *ctx)
2901+{
2902+ const int **pos = (const int **)ctx;
2903+ struct m_sub_property props[] = {
2904+ {"x", SUB_PROP_INT(pos[0][item])},
2905+ {"y", SUB_PROP_INT(pos[1][item])},
2906+ {"id", SUB_PROP_INT(pos[2][item])},
2907+ {0}
2908+ };
2909+
2910+ int r = m_property_read_sub(props, action, arg);
2911+ return r;
2912+}
2913+
2914+#define MAX_TOUCH_POINTS 10
2915+static int mp_property_touch_pos(void *ctx, struct m_property *prop,
2916+ int action, void *arg)
2917+{
2918+ MPContext *mpctx = ctx;
2919+ int xs[MAX_TOUCH_POINTS], ys[MAX_TOUCH_POINTS], ids[MAX_TOUCH_POINTS];
2920+ int count = mp_input_get_touch_pos(mpctx->input, MAX_TOUCH_POINTS, xs, ys, ids);
2921+ const int *pos[3] = {xs, ys, ids};
2922+ return m_property_read_list(action, arg, MPMIN(MAX_TOUCH_POINTS, count),
2923+ get_touch_pos, (void *)pos);
2924+}
2925+
29002926 /// Video fps (RO)
29012927 static int mp_property_fps(void *ctx, struct m_property *prop,
29022928 int action, void *arg)
@@ -4045,6 +4071,7 @@ static const struct m_property mp_properties_base[] = { · 1142 unmodified lines
40454071 {"osd-ass-cc", mp_property_osd_ass},
40464072
40474073 {"mouse-pos", mp_property_mouse_pos},
4074+ {"touch-pos", mp_property_touch_pos},
40484075
40494076 // Subs
40504077 {"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}},
@@ -4182,7 +4209,7 @@ static const char *const *const mp_event_property_change[] = { · 131 unmodified lines
41824209 E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",
41834210 "playlist-count", "playlist/count", "playlist-current-pos",
41844211 "playlist-playing-pos"),
4185− E(MP_EVENT_INPUT_PROCESSED, "mouse-pos"),
4212+ E(MP_EVENT_INPUT_PROCESSED, "mouse-pos", "touch-pos"),
41864213 E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),
41874214 };
41884215 #undef E

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