command: mouse-pos property: add field "hover"

Add a third field: "hover", which is updated from input.c after input
keys MP_KEY_MOUSE_LEAVE and MP_KEY_MOUSE_ENTER - which are typically
sent by the VO.

It's part of mouse-pos and not a new property because it's highly tied
to mouse-pos - it makes x/y invalid while the cursor doesn't hover the
window.

Unike mouse-move, no dummy command was generated, so we add dummy
command in order for observer notification to work even while nothing
is bound.

Like mouse-pos, clients could not detect whether the mouse pointer
hovers the window because the OSC force-binds the MOUSE_LEAVE key, and
now they can using the hover field.

The lua mp.get_mouse_pos() wrapper still returns only x, y because
that's what osc.lua needs. Other clients can simply read the property.
This commit is contained in:
Avi Halachmi (:avih) 2019-12-25 20:52:19 +02:00 committed by avih
parent 0d5055fe93
commit 58004ea2ef
3 changed files with 13 additions and 5 deletions

View File

@ -122,6 +122,7 @@ struct input_ctx {
// Mouse position on the consumer side (as command.c sees it)
int mouse_x, mouse_y;
int mouse_hover; // updated on mouse-enter/leave
char *mouse_section; // last section to receive mouse event
// Mouse position on the producer side (as the VO sees it)
@ -719,8 +720,13 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale,
if (!opts->enable_mouse_movements && MP_KEY_IS_MOUSE(unmod) && !force_mouse)
return;
if (unmod == MP_KEY_MOUSE_LEAVE || unmod == MP_KEY_MOUSE_ENTER) {
ictx->mouse_hover = unmod == MP_KEY_MOUSE_ENTER;
update_mouse_section(ictx);
mp_input_queue_cmd(ictx, get_cmd_from_keys(ictx, NULL, code));
mp_cmd_t *cmd = get_cmd_from_keys(ictx, NULL, code);
if (!cmd) // queue dummy cmd so that mouse-pos can notify observers
cmd = mp_input_parse_cmd(ictx, bstr0("ignore"), "<internal>");
mp_input_queue_cmd(ictx, cmd);
return;
}
double now = mp_time_sec();
@ -962,11 +968,12 @@ mp_cmd_t *mp_input_read_cmd(struct input_ctx *ictx)
return ret;
}
void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y)
void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y, int *hover)
{
input_lock(ictx);
*x = ictx->mouse_x;
*y = ictx->mouse_y;
*hover = ictx->mouse_hover;
input_unlock(ictx);
}

View File

@ -99,7 +99,7 @@ void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y);
// Like mp_input_set_mouse_pos(), but ignore mouse disable option.
void mp_input_set_mouse_pos_artificial(struct input_ctx *ictx, int x, int y);
void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y);
void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y, int *hover);
// Return whether we want/accept mouse input.
bool mp_input_mouse_enabled(struct input_ctx *ictx);

View File

@ -2633,12 +2633,13 @@ static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
case M_PROPERTY_GET: {
struct mpv_node node;
int x, y;
mp_input_get_mouse_pos(mpctx->input, &x, &y);
int x, y, hover;
mp_input_get_mouse_pos(mpctx->input, &x, &y, &hover);
node_init(&node, MPV_FORMAT_NODE_MAP, NULL);
node_map_add_int64(&node, "x", x);
node_map_add_int64(&node, "y", y);
node_map_add_flag(&node, "hover", hover);
*(struct mpv_node *)arg = node;
return M_PROPERTY_OK;