diff --git a/DOCS/interface-changes/touch-pos.txt b/DOCS/interface-changes/touch-pos.txt new file mode 100644 index 0000000000..a390d2369f --- /dev/null +++ b/DOCS/interface-changes/touch-pos.txt @@ -0,0 +1 @@ +add `touch-pos` property diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 1a6fa7de13..3e86004c28 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2800,7 +2800,7 @@ Property list not being opened yet or not being supported by the VO. ``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`` 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 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`` 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 diff --git a/player/command.c b/player/command.c index 0673ecb032..9e239520d1 100644 --- a/player/command.c +++ b/player/command.c @@ -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) +{ + 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) static int mp_property_fps(void *ctx, struct m_property *prop, int action, void *arg) @@ -4045,6 +4071,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}}, @@ -4182,7 +4209,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