Package: x2x
Version: 1.27.svn.20060501-1

If you start x2x where the 'to' display doesn't support DPMS, x2x will
print a warning message to standard error every time the mouse is moved
across to the 'to' display:

zircon$ x2x -to blackrock:0.0 -resurface -west
Xlib:  extension "DPMS" missing on display "blackrock:0.0".
Xlib:  extension "DPMS" missing on display "blackrock:0.0".

(In this case the target display is a Tektronix X terminal which was
manufactured before the DPMS extension was designed...)

It shouldn't be printing this at all, since if the target display does
not support the extension x2x can simply fall back to its traditional
behaviour of doing nothing (on the assumption that the display doesn't
support blanking and unblanking).

Here's a patch to x2x.c which fixes this -- the first time we try to
do any DPMS action we use DPMSQueryExtension() to see if the display
supports it; if it doesn't we don't do anything.

This works for me. I've tried to put in code so that compiling it for
Cygwin still works, but I haven't tested that at all. I also haven't
checked that it still does the right thing if the target display is
DPMS capable, but I can't see how it could possibly be broken :-)

Hope this helps.

===begin patch===
--- x2x-1.27.svn.20060501/x2x.c 2006-04-30 16:13:50.000000000 +0100
+++ x2x-1.27.svn.20060501-patched/x2x.c 2007-04-27 15:41:21.935158688 +0100
@@ -103,6 +103,8 @@
 
 #define DPMSModeOn        0
 extern Status DPMSForceLevel(Display *, unsigned short);
+/* We always support this: */
+#define DPMSQueryExtension(DPY, EVBASE, ERBASE) TRUE
 #else
 #include <X11/extensions/dpms.h>
 #endif
@@ -139,6 +141,7 @@
 #ifndef WIN_2_X
 static int     ErrorHandler();
 #endif
+static void    DoDPMSForceLevel();
 static void    DoX2X();
 static void    InitDpyInfo();
 static void    DoConnect();
@@ -292,6 +295,7 @@
   struct _shadow *pNext;
   char    *name;
   Display *dpy;
+  int     DPMSstatus; /* -1: not queried, 0: not supported, 1: supported */
 } SHADOW, *PSHADOW;
 
 /* sticky keys */
@@ -453,6 +457,7 @@
 
   /* toDpy is always the first shadow */
   pShadow = (PSHADOW)malloc(sizeof(SHADOW));
+  pShadow->DPMSstatus = -1;
   pShadow->name = toDpyName;
   /* link into the global list */
   pShadow->pNext = shadows;
@@ -691,6 +696,7 @@
     } else if (!strcasecmp(argv[arg], "-shadow")) {
       if (++arg >= argc) Usage();
       pShadow = (PSHADOW)malloc(sizeof(SHADOW));
+      pShadow->DPMSstatus = -1;
       pShadow->name = argv[arg];
 
       /* into the global list of shadows */
@@ -1386,6 +1392,27 @@
 
 } /* END InitDpyInfo */
 
+static void DoDPMSForceLevel(pShadow, level)
+PSHADOW pShadow;
+CARD16 level;
+{
+  /* Do a DPMSForceLevel(), but only if the display supports it */
+  if (pShadow->DPMSstatus == -1) {
+    /* Need to see if this display supports the DPMS extension.
+     * If it doesn't then trying DPMSForceLevel() will display
+     * a spurious error message to stderr.
+     */
+    int t1, t2;
+    if (DPMSQueryExtension(pShadow->dpy, &t1, &t2))
+      pShadow->DPMSstatus = 1;
+    else
+      pShadow->DPMSstatus = 0;
+  }
+  
+  if (pShadow->DPMSstatus != 0)
+    DPMSForceLevel(pShadow->dpy, level);
+}
+
 static void DoConnect(pDpyInfo)
 PDPYINFO pDpyInfo;
 {
@@ -1395,7 +1422,7 @@
   PSHADOW   pShadow;
 
   for (pShadow = shadows; pShadow; pShadow = pShadow->pNext) {
-    DPMSForceLevel(pShadow->dpy, DPMSModeOn);
+    DoDPMSForceLevel(pShadow, DPMSModeOn);
     XFlush(pShadow->dpy);
   }
 
@@ -1616,7 +1643,7 @@
   for (pShadow = shadows; pShadow; pShadow = pShadow->pNext) {
     if (doDpmsMouse)
     {
-      DPMSForceLevel(pShadow->dpy, DPMSModeOn);
+      DoDPMSForceLevel(pShadow, DPMSModeOn);
     }
       
     XTestFakeMotionEvent(pShadow->dpy, toScreenNum,
@@ -2324,7 +2351,7 @@
   PSHADOW   pShadow;
 
   for (pShadow = shadows; pShadow; pShadow = pShadow->pNext) {
-    DPMSForceLevel(pShadow->dpy, DPMSModeOn);
+    DoDPMSForceLevel(pShadow, DPMSModeOn);
     XFlush(pShadow->dpy);
   }
 
@@ -2852,7 +2879,7 @@
     for (pShadow = shadows; pShadow; pShadow = pShadow->pNext) {
       if (doDpmsMouse)
       {
-        DPMSForceLevel(pShadow->dpy, DPMSModeOn);
+        DoDPMSForceLevel(pShadow, DPMSModeOn);
       }
       XTestFakeMotionEvent(pShadow->dpy, toScreenNum, 
pDpyInfo->xTables[toScreenNum][x],
         pDpyInfo->yTables[toScreenNum][y], 0);
===endit===

-- PMM


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to