[MPlayer-dev-eng] [PATCH] replace screensaver mess by general "heartbeat" command

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Dec 23 12:12:49 CET 2007


Hello,
attached patch removes all xscreensaver stuff except
XScreenSaverSuspend (and dpms for now) and replaces it with a generic
-heartbeat-cmd commandline option.
If it is set, this command will be executed every 30 seconds during
playback via system().
If someone put something complex in there it will probably cause
playback stutter, but it should not matter fro anything simpler (and
they can always add a '&' at then end then the overhead should be quite
small).
Patch obviously lacks man page part.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 25513)
+++ mplayer.c	(working copy)
@@ -89,6 +90,8 @@
 char * proc_priority=NULL;
 #endif
 
+char *heartbeat_cmd;
+
 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
 
 #ifdef HAVE_RTC
@@ -143,13 +146,7 @@
 #include "get_path.h"
 
 //**************************************************************************//
-//             XScreensaver
 //**************************************************************************//
-
-void xscreensaver_heartbeat(void);
-
-//**************************************************************************//
-//**************************************************************************//
 //             Input media streaming & demultiplexer:
 //**************************************************************************//
 
@@ -3436,12 +3436,14 @@
     current_module="vo_check_events";
     if (vo_config_count) mpctx->video_out->check_events();
 
-#ifdef HAVE_X11
-    if (stop_xscreensaver) {
-	current_module = "stop_xscreensaver";
-	xscreensaver_heartbeat();
+    if (heartbeat_cmd) {
+        static unsigned last_heartbeat;
+        unsigned now = GetTimerMS();
+        if (now - last_heartbeat > 30000) {
+            last_heartbeat = now;
+            system(heartbeat_cmd);
+        }
     }
-#endif
 
     frame_time_remaining = sleep_until_update(&time_frame, &aq_sleep_time);
 
Index: cfg-mplayer.h
===================================================================
--- cfg-mplayer.h	(revision 25513)
+++ cfg-mplayer.h	(working copy)
@@ -204,6 +205,7 @@
 	{"stop_xscreensaver", "Use -stop-xscreensaver instead, options with _ have been obsoleted.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
 	{"fstype", &vo_fstype_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
 #endif
+	{"heartbeat-cmd", &heartbeat_cmd, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"mouseinput", &vo_nomouse_input, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 	{"nomouseinput", &vo_nomouse_input, CONF_TYPE_FLAG,0, 0, 1, NULL},
 
Index: libvo/x11_common.c
===================================================================
--- libvo/x11_common.c	(revision 25513)
+++ libvo/x11_common.c	(working copy)
@@ -75,8 +75,6 @@
 int stop_xscreensaver = 0;
 
 static int dpms_disabled = 0;
-static int timeout_save = 0;
-static int kdescreensaver_was_running = 0;
 
 char *mDisplayName = NULL;
 Display *mDisplay = NULL;
@@ -1594,118 +1592,6 @@
  * 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;
-
-void xscreensaver_heartbeat(void)
-{
-    unsigned int time = GetTimerMS();
-    XEvent ev;
-
-    if (mDisplay && xs_windowid && (time - time_last) > 30000)
-    {
-        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;
-}
-
 static int xss_suspend(Bool suspend)
 {
 #ifndef HAVE_XSS
@@ -1761,30 +1647,6 @@
         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)
@@ -1811,28 +1673,6 @@
         }
     }
 #endif
-    if (!timeout_save)
-    {
-        int interval, prefer_blank, allow_exp;
-        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");
-    }
 }
 
 static XErrorHandler old_handler = NULL;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20071223/12bbf182/attachment.pgp>


More information about the MPlayer-dev-eng mailing list