hi

I was testing Adam Tlalka patch from
 http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2007-February/049183.html
as a way to solve Debian bug  #404975 

 I do not like this method as is ....  the fact that the mouse moves by
 itself can be annoying : I was testing it, I tried to click on a icon,
and I ended up clicking another :->

so I prepared another patch, , to be applied on top of Adam's  

that disables this automatic movement if in
 the previous  seconds the user has moved the mouse himself

I prepared a patch for it ; both patches are in attachment (adapted for 1.0 rc1)

but at the same time I am not completely satisfied by it ; 

I have a better idea but I have no time now to explain it

a.

-- 
Andrea Mennucc

"The EULA sounds like it was written by a team of lawyers who want to tell 
me what I can't do, and the GPL sounds like it was written by a human 
being who wants me to know what I can do."
Anonymous,    http://www.securityfocus.com/columnists/420
--- /tmp/x11_common.c	2007-03-04 17:39:30.000000000 +0100
+++ libvo/x11_common.c	2007-03-04 18:21:02.000000000 +0100
@@ -419,7 +419,6 @@ int vo_init(void)
 
     if (vo_depthonscreen)
     {
-        saver_off(mDisplay);
         return 1;               // already called
     }
 
@@ -534,7 +533,6 @@ int vo_init(void)
 
     fstype_dump(vo_fs_type);
 
-    saver_off(mDisplay);
     return 1;
 }
 
@@ -959,7 +957,6 @@ void vo_setwindow(Window w, GC g)
 
 void vo_x11_uninit(void)
 {
-    saver_on(mDisplay);
     if (vo_window != None)
         vo_showcursor(mDisplay, vo_window);
 
@@ -1002,8 +999,20 @@ void vo_x11_uninit(void)
     }
 }
 
+static unsigned int time_last;
 static unsigned int mouse_timer;
 static int mouse_waiting_hide;
+static int mouse_ignore_motion;
+
+static void timer_check(Display *dpy)
+{
+       	time_last = GetTimerMS();
+	if (vo_mouse_autohide) {
+        	vo_showcursor(dpy, vo_window);
+		mouse_timer = time_last;
+	        mouse_waiting_hide = 1;
+        }
+}
 
 int vo_x11_check_events(Display * mydisplay)
 {
@@ -1091,21 +1100,13 @@ int vo_x11_check_events(Display * mydisp
                     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);
-                    mouse_waiting_hide = 1;
-                    mouse_timer = GetTimerMS();
-                }
+ 		if (mouse_ignore_motion)
+ 			mouse_ignore_motion = 0;
+ 		else
+ 			timer_check(mydisplay);
                 break;
             case ButtonPress:
-                if (vo_mouse_autohide)
-                {
-                    vo_showcursor(mydisplay, vo_window);
-                    mouse_waiting_hide = 1;
-                    mouse_timer = GetTimerMS();
-                }
+	        timer_check(mydisplay);
                 // Ignore mouse whell press event
                 if (Event.xbutton.button > 3)
                 {
@@ -1122,12 +1123,7 @@ int vo_x11_check_events(Display * mydisp
                                  1) | MP_KEY_DOWN);
                 break;
             case ButtonRelease:
