[PATCH xrandr v5 4/6] xrandr: allow single value for --gamma

Giuseppe Bilotta giuseppe.bilotta at gmail.com
Tue Feb 27 11:20:20 UTC 2018


Similarly to --scale, accept a single value to be used for all three
components, and refuse values with extra junk after the acceptable
values.

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
---
 man/xrandr.man |  9 ++++++---
 xrandr.c       | 15 +++++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/man/xrandr.man b/man/xrandr.man
index cfbfb8f..9f976ad 100644
--- a/man/xrandr.man
+++ b/man/xrandr.man
@@ -63,7 +63,7 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-set \fIproperty\fP \fIvalue\fP]
 [\-\-off]
 [\-\-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 values
+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 <w>x<h>[+<x>+<y>[/<track:w>x<h>+<x>+<y>[/<border:l>/<t>/<r>/<b>]]]\n"
-           "      --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)
 	    continue;
 	}
 	if (!strcmp ("--gamma", argv[i])) {
+	    char junk;
 	    if (!config_output) argerr ("%s must be used after --output\n", argv[i]);
 	    if (++i >= argc) argerr ("%s requires an argument\n", argv[i-1]);
-	    if (sscanf(argv[i], "%f:%f:%f", &config_output->gamma.red,
-		    &config_output->gamma.green, &config_output->gamma.blue) != 3)
-		argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+	    if (sscanf(argv[i], "%f:%f:%f%c", &config_output->gamma.red,
+		    &config_output->gamma.green, &config_output->gamma.blue, &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->gamma.red, &junk) != 1)
+		    argerr ("%s: invalid argument '%s'\n", argv[i-1], argv[i]);
+		config_output->gamma.green = config_output->gamma.blue = config_output->gamma.red;
+	    }
 	    config_output->changes |= changes_gamma;
 	    setit_1_2 = True;
 	    continue;
-- 
2.14.1.439.g647b9b4702



More information about the xorg-devel mailing list