[mutter/wip/wayland-display: 34/55] MonitorManager: add support for DPMS levels



commit 27c4e3204f47af53b4720975296056300f08b1bc
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Wed Jul 24 10:39:06 2013 +0200

    MonitorManager: add support for DPMS levels
    
    To the XRandR and dummy backend (and as usual the dummy backend
    has no effect)

 src/core/monitor.c |  131 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xrandr.xml     |   30 ++++++++++++
 2 files changed, 161 insertions(+), 0 deletions(-)
---
diff --git a/src/core/monitor.c b/src/core/monitor.c
index 329681d..c98d402 100644
--- a/src/core/monitor.c
+++ b/src/core/monitor.c
@@ -32,6 +32,7 @@
 
 #ifdef HAVE_RANDR
 #include <X11/extensions/Xrandr.h>
+#include <X11/extensions/dpms.h>
 #endif
 
 #include <meta/main.h>
@@ -46,6 +47,14 @@
 #define ALL_WL_TRANSFORMS ((1 << (WL_OUTPUT_TRANSFORM_FLIPPED_270 + 1)) - 1)
 
 typedef enum {
+  META_POWER_SAVE_UNKNOWN = -1,
+  META_POWER_SAVE_ON = 0,
+  META_POWER_SAVE_STANDBY,
+  META_POWER_SAVE_SUSPEND,
+  META_POWER_SAVE_OFF,
+} MetaPowerSave;
+
+typedef enum {
   META_BACKEND_UNSPECIFIED,
   META_BACKEND_DUMMY,
   META_BACKEND_XRANDR,
@@ -64,6 +73,8 @@ struct _MetaMonitorManager
 
   unsigned int serial;
 
+  MetaPowerSave power_save_mode;
+
   int max_screen_width;
   int max_screen_height;
   int screen_width;
@@ -110,6 +121,12 @@ enum {
   SIGNALS_LAST
 };
 
+enum {
+  PROP_0,
+  PROP_POWER_SAVE_MODE,
+  PROP_LAST
+};
+
 static int signals[SIGNALS_LAST];
 
 static void meta_monitor_manager_display_config_init (MetaDBusDisplayConfigIface *iface);
@@ -334,11 +351,40 @@ read_monitor_infos_from_xrandr (MetaMonitorManager *manager)
     unsigned int n_actual_outputs;
     int min_width, min_height;
     Screen *screen;
+    BOOL dpms_capable, dpms_enabled;
+    CARD16 dpms_state;
 
     if (manager->resources)
       XRRFreeScreenResources (manager->resources);
     manager->resources = NULL;
 
+    meta_error_trap_push (meta_get_display ());
+    dpms_capable = DPMSCapable (manager->xdisplay);
+    meta_error_trap_pop (meta_get_display ());
+
+    if (dpms_capable &&
+        DPMSInfo (manager->xdisplay, &dpms_state, &dpms_enabled) &&
+        dpms_enabled)
+      {
+        switch (dpms_state)
+          {
+          case DPMSModeOn:
+            manager->power_save_mode = META_POWER_SAVE_ON;
+          case DPMSModeStandby:
+            manager->power_save_mode = META_POWER_SAVE_STANDBY;
+          case DPMSModeSuspend:
+            manager->power_save_mode = META_POWER_SAVE_SUSPEND;
+          case DPMSModeOff:
+            manager->power_save_mode = META_POWER_SAVE_OFF;
+          default:
+            manager->power_save_mode = META_POWER_SAVE_UNKNOWN;
+          }
+      }
+    else
+      {
+        manager->power_save_mode = META_POWER_SAVE_UNKNOWN;
+      }
+
     XRRGetScreenSizeRange (manager->xdisplay, DefaultRootWindow (manager->xdisplay),
                            &min_width,
                            &min_height,
@@ -874,6 +920,49 @@ meta_monitor_manager_new (Display *display)
 }
 
 static void
+meta_monitor_manager_set_power_save_mode (MetaMonitorManager *manager,
+                                          MetaPowerSave       mode)
+{
+  if (mode == manager->power_save_mode)
+    return;
+
+  if (manager->power_save_mode == META_POWER_SAVE_UNKNOWN ||
+      mode == META_POWER_SAVE_UNKNOWN)
+    return;
+
+#ifdef HAVE_RANDR
+  if (manager->backend == META_BACKEND_XRANDR)
+    {
+      CARD16 state;
+
+      switch (mode) {
+      case META_POWER_SAVE_ON:
+        state = DPMSModeOn;
+        break;
+      case META_POWER_SAVE_STANDBY:
+        state = DPMSModeStandby;
+        break;
+      case META_POWER_SAVE_SUSPEND:
+        state = DPMSModeSuspend;
+        break;
+      case META_POWER_SAVE_OFF:
+        state = DPMSModeOff;
+        break;
+      default:
+        return;
+      }
+
+      meta_error_trap_push (meta_get_display ());
+      DPMSForceLevel (manager->xdisplay, state);
+      DPMSSetTimeouts (manager->xdisplay, 0, 0, 0);
+      meta_error_trap_pop (meta_get_display ());
+    }
+#endif
+
+  manager->power_save_mode = mode;
+}
+
+static void
 free_output_array (MetaOutput *old_outputs,
                    int         n_old_outputs)
 {
@@ -921,10 +1010,50 @@ meta_monitor_manager_dispose (GObject *object)
 }
 
 static void
+meta_monitor_manager_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  MetaMonitorManager *self = META_MONITOR_MANAGER (object);
+
+  switch (prop_id)
+    {
+    case PROP_POWER_SAVE_MODE:
+      meta_monitor_manager_set_power_save_mode (self, g_value_get_int (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+meta_monitor_manager_get_property (GObject      *object,
+                                   guint         prop_id,
+                                   GValue       *value,
+                                   GParamSpec   *pspec)
+{
+  MetaMonitorManager *self = META_MONITOR_MANAGER (object);
+
+  switch (prop_id)
+    {
+    case PROP_POWER_SAVE_MODE:
+      g_value_set_int (value, self->power_save_mode);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
 meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->get_property = meta_monitor_manager_get_property;
+  object_class->set_property = meta_monitor_manager_set_property;
   object_class->dispose = meta_monitor_manager_dispose;
   object_class->finalize = meta_monitor_manager_finalize;
 
@@ -935,6 +1064,8 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
                  0,
                   NULL, NULL, NULL,
                  G_TYPE_NONE, 0);
+
+  g_object_class_override_property (object_class, PROP_POWER_SAVE_MODE, "power-save-mode");
 }
 
 static gboolean
diff --git a/src/xrandr.xml b/src/xrandr.xml
index 157b8cc..9309929 100644
--- a/src/xrandr.xml
+++ b/src/xrandr.xml
@@ -191,5 +191,35 @@
       <arg name="crtcs" direction="in" type="a(uiiiuaua{sv})" />
       <arg name="outputs" direction="in" type="a(ua{sv})" />
     </method>
+
+    <!--
+        PowerSaveMode:
+
+       Contains the current power saving mode for the screen, and
+       allows changing it.
+
+        Possible values:
+       - 0: on
+       - 1: standby
+       - 2: suspend
+       - 3: off
+       - -1: unknown (unsupported)
+
+        A client should not attempt to change the powersave mode
+       from -1 (unknown) to any other value, and viceversa.
+       Note that the actual effects of the different values
+       depend on the hardware and the kernel driver in use, and
+       it's perfectly possible that all values different than on
+       have the same effect.
+       Also, setting the PowerSaveMode to 3 (off) may or may
+       not have the same effect as disabling all outputs by
+       setting no CRTC on them with ApplyConfiguration(), and
+       may or may not cause a configuration change.
+
+        Also note that this property might become out of date
+       if changed through different means (for example using the
+       XRandR interface directly).
+    -->
+    <property name="PowerSaveMode" type="i" access="readwrite" />
   </interface>
 </node>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]