I really hate to nit-pick, but it's still not correct :/
_backlight = XInternAtom (_ecore_x_disp, RANDR_PROPERTY_BACKLIGHT, True);
should be:
_backlight = XInternAtom(_ecore_x_disp, RANDR_PROPERTY_BACKLIGHT, True);
IE: We don't use spaces between function and function parameters.
Too lazy to rewrite all the lines by hand when I read them from the xbacklight
code. That's why. I corrected my mistakes.
This is done in a few places in this patch, and yet others in this patch
are ok:
XRRPropertyInfo *info = XRRQueryOutputProperty(_ecore_x_disp, output,
_backlight);
So we have a 'mixed' bit of formatting here :/
Also:
if (actual_type != XA_INTEGER || nitems != 1 || actual_format != 32)
Should be done like:
if ((actual_type != XA_INTEGER) || (nitems != 1) || (actual_format != 32))
agreed, much better this way and it suppress a warning if the compiler is picky
(I tried with -Wall -Wextra and still no warnings for this one).
And again here:
if (info->range && info->num_values == 2)
Should be:
if ((info->range) && (info->num_values == 2))
disagree here :-). No need to put the first operand between parenthesis.
Personally, I find that putting parenthesis around expressions that do not
contain test is an useless and overcharging notation while it is better when
expressions contain tests such as the second operand. I did modify it following
your advise.
Bad:
if(!_ecore_x_randr_output_validate(root, output))
Good:
if (!_ecore_x_randr_output_validate(root, output))
Please declare your variables at the beginning of the function .. NOT
inline like these:
+ /* get the ressources */
+ XRRScreenResources *resources = _ecore_x_randr_get_screen_resources
(_ecore_x_disp, root);
+ int o;
+ for (o = 0; o < resources->noutput; o++)
Again, here, I modified the code accordingly but I find much easier to declare
dummy variables where there are used only. The example you gave would be much
better like that.
for(int o=0;...;...)
You do not have to worry about the variable afterward and it avoids annoying
warning such as unused variables from gcc. Of course it means that the c89
standard is not respected (I think it is coming from the c99 standard as well
as inline functions that are used all over the place). And it has been
supported by most compilers for ages ;-).
Functionally, the patch looks sane. I have not tested it tho. If you
could address the above issues, I'd be more than happy to apply locally
and test it out.
Thanks, please try it out. If you want to test it out, just compile this small
program. It setups the backlight to 100 percent (you have to modify the
backlight before of course). Another thing, your driver needs to support it.
intel does, nouveau (most probably) but I do not know about Ati.
cheers too.
Mathieu
#include <Eina.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_X.h>
int main(int argc, char **argv)
{
eina_init();
evas_init();
ecore_init();
ecore_x_init(NULL);
Ecore_X_Window *roots;
Ecore_X_Window root;
int n;
roots = ecore_x_window_root_list(&n);
root = roots[0];
free(roots);
ecore_x_randr_screen_backlight_level_set(root, 100);
ecore_x_shutdown();
ecore_shutdown();
evas_shutdown();
eina_shutdown();
}
Index: src/lib/ecore_x/xlib/ecore_x_randr_12.c
===================================================================
--- src/lib/ecore_x/xlib/ecore_x_randr_12.c (revision 56885)
+++ src/lib/ecore_x/xlib/ecore_x_randr_12.c (working copy)
@@ -36,6 +36,7 @@
Window
window);
extern int _randr_version;
+static Atom _backlight;
#endif
/**
@@ -1904,3 +1905,172 @@
Ecore_X_Randr_Unset);
#endif
}
+
+/**
+ * @brief set up the backlight level to the given level.
+ * @param root the window's screen which will be set.
+ * @param level of the backlight between 0 and 100
+ */
+
+EAPI void
+ecore_x_randr_screen_backlight_level_set(Ecore_X_Window root, double level)
+{
+#ifdef ECORE_XRANDR
+ RANDR_CHECK_1_2_RET();
+ XRRScreenResources *resources = NULL;
+ Ecore_X_Randr_Output output ;
+ int o;
+
+ /*
+ * maybe move this should be in the init part the module.
+ * Initialize it if not already initialized
+ */
+
+ if ((level < 0) || (level > 100))
+ {
+ ERR("Wrong value for the backlight level. It should be between 0 and 100.");
+ return;
+ }
+
+ 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 or driver");
+ return;
+ }
+
+ /* get the ressources */
+ resources = _ecore_x_randr_get_screen_resources(_ecore_x_disp, root);
+
+ if (!resources) return;
+
+ for (o = 0; o < resources->noutput; o++)
+ {
+ output = resources->outputs[o];
+ if (ecore_x_randr_output_backlight_level_get(root, output) >= 0)
+ {
+ ecore_x_randr_output_backlight_level_set(root, output, level);
+ }
+ }
+ XRRFreeScreenResources(resources);
+#endif
+}
+
+/*
+ * @brief get the backlight level of the given output
+ * @param root window which's screen should be queried
+ * @param output from which the backlight level should be 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 = NULL;
+ Atom actual_type;
+ int actual_format;
+ long value, max, min;
+ XRRPropertyInfo *info = NULL;
+
+ /* set backlight variable if not already done */
+ if (_backlight == None)
+ _backlight = XInternAtom(_ecore_x_disp, RANDR_PROPERTY_BACKLIGHT, True);
+ if (_backlight == None)
+ {
+ ERR("Backlight property is not suppported on this server or driver");
+ return -1;
+ }
+
+ if (!_ecore_x_randr_output_validate(root, output))
+ {
+ ERR("Invalid output\n");
+ 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);
+
+ /* I have the current value of the backlight */
+ /* Now retrieve the min and max intensities of the output */
+ info = XRRQueryOutputProperty(_ecore_x_disp, output, _backlight);
+ if (info)
+ {
+ if ((info->range) && (info->num_values == 2))
+ {
+ /* finally convert the current value in percent to be user friendly */
+ min = info->values[0];
+ max = info->values[1];
+ value = (value-min)*100/(max-min);
+ }
+ free(info);
+ }
+ return ((double)value);
+#else
+ return -1;
+#endif
+}
+
+/*
+ * @brief set the backlight level of a given output
+ * @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);
+ XRRPropertyInfo *info = NULL;
+ double min, max, tmp;
+ long new;
+ if (!_ecore_x_randr_output_validate(root, output))
+ return EINA_FALSE;
+
+ info = XRRQueryOutputProperty(_ecore_x_disp, output, _backlight);
+ if(info)
+ {
+ if ((info->range) && (info->num_values == 2))
+ {
+ min = info->values[0];
+ max = info->values[1];
+ tmp = (level * (max - min) / 100) + min;
+ 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
+}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 56885)
+++ ChangeLog (working copy)
@@ -1,3 +1,7 @@
+2011-02-09 Mathieu Taillefumier
+
+ * Add xrandr backlight support to ecore_x
+
2011-01-29 Carsten Haitzler (The Rasterman)
1.0.0 release
Index: src/lib/ecore_x/xlib/ecore_x_randr_12.c
===================================================================
--- src/lib/ecore_x/xlib/ecore_x_randr_12.c (revision 56860)
+++ src/lib/ecore_x/xlib/ecore_x_randr_12.c (working copy)
@@ -82,7 +82,7 @@
int i;
Eina_Bool ret = EINA_FALSE;
- if ((crtc == Ecore_X_Randr_None) ||
+ if ((crtc == Ecore_X_Randr_None) ||
(crtc == Ecore_X_Randr_Unset))
return ret;
@@ -837,7 +837,7 @@
}
if (crtc_info)
XRRFreeCrtcInfo(crtc_info);
-
+
if (res)
XRRFreeScreenResources(res);
@@ -867,10 +867,10 @@
}
if (crtc_info)
XRRFreeCrtcInfo(crtc_info);
-
+
if (res)
XRRFreeScreenResources(res);
-
+
return ret;
#else
return Ecore_X_Randr_None;
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel