mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
vo: different hack for VOs which need to mangle mouse input
Follow up on commit 760548da. Mouse handling is a bit confusing, because
there are at least 3 coordinate systems associated with it, and it
should be cleaned up. But that is hard, so just apply a hack which gets
the currently-annoying issue (VO backends needing access to the VO) out
of the way.
This commit is contained in:
@@ -159,6 +159,9 @@ struct input_ctx {
|
||||
// Unlike mouse_x/y, this can be used to resolve mouse click bindings.
|
||||
int mouse_vo_x, mouse_vo_y;
|
||||
|
||||
bool mouse_mangle, mouse_src_mangle;
|
||||
struct mp_rect mouse_src, mouse_dst;
|
||||
|
||||
bool test;
|
||||
|
||||
bool default_bindings;
|
||||
@@ -738,11 +741,37 @@ void mp_input_put_axis(struct input_ctx *ictx, int direction, double value)
|
||||
input_unlock(ictx);
|
||||
}
|
||||
|
||||
void mp_input_set_mouse_transform(struct input_ctx *ictx, struct mp_rect *dst,
|
||||
struct mp_rect *src)
|
||||
{
|
||||
input_lock(ictx);
|
||||
ictx->mouse_mangle = dst || src;
|
||||
if (ictx->mouse_mangle) {
|
||||
ictx->mouse_dst = *dst;
|
||||
ictx->mouse_src_mangle = !!src;
|
||||
if (ictx->mouse_src_mangle)
|
||||
ictx->mouse_src = *src;
|
||||
}
|
||||
input_unlock(ictx);
|
||||
}
|
||||
|
||||
void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y)
|
||||
{
|
||||
input_lock(ictx);
|
||||
MP_DBG(ictx, "mouse move %d/%d\n", x, y);
|
||||
|
||||
if (ictx->mouse_mangle) {
|
||||
struct mp_rect *src = &ictx->mouse_src;
|
||||
struct mp_rect *dst = &ictx->mouse_dst;
|
||||
x = MPCLAMP(x, dst->x0, dst->x1) - dst->x0;
|
||||
y = MPCLAMP(y, dst->y0, dst->y1) - dst->y0;
|
||||
if (ictx->mouse_src_mangle) {
|
||||
x = x * 1.0 / (dst->x1 - dst->x0) * (src->x1 - src->x0) + src->x0;
|
||||
y = y * 1.0 / (dst->y1 - dst->y0) * (src->y1 - src->y0) + src->y0;
|
||||
}
|
||||
MP_DBG(ictx, "-> %d/%d\n", x, y);
|
||||
}
|
||||
|
||||
ictx->mouse_event_counter++;
|
||||
ictx->mouse_vo_x = x;
|
||||
ictx->mouse_vo_y = y;
|
||||
|
||||
@@ -133,6 +133,13 @@ void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y);
|
||||
|
||||
void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y);
|
||||
|
||||
/* Make mp_input_set_mouse_pos() mangle the mouse coordinates. Hack for certain
|
||||
* VOs. dst=NULL, src=NULL reset it. src can be NULL.
|
||||
*/
|
||||
struct mp_rect;
|
||||
void mp_input_set_mouse_transform(struct input_ctx *ictx, struct mp_rect *dst,
|
||||
struct mp_rect *src);
|
||||
|
||||
// As for the cmd one you usually don't need this function.
|
||||
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user