]> diplodocus.org Git - xorg-xinput/commitdiff
set-prop: add --type={atom,float,int} and --format={8,16,32} options
authorJulien Cristau <jcristau@debian.org>
Tue, 15 Sep 2009 15:55:35 +0000 (17:55 +0200)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 17 Sep 2009 01:02:27 +0000 (11:02 +1000)
Allows creating new properties or modifying the type and format of
existing ones.

Signed-off-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
man/xinput.man
src/property.c
src/xinput.c

index 104cafbd995682165b8ef278982bc016f3f73602..660cc0c818401b09a8b97cec1f3df9bea19ffda2 100644 (file)
@@ -69,10 +69,10 @@ are 8, 16, or 32, depending on the property.
 Sets a float property for the device.
 .PP
 .TP 8
 Sets a float property for the device.
 .PP
 .TP 8
-.B xinput set-prop \fIdevice_name\fP \fIproperty\fP \fIvalue\fP
-Set the property to the given value(s). The format and type of the property
-are left as-is and the arguments are interpreted according to the property
-type. This argument can only be used to modify existing properties.
+.B xinput set\-prop [\-\-type=\fIatom|float|int\fP] [\-\-format=\fI8|16|32\fP] \fIdevice_name\fP \fIproperty\fP \fIvalue\fP [...]
+Set the property to the given value(s).  If not specified, the format and type
+of the property are left as-is.  The arguments are interpreted according to the
+property type.
 .PP
 .TP 8
 .B xinput watch-props \fIdevice_name\fP
 .PP
 .TP 8
 .B xinput watch-props \fIdevice_name\fP
index a41446b1925d2727e3245602f17ce82d547e386c..1ab7e4ae9d513931e9595e5fbe435779d6896e1c 100644 (file)
@@ -915,6 +915,46 @@ do_set_prop(Display *display, Atom type, int format, int argc, char *argv[], cha
 int set_prop(Display *display, int argc, char *argv[], char *name,
              char *desc)
 {
 int set_prop(Display *display, int argc, char *argv[], char *name,
              char *desc)
 {
-    return do_set_prop(display, None, 0, argc, argv, name, desc);
-}
+    Atom type = None;
+    int format = 0;
+    int i = 0, j;
+
+    while (i < argc) {
+        char *option = strchr(argv[i], '=');
+        /* skip non-option arguments */
+        if (strncmp(argv[i], "--", 2) || !option) {
+            i++;
+            continue;
+        }
+
+        if (!strncmp(argv[i], "--type=", strlen("--type="))) {
+            if (!strcmp(option + 1, "int")) {
+                type = XA_INTEGER;
+            } else if (!strcmp(option + 1, "float")) {
+                type = XInternAtom(display, "FLOAT", False);
+                format = 32;
+            } else if (!strcmp(option + 1, "atom")) {
+                type = XA_ATOM;
+                format = 32;
+            } else {
+                fprintf(stderr, "unknown property type %s\n", option + 1);
+                return EXIT_FAILURE;
+            }
+        } else if (!strncmp(argv[i], "--format=", strlen("--format="))) {
+            format = atoi(option + 1);
+            if (format != 8 && format != 16 && format != 32) {
+                fprintf(stderr, "invalid property format %s\n", option + 1);
+                return EXIT_FAILURE;
+            }
+        } else {
+            fprintf(stderr, "invalid option %s\n", argv[i]);
+            return EXIT_FAILURE;
+        }
 
 
+        for (j = i; j + 1 < argc; j++)
+            argv[j] = argv[j + 1];
+        argc--;
+    }
+
+    return do_set_prop(display, type, format, argc, argv, name, desc);
+}
index 8340211a785e120182fe0a853aaad9dfe9b10ef4..1a1e7cef9937419df7b704f20a5651959d3fc76f 100644 (file)
@@ -134,7 +134,7 @@ static entry drivers[] =
       delete_prop
     },
     { "set-prop",
       delete_prop
     },
     { "set-prop",
-      "<device> <property> <val> [<val> ...]",
+      "<device> [--type=atom|float|int] [--format=8|16|32] <property> <val> [<val> ...]",
       set_prop
     },
     {NULL, NULL, NULL
       set_prop
     },
     {NULL, NULL, NULL