[MPlayer-dev-eng] [PATCH] Use XScreenSaverSuspend if supported

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Thu Dec 20 14:22:22 CET 2007


Hello,
On Tue, Apr 11, 2006 at 11:06:00PM +0300, Ismail Donmez wrote:
> Salı 11 Nisan 2006 00:46 tarihinde, Uoti Urpala şunları yazmıştı: 
> > On Mon, 2006-04-10 at 20:49 +0300, Ismail Donmez wrote:
> > > Simpler version without XOpenDisplay , suggested by fredrik.
> >
> > This also removes the runtime checks that were in the original. Doesn't
> > this mean that if compiled with support for XScreenSaverSuspend, MPlayer
> > would fail to disable screensaver when running under an older X server?
> 
> Here is a better(best? ;) patch which checks if the extension is supported. 
> Check is done in vo_init hence should be better than checking everytime 
> calling saver_on/off .
> 
> Please review/comment.

Here is an updated version (actually it is basically new code). For
simplicity I moved the check so it is done on every saver_on/off, it
should not matter performance-wise.
I also added a QueryExtension because the documentation says without it
the effects of the functions are undefined.
I advise you to not ignore this, because I intend to apply soon and then
the KDE-specific hack _will_ be removed unless you have exceptionally
good reasons not to ("KDE does not support disabling via
XScreenSaverSuspend" does not count).

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: configure
===================================================================
--- configure	(revision 25476)
+++ configure	(working copy)
@@ -363,6 +363,7 @@ Video output:
   --enable-xinerama        enable Xinerama support [autodetect]
   --enable-x11             enable X11 video output [autodetect]
   --enable-xshape          enable XShape support [autodetect]
+  --disable-xss            disable screensaver support via xss [autodetect]
   --enable-fbdev           enable FBDev video output [autodetect]
   --enable-mlib            enable mediaLib video output (Solaris) [disable]
   --enable-3dfx            enable obsolete /dev/3dfx video output [disable]
@@ -514,6 +515,7 @@ _mencoder=yes
 _mplayer=yes
 _x11=auto
 _xshape=auto
+_xss=auto
 _dga1=auto
 _dga2=auto
 _xv=auto
@@ -812,6 +814,8 @@ for ac_option do
   --disable-x11)	_x11=no		;;
   --enable-xshape)	_xshape=yes	;;
   --disable-xshape)	_xshape=no	;;
+  --enable-xss)	_xss=yes	;;
+  --disable-xss)	_xss=no	;;
   --enable-xv)		_xv=yes		;;
   --disable-xv)		_xv=no		;;
   --enable-xvmc)        _xvmc=yes       ;;
@@ -3907,6 +3911,26 @@ else
 fi
 echores "$_x11"
 
+echocheck "Xss screensaver extensions"
+if test "$_xss" = auto ; then
+  cat > $TMPC << EOF
+#include <X11/Xlib.h>
+#include <X11/extensions/scrnsaver.h>
+int main(void) {
+    XScreenSaverSuspend(NULL,True);
+    return 0;
+}
+EOF
+  _xss=no
+  cc_check -lXss && _xss=yes
+fi
+if test "$_xss" = yes ; then
+  _def_xss='#define HAVE_XSS 1'
+  _libs_mplayer="$_libs_mplayer -lXss"
+else
+  _def_xss='#undef HAVE_XSS'
+fi
+echores "$_xss"
 
 echocheck "DPMS"
 _xdpms3=no
@@ -8497,6 +8521,7 @@ $_def_dvb
 $_def_dvb_in
 $_def_svga
 $_def_vesa
+$_def_xss
 $_def_xdpms
 $_def_aa
 $_def_caca
Index: libvo/x11_common.c
===================================================================
--- libvo/x11_common.c	(revision 25476)
+++ libvo/x11_common.c	(working copy)
@@ -1702,6 +1702,22 @@
     xs_windowid = 0;
 }
 
+static int xss_suspend(Bool suspend)
+{
+#ifndef HAVE_XSS
+    return 0;
+#else
+    int event, error, major, minor;
+    if (XScreenSaverQueryExtension(mDisplay, &event, &error) != True ||
+        XScreenSaverQueryVersion(mDisplay, &major, &minor) != True)
+        return 0;
+    if (major < 1 || major == 1 && minor < 1)
+        return 0;
+    XScreenSaverSuspend(mDisplay, suspend);
+    return 1;
+#endif
+}
+
 /*
  * End of XScreensaver stuff
  */
@@ -1709,6 +1725,8 @@
 void saver_on(Display * mDisplay)
 {
 
+    if (xss_suspend(False))
+        return;
 #ifdef HAVE_XDPMS
     if (dpms_disabled)
     {
@@ -1767,9 +1785,11 @@
 
 void saver_off(Display * mDisplay)
 {
-#ifdef HAVE_XDPMS
     int nothing;
 
+    if (xss_suspend(True))
+        return;
+#ifdef HAVE_XDPMS
     if (DPMSQueryExtension(mDisplay, &nothing, &nothing))
     {
         BOOL onoff;


More information about the MPlayer-dev-eng mailing list