-                if (vo_mouse_autohide)
-                {
-                    vo_showcursor(mydisplay, vo_window);
-                    mouse_waiting_hide = 1;
-                    mouse_timer = GetTimerMS();
-                }
+		timer_check(mydisplay);
 #ifdef HAVE_NEW_GUI
                 // Ignor mouse button 1 - 3 under gui 
                 if (use_gui && (Event.xbutton.button >= 1)
@@ -1536,228 +1532,20 @@ void vo_x11_ontop(void)
 /*
  * XScreensaver stuff
  */
-
-static int got_badwindow;
-static XErrorHandler old_handler;
-
-static int badwindow_handler(Display * dpy, XErrorEvent * error)
-{
-    if (error->error_code != BadWindow)
-        return (*old_handler) (dpy, error);
-
-    got_badwindow = True;
-    return 0;
-}
-
-static Window find_xscreensaver_window(Display * dpy)
-{
-    int i;
-    Window root = RootWindowOfScreen(DefaultScreenOfDisplay(dpy));
-    Window root2, parent, *kids;
-    Window retval = 0;
-    Atom xs_version;
-    unsigned int nkids = 0;
-
-    xs_version = XInternAtom(dpy, "_SCREENSAVER_VERSION", True);
-
-    if (!(xs_version != None &&
-          XQueryTree(dpy, root, &root2, &parent, &kids, &nkids) &&
-          kids && nkids))
-        return 0;
-
-    old_handler = XSetErrorHandler(badwindow_handler);
-
-    for (i = 0; i < nkids; i++)
-    {
-        Atom type;
-        int format;
-        unsigned long nitems, bytesafter;
-        char *v;
-        int status;
-
-        got_badwindow = False;
-        status =
-            XGetWindowProperty(dpy, kids[i], xs_version, 0, 200, False,
-                               XA_STRING, &type, &format, &nitems,
-                               &bytesafter, (unsigned char **) &v);
-        XSync(dpy, False);
-        if (got_badwindow)
-            status = BadWindow;
-
-        if (status == Success && type != None)
-        {
-            retval = kids[i];
-            break;
-        }
-    }
-    XFree(kids);
-    XSetErrorHandler(old_handler);
-
-    return retval;
-}
-
-static Window xs_windowid = 0;
-static Atom deactivate;
-static Atom screensaver;
-
-static unsigned int time_last;
+static int fake_move_distance = 16;
 
 void xscreensaver_heartbeat(void)
 {
     unsigned int time = GetTimerMS();
     XEvent ev;
 
-    if (mDisplay && xs_windowid && (time - time_last) > 30000)
+    if (mDisplay && (time - time_last) > 10000)
     {
         time_last = time;
-
-        ev.xany.type = ClientMessage;
-        ev.xclient.display = mDisplay;
-        ev.xclient.window = xs_windowid;
-        ev.xclient.message_type = screensaver;
-        ev.xclient.format = 32;
-        memset(&ev.xclient.data, 0, sizeof(ev.xclient.data));
-        ev.xclient.data.l[0] = (long) deactivate;
-
-        mp_msg(MSGT_VO, MSGL_DBG2, "Pinging xscreensaver.\n");
-        old_handler = XSetErrorHandler(badwindow_handler);
-        XSendEvent(mDisplay, xs_windowid, False, 0L, &ev);
-        XSync(mDisplay, False);
-        XSetErrorHandler(old_handler);        
-    }
-}
-
-static void xscreensaver_disable(Display * dpy)
-{
-    mp_msg(MSGT_VO, MSGL_DBG2, "xscreensaver_disable()\n");
-
-    xs_windowid = find_xscreensaver_window(dpy);
-    if (!xs_windowid)
-    {
-        mp_msg(MSGT_VO, MSGL_INFO, MSGTR_CouldNotFindXScreenSaver);
-        return;
-    }
-    mp_msg(MSGT_VO, MSGL_INFO,
-           "xscreensaver_disable: xscreensaver wid=%ld.\n", xs_windowid);
-
-    deactivate = XInternAtom(dpy, "DEACTIVATE", False);
-    screensaver = XInternAtom(dpy, "SCREENSAVER", False);
-}
-
-static void xscreensaver_enable(void)
-{
-    xs_windowid = 0;
-}
-
-/*
- * End of XScreensaver stuff
- */
-
-void saver_on(Display * mDisplay)
-{
-
-#ifdef HAVE_XDPMS
-    int nothing;
-
-    if (dpms_disabled)
-    {
-        if (DPMSQueryExtension(mDisplay, &nothing, &nothing))
-        {
-            if (!DPMSEnable(mDisplay))
-            {                   // restoring power saving settings
-                mp_msg(MSGT_VO, MSGL_WARN, "DPMS not available?\n");
-            } else
-            {
-                // DPMS does not seem to be enabled unless we call DPMSInfo
-                BOOL onoff;
-                CARD16 state;
-
-                DPMSForceLevel(mDisplay, DPMSModeOn);
-                DPMSInfo(mDisplay, &state, &onoff);
-                if (onoff)
-                {
-                    mp_msg(MSGT_VO, MSGL_V,
-                           "Successfully enabled DPMS\n");
-                } else
-                {
-                    mp_msg(MSGT_VO, MSGL_WARN, "Could not enable DPMS\n");
-                }
-            }
-        }
-        dpms_disabled = 0;
-    }
-#endif
-
-    if (timeout_save)
-    {
-        int dummy, interval, prefer_blank, allow_exp;
-
-        XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank,
-                        &allow_exp);
-        XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank,
-                        allow_exp);
-        XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
-                        &allow_exp);
-        timeout_save = 0;
-    }
-
-    if (stop_xscreensaver)
-        xscreensaver_enable();
-    if (kdescreensaver_was_running && stop_xscreensaver)
-    {
-        system
-            ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
-        kdescreensaver_was_running = 0;
-    }
-
-
-}
-
-void saver_off(Display * mDisplay)
-{
-
-    int interval, prefer_blank, allow_exp;
-
-#ifdef HAVE_XDPMS
-    int nothing;
-
-    if (DPMSQueryExtension(mDisplay, &nothing, &nothing))
-    {
-        BOOL onoff;
-        CARD16 state;
-
-        DPMSInfo(mDisplay, &state, &onoff);
-        if (onoff)
-        {
-            Status stat;
-
-            mp_msg(MSGT_VO, MSGL_V, "Disabling DPMS\n");
-            dpms_disabled = 1;
-            stat = DPMSDisable(mDisplay);       // monitor powersave off
-            mp_msg(MSGT_VO, MSGL_V, "DPMSDisable stat: %d\n", stat);
-        }
-    }
-#endif
-    if (!timeout_save)
-    {
-        XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
-                        &allow_exp);
-        if (timeout_save)
-            XSetScreenSaver(mDisplay, 0, interval, prefer_blank,
-                            allow_exp);
-    }
-    // turning off screensaver
-    if (stop_xscreensaver)
-        xscreensaver_disable(mDisplay);
-    if (stop_xscreensaver && !kdescreensaver_was_running)
-    {
-        kdescreensaver_was_running =
-            (system
-             ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
-             == 0);
-        if (kdescreensaver_was_running)
-            system
-                ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
+	mouse_ignore_motion = 1;
+	XWarpPointer(mDisplay, None, None, 0, 0, 0, 0, fake_move_distance, 0);
+	fake_move_distance = -fake_move_distance;
+        mp_msg(MSGT_VO, MSGL_DBG2, "Moving mouse pointer to avoid screensaver.\n");
     }
 }
 
