changeset 19850:4919b3ce8d5e

report to mplayer with a slave command the coordinates of the pointer reported by x11; rescale coordinates to [0,1]x[0,1] range - patch by Jonas Jermann and me
author nicodvb
date Sat, 16 Sep 2006 15:13:41 +0000
parents f4504b07bdbd
children adfd08588514
files cfg-mplayer.h input/input.c input/input.h libvo/x11_common.c mplayer.c
diffstat 5 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-mplayer.h	Sat Sep 16 14:33:41 2006 +0000
+++ b/cfg-mplayer.h	Sat Sep 16 15:13:41 2006 +0000
@@ -101,6 +101,7 @@
 extern int readPPOpt(void *conf, char *arg);
 extern void revertPPOpt(void *conf, char* opt);
 extern char* pp_help;
+extern int enable_mouse_movements;
 
 m_option_t vd_conf[]={
 	{"help", "Use MPlayer with an appropriate video file instead of live partners to avoid vd.\n", CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
@@ -366,6 +367,8 @@
 	{"key-fifo-size", &key_fifo_size, CONF_TYPE_INT, CONF_RANGE, 2, 65000, NULL},
 	{"noconsolecontrols", &noconsolecontrols, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
 	{"consolecontrols", &noconsolecontrols, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 0, NULL},
+        {"mouse-movements", &enable_mouse_movements, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
+        {"nomouse-movements", &enable_mouse_movements, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 0, NULL},
 
 #define MAIN_CONF
 #include "cfg-common.h"
--- a/input/input.c	Sat Sep 16 14:33:41 2006 +0000
+++ b/input/input.c	Sat Sep 16 15:13:41 2006 +0000
@@ -167,6 +167,7 @@
   { MP_CMD_GET_PROPERTY, "get_property", 1, { {MP_CMD_ARG_STRING, {0}},  {-1,{0}} } },
   
   { MP_CMD_SEEK_CHAPTER, "seek_chapter", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_SET_MOUSE_POS, "set_mouse_pos", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
   
   { 0, NULL, 0, {} }
 };
--- a/input/input.h	Sat Sep 16 14:33:41 2006 +0000
+++ b/input/input.h	Sat Sep 16 15:13:41 2006 +0000
@@ -89,6 +89,7 @@
 #define MP_CMD_RADIO_STEP_CHANNEL 87
 #define MP_CMD_RADIO_SET_CHANNEL 88
 #define MP_CMD_RADIO_SET_FREQ 89
+#define MP_CMD_SET_MOUSE_POS 90
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
--- a/libvo/x11_common.c	Sat Sep 16 14:33:41 2006 +0000
+++ b/libvo/x11_common.c	Sat Sep 16 15:13:41 2006 +0000
@@ -63,6 +63,7 @@
 #define WIN_LAYER_ONTOP                  6
 #define WIN_LAYER_ABOVE_DOCK             10
 
+extern int enable_mouse_movements;
 int fs_layer = WIN_LAYER_ABOVE_DOCK;
 static int orig_layer = 0;
 static int old_gravity = NorthWestGravity;
@@ -1084,6 +1085,13 @@
                 }
                 break;
             case MotionNotify:
+                if(enable_mouse_movements)
+                {
+                    char cmd_str[40];
+                    sprintf(cmd_str,"set_mouse_pos %i %i",Event.xmotion.x, Event.xmotion.y);
+                    mp_input_queue_cmd(mp_input_parse_cmd(cmd_str));
+                }
+
                 if (vo_mouse_autohide)
                 {
                     vo_showcursor(mydisplay, vo_window);
--- a/mplayer.c	Sat Sep 16 14:33:41 2006 +0000
+++ b/mplayer.c	Sat Sep 16 15:13:41 2006 +0000
@@ -86,6 +86,7 @@
 int slave_mode=0;
 int player_idle_mode=0;
 int quiet=0;
+int enable_mouse_movements=0;
 
 #ifdef WIN32
 char * proc_priority=NULL;
@@ -2713,6 +2714,24 @@
     return 1;
 }
 
+static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) {
+    //remove the borders, if any, and rescale to the range [0,1],[0,1]
+    if(vo_fs) {  //we are in full-screen mode
+        if(vo_screenwidth > vo_dwidth) //there are borders along the x axis
+            ix -= (vo_screenwidth - vo_dwidth) / 2;
+        if(vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
+            iy -= (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: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
+        *dx, *dy, vo_screenwidth, vo_screenheight,  vo_dwidth, vo_dheight, vo_fs);
+}
 
 int main(int argc,char* argv[]){
 
@@ -5132,6 +5151,14 @@
         }
         break;
     } break;
+    case MP_CMD_SET_MOUSE_POS: {
+        int button = 0, pointer_x, pointer_y;
+        double dx, dy;
+        pointer_x = cmd->args[0].v.i;
+        pointer_y = cmd->args[1].v.i;
+        rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
+        break;
+    }
 #ifdef USE_DVDNAV
     case MP_CMD_DVDNAV: {
       int button = 0;