summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2019-12-25 20:42:44 +0200
committeravih <avih@users.noreply.github.com>2020-11-16 20:29:58 +0200
commita7686679564de584eaa720a6f682c8bd8ad062e6 (patch)
tree81d377e6b29e5ccbd6863bac1451a2beb233859d
parent799d3d4557e3655f9a373b6a7009790d3fa92e70 (diff)
downloadmpv-a7686679564de584eaa720a6f682c8bd8ad062e6.tar.bz2
mpv-a7686679564de584eaa720a6f682c8bd8ad062e6.tar.xz
command: new property: mouse-pos
This is a read-only MPV_NODE value with integer fields: x, y. The values are unmodified from mp_input_get_mouse_pos(...). Observer notification of this property is tied to the INPUT_PROCESSED event, which fires after mouse move even if no command is bound (dummy commands are generated if nothing is bound to ensure that mp_input_get_mouse_pos returns the latest values - see ac927e39 ). This allows clients such as JSON IPC to observe mouse position even while the OSC is enabled - the OSC force-binds mouse move for most of the window area, making it impossible for other clients to bind mouse move without breaking the OSC.
-rw-r--r--player/command.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index c26a0a95c2..ddaf0615f4 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2621,6 +2621,33 @@ static int mp_property_osd_ass(void *ctx, struct m_property *prop,
return m_property_read_sub(props, action, arg);
}
+static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+
+ switch (action) {
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE};
+ return M_PROPERTY_OK;
+
+ case M_PROPERTY_GET: {
+ struct mpv_node node;
+ int x, y;
+ mp_input_get_mouse_pos(mpctx->input, &x, &y);
+
+ node_init(&node, MPV_FORMAT_NODE_MAP, NULL);
+ node_map_add_int64(&node, "x", x);
+ node_map_add_int64(&node, "y", y);
+ *(struct mpv_node *)arg = node;
+
+ return M_PROPERTY_OK;
+ }
+ }
+
+ return M_PROPERTY_NOT_IMPLEMENTED;
+}
+
/// Video fps (RO)
static int mp_property_fps(void *ctx, struct m_property *prop,
int action, void *arg)
@@ -3591,6 +3618,8 @@ static const struct m_property mp_properties_base[] = {
{"osd-sym-cc", mp_property_osd_sym},
{"osd-ass-cc", mp_property_osd_ass},
+ {"mouse-pos", mp_property_mouse_pos},
+
// Subs
{"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}},
{"secondary-sid", property_switch_track,
@@ -3710,6 +3739,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_CORE_IDLE, "core-idle", "eof-reached"),
};
#undef E