From 58004ea2ef1a14da51b3f46e1c8565c0a3a91ee0 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Wed, 25 Dec 2019 20:52:19 +0200 Subject: 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. --- input/input.c | 11 +++++++++-- input/input.h | 2 +- player/command.c | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/input/input.c b/input/input.c index 1d0c60569c..40abd7d0fa 100644 --- a/input/input.c +++ b/input/input.c @@ -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"), ""); + 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); } diff --git a/input/input.h b/input/input.h index 82e7adc503..5b5e7a99ce 100644 --- a/input/input.h +++ b/input/input.h @@ -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); diff --git a/player/command.c b/player/command.c index ddaf0615f4..ba234ddc9f 100644 --- a/player/command.c +++ b/player/command.c @@ -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; -- cgit v1.2.3