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
This commit is contained in:
nanahi 2024-04-27 01:59:59 -04:00
parent 9269b0c041
commit 88a63e9742
No known key found for this signature in database
3 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1 @@
add `touch-pos` property

View File

@ -2813,6 +2813,35 @@ Property list
coordinates should be ignored when this value is false, because the
video backends update them only when the pointer hovers the window.
``touch-pos``
Read-only - last known touch point positions, normalizd to OSD dimensions.
This has a number of sub-properties. Replace ``N`` with the 0-based touch
point index. Whenever a new finger touches the screen, a new touch point is
added to the list of touch points with the smallest unused ``N`` available.
``touch-pos/count``
Number of active touch points.
``touch-pos/N/x``, ``touch-pos/N/y``
Position of the Nth touch point.
``touch-pos/N/id``
Unique identifier of the touch point. This can be used to identify
individual touch points when their indexes change.
When querying the property with the client API using ``MPV_FORMAT_NODE``,
or with Lua ``mp.get_property_native``, this will return a mpv_node with
the following contents:
::
MPV_FORMAT_NODE_ARRAY
MPV_FORMAT_NODE_MAP (for each touch point)
"x" MPV_FORMAT_INT
"y" MPV_FORMAT_INT
"id" MPV_FORMAT_INT
``sub-ass-extradata``
The current ASS subtitle track's extradata. There is no formatting done.
The extradata is returned as a string as-is. This property is not

View File

@ -2897,6 +2897,32 @@ static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int get_touch_pos(int item, int action, void *arg, void *ctx)
{
int **pos = (int **)ctx;
struct m_sub_property props[] = {
{"x", SUB_PROP_INT(pos[0][item])},
{"y", SUB_PROP_INT(pos[1][item])},
{"id", SUB_PROP_INT(pos[2][item])},
{0}
};
int r = m_property_read_sub(props, action, arg);
return r;
}
#define MAX_TOUCH_POINTS 10
static int mp_property_touch_pos(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
int xs[MAX_TOUCH_POINTS], ys[MAX_TOUCH_POINTS], ids[MAX_TOUCH_POINTS];
int count = mp_input_get_touch_pos(mpctx->input, MAX_TOUCH_POINTS, xs, ys, ids);
int *pos[3] = {xs, ys, ids};
return m_property_read_list(action, arg, count,
get_touch_pos, (void *)pos);
}
/// Video fps (RO)
static int mp_property_fps(void *ctx, struct m_property *prop,
int action, void *arg)
@ -4031,6 +4057,7 @@ static const struct m_property mp_properties_base[] = {
{"osd-ass-cc", mp_property_osd_ass},
{"mouse-pos", mp_property_mouse_pos},
{"touch-pos", mp_property_touch_pos},
// Subs
{"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}},
@ -4169,7 +4196,7 @@ static const char *const *const mp_event_property_change[] = {
E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",
"playlist-count", "playlist/count", "playlist-current-pos",
"playlist-playing-pos"),
E(MP_EVENT_INPUT_PROCESSED, "mouse-pos"),
E(MP_EVENT_INPUT_PROCESSED, "mouse-pos", "touch-pos"),
E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),
};
#undef E