diff options
author | Andy Ritger <aritger@nvidia.com> | 2012-09-07 17:58:45 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2012-12-11 13:34:11 -0800 |
commit | 7a22279cadf7d1a2064cf985acc015401407d71c (patch) | |
tree | 6b0ff347bc8524a5d82e060cf47b9b84c8fc7108 | |
parent | 7cb20881991c8bcf7e8fa0af6ad0f85682f98e1f (diff) |
xrandr: extend '--set' syntax to allow a comma-separated list of values
Signed-off-by: Andy Ritger <aritger@nvidia.com>
Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
-rw-r--r-- | man/xrandr.man | 6 | ||||
-rw-r--r-- | xrandr.c | 93 |
2 files changed, 93 insertions, 6 deletions
diff --git a/man/xrandr.man b/man/xrandr.man index a0b9129..f04d2ed 100644 --- a/man/xrandr.man +++ b/man/xrandr.man @@ -262,9 +262,9 @@ output, so it is not valid to say \-\-output a \-\-left\-of b \-\-output b \-\-left\-of a. .IP "\-\-set \fIproperty\fP \fIvalue\fP" Sets an output property. Integer properties may be specified as a valid -(see \-\-prop) decimal or hexadecimal (with a leading 0x) value. Atom properties -may be set to any of the valid atoms (see \-\-prop). String properties may be -set to any value. +(see \-\-prop) comma-separated list of decimal or hexadecimal (with a leading 0x) values. +Atom properties may be set to any of the valid atoms (see \-\-prop). +String properties may be set to any value. .IP "\-\-off" Disables the output. .IP "\-\-crtc \fIcrtc\fP" @@ -35,6 +35,7 @@ #include <strings.h> #include <string.h> #include <stdlib.h> +#include <stdint.h> #include <stdarg.h> #include <math.h> @@ -2216,6 +2217,82 @@ check_strtod(char *s) return result; } + +static void * +property_values_from_string(const char *str, const Atom type, const int format, + int *returned_nitems) +{ + char *token, *tmp; + void *returned_bytes = NULL; + int nitems = 0, bytes_per_item = format / 8; + + if ((type != XA_INTEGER && type != XA_CARDINAL) || + (format != 8 && format != 16 && format != 32)) + { + return NULL; + } + + tmp = strdup (str); + + for (token = strtok (tmp, ","); token; token = strtok (NULL, ",")) + { + char *endptr; + long int val = strtol (token, &endptr, 0); + + if (token == endptr || *endptr != '\0') + { + usage (); + } + + returned_bytes = realloc (returned_bytes, (nitems + 1) * bytes_per_item); + + if (type == XA_INTEGER && format == 8) + { + int8_t *ptr = returned_bytes; + ptr[nitems] = (int8_t) val; + } + else if (type == XA_INTEGER && format == 16) + { + int16_t *ptr = returned_bytes; + ptr[nitems] = (int16_t) val; + } + else if (type == XA_INTEGER && format == 32) + { + int32_t *ptr = returned_bytes; + ptr[nitems] = (int32_t) val; + } + else if (type == XA_CARDINAL && format == 8) + { + uint8_t *ptr = returned_bytes; + ptr[nitems] = (uint8_t) val; + } + else if (type == XA_CARDINAL && format == 16) + { + uint16_t *ptr = returned_bytes; + ptr[nitems] = (uint16_t) val; + } + else if (type == XA_CARDINAL && format == 32) + { + uint32_t *ptr = returned_bytes; + ptr[nitems] = (uint32_t) val; + } + else + { + free (tmp); + free (returned_bytes); + return NULL; + } + + nitems++; + } + + free (tmp); + + *returned_nitems = nitems; + return returned_bytes; +} + + int main (int argc, char **argv) { @@ -2899,7 +2976,7 @@ main (int argc, char **argv) Atom name = XInternAtom (dpy, prop->name, False); Atom type; int format = 0; - unsigned char *data; + unsigned char *data, *malloced_data = NULL; int nelements; int int_value; unsigned long ulong_value; @@ -2923,8 +3000,17 @@ main (int argc, char **argv) type = actual_type; format = actual_format; } - - if ((type == XA_INTEGER || type == AnyPropertyType) && + + malloced_data = property_values_from_string + (prop->value, type, actual_format, &nelements); + + if (malloced_data) + { + data = malloced_data; + type = actual_type; + format = actual_format; + } + else if (type == AnyPropertyType && (sscanf (prop->value, "%d", &int_value) == 1 || sscanf (prop->value, "0x%x", &int_value) == 1)) { @@ -2952,6 +3038,7 @@ main (int argc, char **argv) XRRChangeOutputProperty (dpy, output->output.xid, name, type, format, PropModeReplace, data, nelements); + free (malloced_data); } } if (!setit_1_2) |