--- /home/debdev/mplayer/x11_common.c	2007-03-07 13:41:27.000000000 +0100
+++ libvo/x11_common.c	2007-03-07 17:42:05.000000000 +0100
@@ -999,10 +999,10 @@ void vo_x11_uninit(void)
     }
 }
 
-static unsigned int time_last;
-static unsigned int mouse_timer;
-static int mouse_waiting_hide;
-static int mouse_ignore_motion;
+static unsigned int time_last=0;
+static unsigned int mouse_timer=0;
+static int mouse_waiting_hide=0;
+static int mouse_ignore_motion=0;
 
 static void timer_check(Display *dpy)
 {
@@ -1538,11 +1538,34 @@ void xscreensaver_heartbeat(void)
 {
     unsigned int time = GetTimerMS();
     XEvent ev;
+    static unsigned int time_last_query = 0 ; 
 
-    if (mDisplay && (time - time_last) > 10000)
+    if (mDisplay && (time - time_last_query) > 1000)
     {
+      static int old_root_x_return=0, old_root_y_return=0;
+      Window root_return, child_return;
+      int win_x_return,  win_y_return, new_root_x_return, new_root_y_return;
+      unsigned int mask_return;
+#define SQR(A) ((A)*(A))
+
+      time_last_query=time;
+
+      if( XQueryPointer(mDisplay, mRootWin, & root_return, &child_return,
+			& new_root_x_return, & new_root_y_return, 
+			& win_x_return,& win_y_return, &mask_return) ) {
+	if ( SQR(old_root_x_return- new_root_x_return) 
+	     + SQR(old_root_y_return - new_root_y_return) > 16 ) {
         time_last = time;
+	}
+
+	old_root_x_return = new_root_x_return;
+	old_root_y_return = new_root_y_return;	  
+      }
+    }
+    if (mDisplay && (time - time_last) > 5000) 
+     {
 	mouse_ignore_motion = 1;
+	time_last = time;
 	XWarpPointer(mDisplay, None, None, 0, 0, 0, 0, fake_move_distance, 0);
 	fake_move_distance = -fake_move_distance;
         mp_msg(MSGT_VO, MSGL_DBG2, "Moving mouse pointer to avoid screensaver.\n");

Reply via email to