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 committed by Kacper Michajłow
parent 28a4fb8e4e
commit 46cca1a67f
3 changed files with 59 additions and 2 deletions

View File

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

View File

@ -2800,7 +2800,7 @@ Property list
not being opened yet or not being supported by the VO. not being opened yet or not being supported by the VO.
``mouse-pos`` ``mouse-pos``
Read-only - last known mouse position, normalizd to OSD dimensions. Read-only - last known mouse position, normalized to OSD dimensions.
Has the following sub-properties (which can be read as ``MPV_FORMAT_NODE`` Has the following sub-properties (which can be read as ``MPV_FORMAT_NODE``
or Lua table with ``mp.get_property_native``): or Lua table with ``mp.get_property_native``):
@ -2813,6 +2813,35 @@ Property list
coordinates should be ignored when this value is false, because the coordinates should be ignored when this value is false, because the
video backends update them only when the pointer hovers the window. video backends update them only when the pointer hovers the window.
``touch-pos``
Read-only - last known touch point positions, normalized 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_INT64
"y" MPV_FORMAT_INT64
"id" MPV_FORMAT_INT64
``sub-ass-extradata`` ``sub-ass-extradata``
The current ASS subtitle track's extradata. There is no formatting done. 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 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; return M_PROPERTY_NOT_IMPLEMENTED;
} }
static int get_touch_pos(int item, int action, void *arg, void *ctx)
{
const int **pos = (const 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);
const int *pos[3] = {xs, ys, ids};
return m_property_read_list(action, arg, MPMIN(MAX_TOUCH_POINTS, count),
get_touch_pos, (void *)pos);
}
/// Video fps (RO) /// Video fps (RO)
static int mp_property_fps(void *ctx, struct m_property *prop, static int mp_property_fps(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
@ -4045,6 +4071,7 @@ static const struct m_property mp_properties_base[] = {
{"osd-ass-cc", mp_property_osd_ass}, {"osd-ass-cc", mp_property_osd_ass},
{"mouse-pos", mp_property_mouse_pos}, {"mouse-pos", mp_property_mouse_pos},
{"touch-pos", mp_property_touch_pos},
// Subs // Subs
{"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}}, {"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}},
@ -4182,7 +4209,7 @@ static const char *const *const mp_event_property_change[] = {
E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",
"playlist-count", "playlist/count", "playlist-current-pos", "playlist-count", "playlist/count", "playlist-current-pos",
"playlist-playing-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"), E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),
}; };
#undef E #undef E