Similarly to --scale, accept a single value to be used for all three
components, and refuse values with extra junk after the acceptable
 man/ |  9 ++++++---
 xrandr.c       | 15 +++++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/man/ b/man/
index cfbfb8f..9f976ad 100644
--- a/man/
+++ b/man/
@@ -63,7 +63,7 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-set \fIproperty\fP \fIvalue\fP]
 [\-\-crtc \fIcrtc\fP]
-[\-\-gamma \fIred\fP:\fIgreen\fP:\fIblue\fP]
+[\-\-gamma \fIred\fP[:\fIgreen\fP:\fIblue\fP]]
 [\-\-brightness \fIbrightness\fP]
 [\-o \fIorientation\fP]
 [\-s \fIsize\fP]
@@ -303,9 +303,12 @@ Uses the specified crtc (either as an index in the list of 
CRTCs or XID).
 In normal usage, this option is not required as xrandr tries to make
 sensible choices about which crtc to use with each output. When that fails
 for some reason, this option can override the normal selection.
-.IP "\-\-gamma \fIred\fP:\fIgreen\fP:\fIblue\fP"
+.IP "\-\-gamma \fIred\fP[:\fIgreen\fP:\fIblue\fP]"
 Set the specified floating point values as gamma correction on the crtc
-currently attached to this output. Note that you cannot get two different 
+currently attached to this output.
+If green and blue are not specified, the red value will be used
+for all three components.
+Note that you cannot get two different values
 for cloned outputs (i.e.: which share the same crtc) and that switching an 
output to another crtc doesn't change
 the crtc gamma corrections at all.
 .IP "\-\-brightness \fIbrightness\fP"
diff --git a/xrandr.c b/xrandr.c
index 6a38cf2..f6c425f 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -144,7 +144,7 @@ usage(void)
            "      --off\n"
            "      --crtc <crtc>\n"
            "      --panning 
-           "      --gamma <r>:<g>:<b>\n"
+           "      --gamma <r>[:<g>:<b>]\n"
            "      --brightness <value>\n"
            "      --primary\n"
            "  --noprimary\n"
@@ -2967,11 +2967,18 @@ main (int argc, char **argv)
        if (!strcmp ("--gamma", argv[i])) {
+           char junk;
            if (!config_output) argerr ("%s must be used after --output\n", 
            if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
-           if (sscanf(argv[i], "%f:%f:%f", &config_output->,
-                   &config_output->, &config_output-> != 
-               argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+           if (sscanf(argv[i], "%f:%f:%f%c", &config_output->,
+                   &config_output->, &config_output->, 
&junk) != 3)
+           {
+               /* check if it's a single floating-point value,
+                * to be applied to all components */
+               if (sscanf(argv[i], "%f%c", &config_output->, &junk) 
!= 1)
+                   argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+               config_output-> = config_output-> = 
+           }
            config_output->changes |= changes_gamma;
            setit_1_2 = True;

_______________________________________________ X.Org development

Reply via email to