[PATCH] Close non-keyboard devices on DPMS off

Keith Packard keithp at keithp.com
Fri Oct 4 12:19:15 PDT 2013


This prevents X server wakeup by mouse, tablet or touchscreen
devices. It also saves power by shutting those devices down when the
screen is blank.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 hw/xfree86/common/xf86DPMS.c | 24 ++++++++++++++++++++++++
 include/inputstr.h           |  1 +
 2 files changed, 25 insertions(+)

diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 3f1e142..e308378 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -143,6 +143,8 @@ DPMSSetScreen(ScrnInfoPtr pScrn, int level)
     }
 }
 
+#include "inputstr.h"
+
 /*
  * DPMSSet --
  *	Device dependent DPMS mode setting hook.  This is called whenever
@@ -171,6 +173,28 @@ DPMSSet(ClientPtr client, int level)
     for (i = 0; i < xf86NumGPUScreens; i++) {
         DPMSSetScreen(xf86GPUScreens[i], level);
     }
+
+    /* Turn off non-keyboard devices while screen is off */
+    if (level != DPMSModeOn) {
+        DeviceIntPtr    dev, tmp;
+
+        nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
+            if (!IsKeyboardDevice(dev) && !IsMaster(dev)) {
+                dev->dpms_off = TRUE;
+                DisableDevice(dev, FALSE);
+            }
+        }
+    } else {
+        DeviceIntPtr    dev, tmp;
+
+        nt_list_for_each_entry_safe(dev, tmp, inputInfo.off_devices, next) {
+            if (dev->dpms_off) {
+                dev->dpms_off = FALSE;
+                EnableDevice(dev, FALSE);
+            }
+        }
+    }
+
     return Success;
 }
 
diff --git a/include/inputstr.h b/include/inputstr.h
index dc36c5d..76b884a 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -539,6 +539,7 @@ typedef struct _DeviceIntRec {
     Bool inited;                /* TRUE if INIT returns Success */
     Bool enabled;               /* TRUE if ON returns Success */
     Bool coreEvents;            /* TRUE if device also sends core */
+    Bool dpms_off;
     GrabInfoRec deviceGrab;     /* grab on the device */
     int type;                   /* MASTER_POINTER, MASTER_KEYBOARD, SLAVE */
     Atom xinput_type;
-- 
1.8.4.rc3



More information about the xorg-devel mailing list