summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-26 02:13:30 +0200
committerwm4 <wm4@nowhere>2013-06-29 22:58:13 +0200
commit5b38a522f17aa24d89b807846c2f76760923351f (patch)
tree44fc0bf235cb6df8e8bdf3a4dc19fdd616553081 /video
parentd4680aaecdc8711a878d973c74e223d49cdf9da3 (diff)
downloadmpv-5b38a522f17aa24d89b807846c2f76760923351f.tar.bz2
mpv-5b38a522f17aa24d89b807846c2f76760923351f.tar.xz
input: handle mouse movement differently
Before this commit, mouse movement events emitted a special command ("set_mouse_pos"), which was specially handled in command.c. This was once special-cased to the dvdnav and menu code, and did nothing after libmenu and dvdnav were removed. Change it so that mouse movement triggers a pseudo-key ("MOUSE_MOVE"), which then can be bound to an arbitrary command. The mouse position is now managed in input.c. A command which actually needs the mouse position can use either mp_input_get_mouse_pos() or mp_get_osd_mouse_pos() to query it. The former returns raw window-space coordinates, while the latter returns coordinates transformed to OSD- space. (Both are the same for most VOs, except vo_xv and vo_x11, which can't render OSD in window-space. These require extra code for mapping mouse position.) As of this commit, there is still nothing that uses mouse movement, so MOUSE_MOVE is mapped to "ignore" to silence warnings when moving the mouse (much like MOUSE_BTN0). Extend the concept of input sections. Allow multiple sections to be active at once, and organize them as stack. Bindings from the top of the stack are preferred to lower ones. Each section has a mouse input section associated, inside which mouse events are associated with the bindings. If the mouse pointer is outside of a section's mouse area, mouse events will be dispatched to an input section lower on the stack of active sections. This is intended for scripting, which is to be added later. Two scripts could occupy different areas of the screen without conflicting with each other. (If it turns out that this mechanism is useless, we'll just remove it again.)
Diffstat (limited to 'video')
-rw-r--r--video/out/vo.c9
-rw-r--r--video/out/vo.h1
-rw-r--r--video/out/vo_x11.c9
-rw-r--r--video/out/vo_xv.c10
4 files changed, 23 insertions, 6 deletions
diff --git a/video/out/vo.c b/video/out/vo.c
index 02d51bf7b6..f3af26273d 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -586,10 +586,7 @@ const char *vo_get_window_title(struct vo *vo)
*/
void vo_mouse_movement(struct vo *vo, int posx, int posy)
{
- char cmd_str[40];
- if (!vo->opts->enable_mouse_movements)
- return;
- snprintf(cmd_str, sizeof(cmd_str), "set_mouse_pos %i %i", posx, posy);
- mp_input_queue_cmd(vo->input_ctx, mp_input_parse_cmd(bstr0(cmd_str), ""));
+ if (!vo->opts->enable_mouse_movements)
+ return;
+ mp_input_set_mouse_pos(vo->input_ctx, posx, posy);
}
-
diff --git a/video/out/vo.h b/video/out/vo.h
index 9f4d2a9060..9300fa37c0 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -71,6 +71,7 @@ enum mp_voctrl {
VOCTRL_GET_DEINTERLACE,
VOCTRL_UPDATE_SCREENINFO,
+ VOCTRL_WINDOW_TO_OSD_COORDS, // float[2] (x/y)
VOCTRL_SET_YUV_COLORSPACE, // struct mp_csp_details*
VOCTRL_GET_YUV_COLORSPACE, // struct mp_csp_details*
diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c
index e7b595ff67..b86f851334 100644
--- a/video/out/vo_x11.c
+++ b/video/out/vo_x11.c
@@ -638,6 +638,7 @@ static int preinit(struct vo *vo, const char *arg)
static int control(struct vo *vo, uint32_t request, void *data)
{
+ struct priv *p = vo->priv;
switch (request) {
case VOCTRL_SET_EQUALIZER:
{
@@ -656,6 +657,14 @@ static int control(struct vo *vo, uint32_t request, void *data)
return VO_TRUE;
case VOCTRL_REDRAW_FRAME:
return redraw_frame(vo);
+ case VOCTRL_WINDOW_TO_OSD_COORDS: {
+ // OSD is rendered into the scaled image
+ float *c = data;
+ struct mp_rect *dst = &p->dst;
+ c[0] = av_clipf(c[0], dst->x0, dst->x1) - dst->x0;
+ c[1] = av_clipf(c[1], dst->y0, dst->y1) - dst->y0;
+ return VO_TRUE;
+ }
case VOCTRL_SCREENSHOT: {
struct voctrl_screenshot_args *args = data;
args->out_image = get_screenshot(vo);
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index fd8901da80..b40add2273 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -944,6 +944,16 @@ static int control(struct vo *vo, uint32_t request, void *data)
args->out_image = get_screenshot(vo);
return true;
}
+ case VOCTRL_WINDOW_TO_OSD_COORDS: {
+ float *c = data;
+ struct mp_rect *src = &ctx->src_rect;
+ struct mp_rect *dst = &ctx->dst_rect;
+ c[0] = av_clipf(c[0], dst->x0, dst->x1) - dst->x0;
+ c[1] = av_clipf(c[1], dst->y0, dst->y1) - dst->y0;
+ c[0] = c[0] / (dst->x1 - dst->x0) * (src->x1 - src->x0) + src->x0;
+ c[1] = c[1] / (dst->y1 - dst->y0) * (src->y1 - src->y0) + src->y0;
+ return VO_TRUE;
+ }
}
int events = 0;
int r = vo_x11_control(vo, &events, request, data);