Hello,

I wrote three additional functions allowing us yo change the backlight 
properties of the screes supporting it. I discover that the functions are 
already declared in the headers files but the code was not added so far. The 
patch is simple and should be directly applied in the directory 
src/lib/ecore_x/xlib after reviewing it. I am open for comments and suggestions 
for improving these three functions. 

I should indicate that I plan to create a module for e17 which controls the 
backlight properties but in order to do that I would like to ask a question. I 
would like to add a timer in this module in order decrease the backlight to a 
lower value after 10 seconds of activity for instance. For course the timer 
should be deactivited when the keyboard or the mouse are used but unfortunately 
I do not know how to create such timer. 

cheers

Mathieu
Index: ecore_x_randr_12.c
===================================================================
--- ecore_x_randr_12.c	(revision 56191)
+++ ecore_x_randr_12.c	(working copy)
@@ -1902,3 +1902,135 @@
                                          Ecore_X_Randr_Unset);
 #endif
 }
+
+EAPI void
+ecore_x_randr_screen_backlight_level_set(Ecore_X_Window root, double level)
+{
+#ifdef ECORE_XRANDR
+   RANDR_CHECK_1_2_RET();
+   
+   /* 
+    *  maybe move this in the init part the module.
+    *  Initialize it if not already initialized 
+    */
+
+   if(_backlight == None)
+     _backlight = XInternAtom (_ecore_x_disp, RANDR_PROPERTY_BACKLIGHT, True);
+
+   // Clearly the server does not support it.
+   if(_backlight == None)
+     {
+       ERR("Backlight property is not suppported on this server");
+       return;
+     }
+   
+   /* get the ressources */
+   XRRScreenResources  *resources = _ecore_x_randr_get_screen_resources (_ecore_x_disp, root);
+   
+   int o;
+  
+   if (!resources) return;
+   for (o = 0; o < resources->noutput; o++)
+     {
+       Ecore_X_Randr_Output	output = resources->outputs[o];
+       if (ecore_x_randr_output_backlight_level_get(root, output) != -1)
+	 {
+	   ecore_x_randr_output_backlight_level_set(root, output, level);
+	 }
+     }
+   XRRFreeScreenResources (resources);
+#endif  
+}
+
+/*
+ * @param root window which's screen should be queried 
+ * @param output from which the backlight level should retrieved 
+ * @return the backlight level 
+ */
+
+
+EAPI double
+ecore_x_randr_output_backlight_level_get(Ecore_X_Window root,
+                                         Ecore_X_Randr_Output output)
+{
+#ifdef ECORE_XRANDR
+   RANDR_CHECK_1_2_RET(-1);  
+   unsigned long   nitems;
+   unsigned long   bytes_after;
+   unsigned char   *prop;
+   Atom	    actual_type;
+   int	    actual_format;
+   long	    value;
+   
+   if(_backlight == None)
+     _backlight = XInternAtom (_ecore_x_disp, RANDR_PROPERTY_BACKLIGHT, True);
+   if(_backlight == None)
+     {
+       ERR("Backlight property is not suppported on this server");
+       return -1;
+     }
+
+   if(!_ecore_x_randr_output_validate(root, output))
+     return -1;
+   
+   if (XRRGetOutputProperty (_ecore_x_disp, output, _backlight,
+			     0, 4, False, False, None,
+			     &actual_type, &actual_format,
+			     &nitems, &bytes_after, &prop) != Success) {
+     WRN("Backlight not supported on this output");
+     return -1;
+   }
+   
+   if (actual_type != XA_INTEGER || nitems != 1 || actual_format != 32)
+     value = -1;
+   else
+     value = *((long *) prop);
+   free (prop);
+   return value;
+#else
+   return -1;
+#endif
+}
+
+/*
+ * @param root window which's screen should be queried
+ * @param output that should be set
+ * @param level for which the backlight should be set
+ * @return EINA_TRUE in case of success 
+ */
+
+EAPI Eina_Bool
+ecore_x_randr_output_backlight_level_set(Ecore_X_Window root,
+                                         Ecore_X_Randr_Output output,
+                                         double level)
+{
+#ifdef ECORE_XRANDR
+  RANDR_CHECK_1_2_RET(EINA_FALSE);
+  if(!_ecore_x_randr_output_validate(root, output))
+    return;
+  
+  XRRPropertyInfo *info =  XRRQueryOutputProperty (_ecore_x_disp, output, _backlight);
+  if (info)
+    {
+      if (info->range && info->num_values == 2)
+	{
+	  double min = info->values[0];
+	  double max = info->values[1];
+	  double tmp = (level * (max - min) / 100) + min;
+	  long new = tmp;
+	  if (new > max) new = max;
+	  if (new < min) new = min;
+	  
+	  XRRChangeOutputProperty (_ecore_x_disp, output, _backlight, XA_INTEGER, 32,
+				   PropModeReplace, (unsigned char *) &new, 1);
+	  XFlush (_ecore_x_disp);
+	}
+      free(info);      
+      return EINA_TRUE;
+    }
+  
+  return EINA_FALSE;
+#else
+  return EINA_FALSE;
+#endif
+}
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to