mirror of https://github.com/mpv-player/mpv
input: translate mouse position to OSD space early
Until now, mouse positions were just passed to the core as-is, even if the mouse coordinates didn't map to any useful coordinate space, like OSD coordinates. Lua scripting (used by the OSC, the only current user of mouse input) had to translate mouse coordinates manually to OSD space using mp_get_osd_mouse_pos(). This actually didn't work correctly in cases mouse coordinates didn't map to OSD (like vo_xv): the mouse coordinates the OSC got were correct, but input.c was still expecting "real" mosue coordinates for mouse areas. Fix this by converting to OSD coordinates before passing the mouse position to the core.
This commit is contained in:
parent
3871024ec3
commit
ede652774e
|
@ -85,19 +85,6 @@ static char *format_delay(double time)
|
||||||
return talloc_asprintf(NULL, "%d ms", ROUND(time * 1000));
|
return talloc_asprintf(NULL, "%d ms", ROUND(time * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current mouse position in OSD coordinate space.
|
|
||||||
void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y)
|
|
||||||
{
|
|
||||||
int wx, wy;
|
|
||||||
mp_input_get_mouse_pos(mpctx->input, &wx, &wy);
|
|
||||||
float p[2] = {wx, wy};
|
|
||||||
// Raw window coordinates (VO mouse events) to OSD resolution.
|
|
||||||
if (mpctx->video_out)
|
|
||||||
vo_control(mpctx->video_out, VOCTRL_WINDOW_TO_OSD_COORDS, p);
|
|
||||||
*x = p[0];
|
|
||||||
*y = p[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Property-option bridge.
|
// Property-option bridge.
|
||||||
static int mp_property_generic_option(struct m_option *prop, int action,
|
static int mp_property_generic_option(struct m_option *prop, int action,
|
||||||
void *arg, MPContext *mpctx)
|
void *arg, MPContext *mpctx)
|
||||||
|
|
|
@ -24,8 +24,6 @@ struct mp_cmd;
|
||||||
|
|
||||||
void command_init(struct MPContext *mpctx);
|
void command_init(struct MPContext *mpctx);
|
||||||
|
|
||||||
void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y);
|
|
||||||
|
|
||||||
void run_command(struct MPContext *mpctx, struct mp_cmd *cmd);
|
void run_command(struct MPContext *mpctx, struct mp_cmd *cmd);
|
||||||
char *mp_property_expand_string(struct MPContext *mpctx, const char *str);
|
char *mp_property_expand_string(struct MPContext *mpctx, const char *str);
|
||||||
void property_print_help(void);
|
void property_print_help(void);
|
||||||
|
|
|
@ -457,8 +457,8 @@ static int script_get_screen_size(lua_State *L)
|
||||||
static int script_get_mouse_pos(lua_State *L)
|
static int script_get_mouse_pos(lua_State *L)
|
||||||
{
|
{
|
||||||
struct MPContext *mpctx = get_mpctx(L);
|
struct MPContext *mpctx = get_mpctx(L);
|
||||||
float px, py;
|
int px, py;
|
||||||
mp_get_osd_mouse_pos(mpctx, &px, &py);
|
mp_input_get_mouse_pos(mpctx->input, &px, &py);
|
||||||
double sw, sh;
|
double sw, sh;
|
||||||
osd_object_get_scale_factor(mpctx->osd, mpctx->osd->objs[OSDTYPE_EXTERNAL],
|
osd_object_get_scale_factor(mpctx->osd, mpctx->osd->objs[OSDTYPE_EXTERNAL],
|
||||||
&sw, &sh);
|
&sw, &sh);
|
||||||
|
|
|
@ -601,5 +601,7 @@ void vo_mouse_movement(struct vo *vo, int posx, int posy)
|
||||||
{
|
{
|
||||||
if (!vo->opts->enable_mouse_movements)
|
if (!vo->opts->enable_mouse_movements)
|
||||||
return;
|
return;
|
||||||
mp_input_set_mouse_pos(vo->input_ctx, posx, posy);
|
float p[2] = {posx, posy};
|
||||||
|
vo_control(vo, VOCTRL_WINDOW_TO_OSD_COORDS, p);
|
||||||
|
mp_input_set_mouse_pos(vo->input_ctx, p[0], p[1]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue