summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2020-07-26 14:16:08 +0300
committeravih <avih@users.noreply.github.com>2020-11-16 20:29:58 +0200
commit24d696183364c4b5d36c46551bdb8d8b53f9c699 (patch)
treee20398bfcb9f4ff251ac48160eb030cc899e0984 /player/command.c
parent3710c154d4ce26541b42ce79c99af2016925191b (diff)
downloadmpv-24d696183364c4b5d36c46551bdb8d8b53f9c699.tar.bz2
mpv-24d696183364c4b5d36c46551bdb8d8b53f9c699.tar.xz
command: mouse: generate MOUSE_{ENTER,LEAVE} if required
Previously the mouse command never ended up in enter/leave keypresses for the default section even when logically required, because input.c does not know the area of the default section and relies on something feeding it ENTER/LEAVE presses - which the VO typically does but the mouse command didn't. Now the mouse command feeds it ENTER/LEAVE if required. It's possible to handle it differently and more consistently by: 1. reverting this commit. 2. Updating the default section area whenever the osd dimensions change. 3. Always ignore MOUSE_ENTER keys because the position is not known yet (but MOSE_MOVE typically follows right away). 4. On mouse move: first generate ENTER/LEAVE if required. That would guarantee consistency between mouse position and enter/leave events but could be more sensitive to manage (the default section has "infinite" area which is used to capture any event outside of specific section areas), while this commit keeps consistency same as before and depending on correct external feeding - which we now do better, even if still not optimally (like before, it's still technically possible that a script recieves MOUSE_ENTER and then reads the position before it got updated after the ENTER).
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index ba234ddc9f..066e8be784 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5737,10 +5737,26 @@ static void cmd_mouse(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
+ int pre_key = 0;
const int x = cmd->args[0].v.i, y = cmd->args[1].v.i;
int button = cmd->args[2].v.i;
+
+ if (mpctx->video_out && mpctx->video_out->config_ok) {
+ int oldx, oldy, oldhover;
+ mp_input_get_mouse_pos(mpctx->input, &oldx, &oldy, &oldhover);
+ struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
+
+ // TODO: VOs don't send outside positions. should we abort if outside?
+ int hover = x >= 0 && y >= 0 && x < vo_res.w && y < vo_res.h;
+
+ if (vo_res.w && vo_res.h && hover != oldhover)
+ pre_key = hover ? MP_KEY_MOUSE_ENTER : MP_KEY_MOUSE_LEAVE;
+ }
+
if (button == -1) {// no button
+ if (pre_key)
+ mp_input_put_key_artificial(mpctx->input, pre_key);
mp_input_set_mouse_pos_artificial(mpctx->input, x, y);
return;
}
@@ -5757,6 +5773,8 @@ static void cmd_mouse(void *p)
return;
}
button += dbc ? MP_MBTN_DBL_BASE : MP_MBTN_BASE;
+ if (pre_key)
+ mp_input_put_key_artificial(mpctx->input, pre_key);
mp_input_set_mouse_pos_artificial(mpctx->input, x, y);
mp_input_put_key_artificial(mpctx->input, button);
}