summaryrefslogtreecommitdiffstats
path: root/core/command.c
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 /core/command.c
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 'core/command.c')
-rw-r--r--core/command.c49
1 files changed, 10 insertions, 39 deletions
diff --git a/core/command.c b/core/command.c
index 828bf21a08..9e77436a95 100644
--- a/core/command.c
+++ b/core/command.c
@@ -84,37 +84,17 @@ static char *format_delay(double time)
return talloc_asprintf(NULL, "%d ms", ROUND(time * 1000));
}
-static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
- double *dx, double *dy)
+// Get current mouse position in OSD coordinate space.
+void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y)
{
- struct MPOpts *opts = &mpctx->opts;
- struct vo *vo = mpctx->video_out;
- //remove the borders, if any, and rescale to the range [0,1],[0,1]
- if (opts->vo.fs) { //we are in full-screen mode
- if (opts->vo.screenwidth > vo->dwidth)
- // there are borders along the x axis
- ix -= (opts->vo.screenwidth - vo->dwidth) / 2;
- if (opts->vo.screenheight > vo->dheight)
- // there are borders along the y axis (usual way)
- iy -= (opts->vo.screenheight - vo->dheight) / 2;
-
- if (ix < 0 || ix > vo->dwidth) {
- *dx = *dy = -1.0;
- return;
- } //we are on one of the borders
- if (iy < 0 || iy > vo->dheight) {
- *dx = *dy = -1.0;
- return;
- } //we are on one of the borders
- }
-
- *dx = (double) ix / (double) vo->dwidth;
- *dy = (double) iy / (double) vo->dheight;
-
- mp_msg(MSGT_CPLAYER, MSGL_V,
- "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
- *dx, *dy, opts->vo.screenwidth, opts->vo.screenheight, vo->dwidth,
- vo->dheight, opts->vo.fs);
+ 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.
@@ -2432,15 +2412,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
break;
- case MP_CMD_SET_MOUSE_POS: {
- int pointer_x, pointer_y;
- double dx, dy;
- pointer_x = cmd->args[0].v.i;
- pointer_y = cmd->args[1].v.i;
- rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
- break;
- }
-
case MP_CMD_VO_CMDLINE:
if (mpctx->video_out) {
char *s = cmd->args[0].v.s;