Skip to content

Commit

Permalink
command: mouse: generate MOUSE_{ENTER,LEAVE} if required
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
avih committed Nov 16, 2020
1 parent 3710c15 commit 24d6961
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 24d6961

Please sign in to comment.