mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 09:32:40 +00:00
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.
This commit is contained in:
parent
799d3d4557
commit
a768667956
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user